优化页面结构

This commit is contained in:
Jerry 2025-06-23 17:17:32 +08:00
parent 223d43f0d9
commit 36ed9562d9
3 changed files with 39 additions and 29 deletions

View File

@ -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;

View File

@ -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 (

View File

@ -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: '获取上一次扫描记录成功!',
});