From 36ed9562d950ab66cde096e7f925af4b2baae531 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 23 Jun 2025 17:17:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A1=B5=E9=9D=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/libs/script/scanPage/scanEffect.js | 24 ++++++++++++++ src/frontend/src/pages/DevicesPage.jsx | 13 ++++---- src/frontend/src/pages/ScanPage.jsx | 31 +++++-------------- 3 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 src/frontend/src/libs/script/scanPage/scanEffect.js diff --git a/src/frontend/src/libs/script/scanPage/scanEffect.js b/src/frontend/src/libs/script/scanPage/scanEffect.js new file mode 100644 index 0000000..16b72eb --- /dev/null +++ b/src/frontend/src/libs/script/scanPage/scanEffect.js @@ -0,0 +1,24 @@ +const ScanEffect = { + getTestDevices() { + return [ + { ip: '192.168.1.1', mac: '00:1A:2B:3C:4D:5E', ports: [22, 23, 161] }, + { ip: '192.168.1.2', mac: '00:1D:7D:AA:1B:01', ports: [22, 23, 161] }, + { ip: '192.168.1.3', mac: '00:0C:29:5A:3B:11', ports: [22, 23, 161, 443] }, + { ip: '192.168.1.4', mac: '00:23:CD:FF:10:02', ports: [22, 23] }, + { ip: '192.168.1.5', mac: '00:04:4B:AA:BB:CC', ports: [22, 23, 80, 443] }, + { ip: '192.168.1.6', mac: '00:11:22:33:44:55', ports: [22, 23, 161] }, + { ip: '192.168.1.7', mac: '00:1F:45:67:89:AB', ports: [23] }, + { ip: '192.168.1.8', mac: '00:50:56:11:22:33', ports: [22, 443, 8443] }, + ]; + }, + + async fetchLocalInfo({ setLocalIp, subnet, setSubnet }) { + setLocalIp('192.168.1.100'); + if (!subnet) { + const ipParts = '192.168.1.0'.split('.'); + setSubnet(`${ipParts[0]}.${ipParts[1]}.${ipParts[2]}.0/24`); + } + }, +}; + +export default ScanEffect; diff --git a/src/frontend/src/pages/DevicesPage.jsx b/src/frontend/src/pages/DevicesPage.jsx index f56979b..8a63112 100644 --- a/src/frontend/src/pages/DevicesPage.jsx +++ b/src/frontend/src/pages/DevicesPage.jsx @@ -43,13 +43,14 @@ const DevicesPage = () => { const handleSave = (idx) => { const updated = [...devices]; updated[idx].name = editingName; - Common.sleep(200); - setDevices(updated); - ConfigTool.save({ ...ConfigTool.load(), devices: updated }); - Notification.success({ - title: '设备重命名成功!', + Common.sleep(200).then(() => { + setDevices(updated); + ConfigTool.save({ ...ConfigTool.load(), devices: updated }); + Notification.success({ + title: '设备重命名成功!', + }); + setEditingIndex(null); }); - setEditingIndex(null); }; return ( diff --git a/src/frontend/src/pages/ScanPage.jsx b/src/frontend/src/pages/ScanPage.jsx index 9ce3ff8..6132e8c 100644 --- a/src/frontend/src/pages/ScanPage.jsx +++ b/src/frontend/src/pages/ScanPage.jsx @@ -19,6 +19,7 @@ import { api } from '@/services/api/api'; import ConfigTool from '@/libs/config/ConfigTool'; import Common from '@/libs/common'; import Notification from '@/libs/system/Notification'; +import ScanEffect from '@/libs/script/scanPage/scanEffect'; /** * 网络扫描页面 @@ -35,36 +36,20 @@ const ScanPage = () => { const testMode = config.testMode; useEffect(() => { - const fetchLocalInfo = async () => { - setLocalIp('192.168.1.100'); - if (!subnet) { - const ipParts = '192.168.1.0'.split('.'); - setSubnet(`${ipParts[0]}.${ipParts[1]}.${ipParts[2]}.0/24`); - } - }; - fetchLocalInfo(); + ScanEffect.fetchLocalInfo({ + setLocalIp: setLocalIp, + setSubnet: setSubnet, + subnet: subnet, + }).then(); }, [subnet, Notification]); - const getTestDevices = () => { - return [ - { ip: '192.168.1.1', mac: '00:1A:2B:3C:4D:5E', ports: [22, 23, 161] }, - { ip: '192.168.1.2', mac: '00:1D:7D:AA:1B:01', ports: [22, 23, 161] }, - { ip: '192.168.1.3', mac: '00:0C:29:5A:3B:11', ports: [22, 23, 161, 443] }, - { ip: '192.168.1.4', mac: '00:23:CD:FF:10:02', ports: [22, 23] }, - { ip: '192.168.1.5', mac: '00:04:4B:AA:BB:CC', ports: [22, 23, 80, 443] }, - { ip: '192.168.1.6', mac: '00:11:22:33:44:55', ports: [22, 23, 161] }, - { ip: '192.168.1.7', mac: '00:1F:45:67:89:AB', ports: [23] }, - { ip: '192.168.1.8', mac: '00:50:56:11:22:33', ports: [22, 443, 8443] }, - ]; - }; - const handleScan = async () => { setLoading(true); try { let scanDevices; if (testMode) { await Common.sleep(2000); - scanDevices = getTestDevices(); + scanDevices = ScanEffect.getTestDevices(); Notification.success({ title: '扫描子网设备成功!', }); @@ -104,7 +89,7 @@ const ScanPage = () => { let scanDevices; if (testMode) { await Common.sleep(500); - scanDevices = getTestDevices(); + scanDevices = ScanEffect.getTestDevices(); Notification.success({ title: '获取上一次扫描记录成功!', });