From 1d7939b88b7d6e46831a73bb5fa18e682b79c74a Mon Sep 17 00:00:00 2001 From: Jerryplusy Date: Wed, 10 Sep 2025 15:20:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E5=87=BA=E6=B5=8B=E8=AF=95=E5=88=86?= =?UTF-8?q?=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/app/api/endpoints.py | 31 +++++++++++++++++++++++++++ src/frontend/src/pages/ConfigPage.jsx | 23 ++++++++------------ src/frontend/src/services/api/api.js | 3 +++ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/backend/app/api/endpoints.py b/src/backend/app/api/endpoints.py index 697e687..7a0ad9d 100644 --- a/src/backend/app/api/endpoints.py +++ b/src/backend/app/api/endpoints.py @@ -89,6 +89,7 @@ class DeviceItem(BaseModel): class CommandRequest(BaseModel): command: str devices: List[DeviceItem] + test_mode: bool = False @router.post("/parse_command", response_model=dict) async def parse_command(request: CommandRequest): @@ -101,6 +102,36 @@ async def parse_command(request: CommandRequest): detail=f"以下设备未配置厂商: {names}" ) try: + if request.test_mode: + return { + "success": True, + "config": [ + { + "device": { + "name": "交换机 1", + "ip": "172.17.99.207", + "vendor": "huawei", + "username": "NONE", + "password": "NONE" + }, + "config": { + "type": "vlan", + "vlan_id": 114, + "commands": [ + "system-view", + "vlan 114", + "quit", + "interface GigabitEthernet 0/0/1", + "port link-type access", + "port default vlan 114", + "quit", + "save", + "Y" + ] + } + } + ] +} ai_service = AIService(settings.SILICONFLOW_API_KEY, settings.SILICONFLOW_API_URL) config = await ai_service.parse_command(request.command, [d.dict() for d in request.devices]) return {"success": True, "config": config.get("results", [])} diff --git a/src/frontend/src/pages/ConfigPage.jsx b/src/frontend/src/pages/ConfigPage.jsx index 4f343cb..ac3b32f 100644 --- a/src/frontend/src/pages/ConfigPage.jsx +++ b/src/frontend/src/pages/ConfigPage.jsx @@ -8,7 +8,6 @@ import { HStack, Portal, Select, - Spinner, Text, Textarea, VStack, @@ -21,7 +20,6 @@ import FadeInWrapper from '@/components/system/layout/FadeInWrapper'; import ConfigTool from '@/libs/config/ConfigTool'; import { api } from '@/services/api/api'; import Notification from '@/libs/system/Notification'; -import Common from '@/libs/common'; const testMode = ConfigTool.load().testMode; @@ -66,10 +64,15 @@ const ConfigPage = () => { try { const performParse = async () => - await api.parseCommand({ - command: inputText, - devices: selectedConfigs, - }); + testMode + ? await api.parseTest({ + command: inputText, + devices: selectedConfigs, + }) + : await api.parseCommand({ + command: inputText, + devices: selectedConfigs, + }); const resultWrapper = await Notification.promise({ promise: performParse(), @@ -120,14 +123,6 @@ const ConfigPage = () => { setApplying(true); try { const applyOperation = async () => { - if (testMode) { - await Common.sleep(1000); - Notification.success({ - title: '测试模式成功', - description: '配置已模拟应用', - }); - return; - } const applyPromises = selectedDevices.map(async (ip) => { const deviceItem = deviceConfigs[ip]; if (!deviceItem) return; diff --git a/src/frontend/src/services/api/api.js b/src/frontend/src/services/api/api.js index c4718eb..460de3a 100644 --- a/src/frontend/src/services/api/api.js +++ b/src/frontend/src/services/api/api.js @@ -47,6 +47,9 @@ export const api = { parseCommand: ({ command, devices }) => axios.post(buildUrl('/api/parse_command'), { command, devices }), + parseTest: ({ command, devices }) => + axios.post(buildUrl('/api/parse_command'), { command, devices, test_mode: true }), + /** * 应用配置 * @param {string} switch_ip 交换机IP