diff --git a/src/frontend/src/components/pages/config/DeviceConfigModal.jsx b/src/frontend/src/components/pages/config/DeviceConfigModal.jsx new file mode 100644 index 0000000..744ad81 --- /dev/null +++ b/src/frontend/src/components/pages/config/DeviceConfigModal.jsx @@ -0,0 +1,138 @@ +import React, { useState } from 'react'; +import { + Button, + Box, + Dialog, + DialogBackdrop, + DialogPositioner, + DialogContent, + DialogHeader, + DialogBody, + DialogFooter, + Field, + Input, + Stack, +} from '@chakra-ui/react'; +import { motion } from 'framer-motion'; +import { FiCheck } from 'react-icons/fi'; +import Notification from '@/libs/system/Notification'; + +const MotionBox = motion(Box); + +/** + * 设备配置弹窗 + * @param isOpen 是否打开 + * @param onClose 关闭弹窗 + * @param onSave 保存修改 + * @param device 当前设备 + * @returns {JSX.Element} + * @constructor + */ +const DeviceConfigModal = ({ isOpen, onClose, onSave, device }) => { + const [username, setUsername] = useState(device.username || ''); + const [password, setPassword] = useState(device.password || ''); + const [saved, setSaved] = useState(false); + + const handleSave = () => { + const updatedDevice = { ...device, username, password }; + onSave(updatedDevice); + setSaved(true); + setTimeout(() => { + setSaved(false); + onClose(); + }, 1200); + }; + + return ( + + + + + 交换机设备配置 + + + + + 交换机用户名 + setUsername(e.target.value)} + placeholder={'请输入设备用户名'} + bg={'whiteAlpha.200'} + /> + + + + 交换机密码 + setPassword(e.target.value)} + placeholder={'请输入设备密码'} + bg={'whiteAlpha.200'} + type={'password'} + /> + + + + + + + + + + + + + ); +}; + +export default DeviceConfigModal; diff --git a/src/frontend/src/pages/ConfigPage.jsx b/src/frontend/src/pages/ConfigPage.jsx index 5e77270..bc5d98a 100644 --- a/src/frontend/src/pages/ConfigPage.jsx +++ b/src/frontend/src/pages/ConfigPage.jsx @@ -8,10 +8,12 @@ import { HStack, Portal, Select, + Spinner, Text, Textarea, VStack, } from '@chakra-ui/react'; + import DocumentTitle from '@/components/system/pages/DocumentTitle'; import PageContainer from '@/components/system/PageContainer'; import DashboardBackground from '@/components/system/pages/DashboardBackground'; @@ -32,6 +34,9 @@ const ConfigPage = () => { const [editableConfig, setEditableConfig] = useState(''); const [applying, setApplying] = useState(false); const [hasParsed, setHasParsed] = useState(false); + const [isPeizhi, setisPeizhi] = useState(false); + const [isApplying, setIsApplying] = useState(false); + const [applyStatus, setApplyStatus] = useState([]); const deviceCollection = createListCollection({ items: devices.map((device) => ({ @@ -79,12 +84,12 @@ const ConfigPage = () => { }, }); - const result = await resultWrapper.unwrap(); - - if (result?.config) { - setParsedConfig(result.config); - setEditableConfig(result.config); + let result = await resultWrapper.unwrap(); + if (result?.data) { + setParsedConfig(JSON.stringify(result.data)); + setEditableConfig(JSON.stringify(result.data)); setHasParsed(true); + setisPeizhi(true); } } catch (error) { console.error('配置解析异常:', error); @@ -105,10 +110,11 @@ const ConfigPage = () => { } setApplying(true); + setIsApplying(true); try { const applyOperation = testMode ? Common.sleep(1000).then(() => ({ success: true })) - : await api.applyConfig(selectedDevice, editableConfig); + : await api.applyConfig(selectedDevice, JSON.parse(editableConfig)?.config?.commands); await Notification.promise({ promise: applyOperation, @@ -139,7 +145,6 @@ const ConfigPage = () => { 交换机配置中心 - 选择交换机设备 @@ -175,21 +180,21 @@ const ConfigPage = () => { - 配置指令输入