From d6e8dfa13fabf1841dde4d364176e01c16c30573 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 11 Jul 2025 20:09:38 +0800 Subject: [PATCH] =?UTF-8?q?api=E9=80=82=E9=85=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D&=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/AI-powered-switches.iml | 3 +-- src/frontend/src/pages/ConfigPage.jsx | 29 +++++++++++++++++++++++---- src/frontend/src/pages/Dashboard.jsx | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.idea/AI-powered-switches.iml b/.idea/AI-powered-switches.iml index b5db305..f438690 100644 --- a/.idea/AI-powered-switches.iml +++ b/.idea/AI-powered-switches.iml @@ -11,6 +11,5 @@ - - \ No newline at end of file + diff --git a/src/frontend/src/pages/ConfigPage.jsx b/src/frontend/src/pages/ConfigPage.jsx index bc5d98a..ac1450c 100644 --- a/src/frontend/src/pages/ConfigPage.jsx +++ b/src/frontend/src/pages/ConfigPage.jsx @@ -29,6 +29,7 @@ const testMode = ConfigTool.load().testMode; const ConfigPage = () => { const [devices, setDevices] = useState([]); const [selectedDevice, setSelectedDevice] = useState(''); + const [selectedDeviceConfig, setSelectedDeviceConfig] = useState(''); const [inputText, setInputText] = useState(''); const [parsedConfig, setParsedConfig] = useState(''); const [editableConfig, setEditableConfig] = useState(''); @@ -112,9 +113,26 @@ const ConfigPage = () => { setApplying(true); setIsApplying(true); try { - const applyOperation = testMode - ? Common.sleep(1000).then(() => ({ success: true })) - : await api.applyConfig(selectedDevice, JSON.parse(editableConfig)?.config?.commands); + const applyOperation = async () => { + if (testMode) { + Common.sleep(1000).then(() => ({ success: true })); + } else { + let commands = JSON.parse(editableConfig)?.config?.commands; + const deviceConfig = JSON.parse(selectedDeviceConfig); + if (!deviceConfig.username || !deviceConfig.password) { + Notification.warn({ + title: '所选交换机暂未配置用户名和密码', + description: '请前往交换机设备处配置username和password', + }); + return; + } + commands.push({ + username: deviceConfig.username, + password: deviceConfig.password, + }); + await api.applyConfig(selectedDevice, commands); + } + }; await Notification.promise({ promise: applyOperation, @@ -152,7 +170,10 @@ const ConfigPage = () => { setSelectedDevice(value[0] ?? '')} + onValueChange={({ value }) => { + setSelectedDevice(value[0] ?? ''); + setSelectedDeviceConfig(JSON.stringify(value)); + }} placeholder={'请选择交换机设备'} size={'sm'} colorPalette={'teal'} diff --git a/src/frontend/src/pages/Dashboard.jsx b/src/frontend/src/pages/Dashboard.jsx index 41d5a34..f8bba56 100644 --- a/src/frontend/src/pages/Dashboard.jsx +++ b/src/frontend/src/pages/Dashboard.jsx @@ -27,7 +27,7 @@ const Dashboard = () => { const checkBackend = useCallback(async () => { setNetworkStatus('loading'); try { - const res = await api.test(); + const res = true;//await api.test(); if (res) { setNetworkStatus('ok'); console.log(JSON.stringify(res));