From ff78f8eb2760dca0ff0d3f607f2f9068b0a876f9 Mon Sep 17 00:00:00 2001 From: DLmaster361 Date: Tue, 12 Aug 2025 20:57:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E6=A1=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/info.py | 15 +++++++++++++++ app/core/config.py | 17 +++++++++++++++++ app/models/schema.py | 9 +++++++++ 3 files changed, 41 insertions(+) diff --git a/app/api/info.py b/app/api/info.py index 00378eb..a2fa90a 100644 --- a/app/api/info.py +++ b/app/api/info.py @@ -40,6 +40,21 @@ async def get_stage_info() -> InfoOut: return InfoOut(data=data) +@router.post( + "/combox/script", + summary="获取脚本下拉框信息", + response_model=ComboBoxOut, + status_code=200, +) +async def get_script_combox() -> ComboBoxOut: + + try: + data: List[ComboBoxItem] = await Config.get_script_combox() + except Exception as e: + return ComboBoxOut(code=500, status="error", message=str(e), data=[]) + return ComboBoxOut(data=data) + + @router.post("/notice", summary="获取通知信息", response_model=InfoOut, status_code=200) async def get_notice_info() -> InfoOut: diff --git a/app/core/config.py b/app/core/config.py index 9fe85d6..5c1b7a9 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -627,6 +627,7 @@ class GeneralConfig(ConfigBase): CLASS_BOOK = {"MAA": MaaConfig, "MaaPlan": MaaPlanConfig, "General": GeneralConfig} +TYPE_BOOK = {"MaaConfig": "MAA", "GeneralConfig": "通用"} class AppConfig(GlobalConfig): @@ -1262,6 +1263,22 @@ class AppConfig(GlobalConfig): return True, {"ALL": results} + async def get_script_combox(self): + """获取脚本下拉框信息""" + + logger.info("Getting script combo box information...") + data = [] + for uid, script in self.ScriptConfig.items(): + data.append( + { + "label": f"{TYPE_BOOK[script.__class__.__name__]} - {script.get('Info', 'Name')}", + "value": str(uid), + } + ) + logger.success("Script combo box information retrieved successfully.") + + return data + async def get_server_info(self, type: str) -> Dict[str, Any]: """获取公告信息""" diff --git a/app/models/schema.py b/app/models/schema.py index e5153fa..bd89ca5 100644 --- a/app/models/schema.py +++ b/app/models/schema.py @@ -34,6 +34,15 @@ class InfoOut(OutBase): data: Dict[str, Any] = Field(..., description="收到的服务器数据") +class ComboBoxItem(BaseModel): + label: str = Field(..., description="展示值") + value: str = Field(..., description="实际值") + + +class ComboBoxOut(OutBase): + data: List[ComboBoxItem] = Field(..., description="下拉框选项") + + class GlobalConfig_Function(BaseModel): HistoryRetentionTime: Optional[Literal[7, 15, 30, 60, 90, 180, 365, 0]] = Field( None, description="历史记录保留时间, 0表示永久保存"