From dc0451529efec8ebb6d8f5e6df4e1c28d670f53e Mon Sep 17 00:00:00 2001 From: BenjaminNH <1249376374@qq.com> Date: Tue, 1 Jul 2025 11:24:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/DeviceStatusConfig.js | 5 + src/config/menuConfig.js | 7 + src/pages/deviceAdmin/DeviceDetailModal.jsx | 109 ++++++++++++++++ src/pages/deviceAdmin/DeviceManage.jsx | 136 ++++++++++++++++++++ src/pages/shared/MyApproval.jsx | 13 +- src/pages/shared/UserDetail.jsx | 2 +- src/pages/user/DeviceDetailModal.jsx | 7 +- src/pages/user/Reserve.jsx | 2 +- src/router/index.jsx | 23 ++-- 9 files changed, 283 insertions(+), 21 deletions(-) create mode 100644 src/config/DeviceStatusConfig.js create mode 100644 src/pages/deviceAdmin/DeviceDetailModal.jsx create mode 100644 src/pages/deviceAdmin/DeviceManage.jsx diff --git a/src/config/DeviceStatusConfig.js b/src/config/DeviceStatusConfig.js new file mode 100644 index 0000000..3aeda2e --- /dev/null +++ b/src/config/DeviceStatusConfig.js @@ -0,0 +1,5 @@ +export const deviceStatusOptions = [ + { label: "可用", value: "AVAILABLE" }, + { label: "停用", value: "DISABLED" }, + // { label: "维修中", value: "MAINTENANCE" }, +]; diff --git a/src/config/menuConfig.js b/src/config/menuConfig.js index 2db2373..70e6eb7 100644 --- a/src/config/menuConfig.js +++ b/src/config/menuConfig.js @@ -1,5 +1,6 @@ import { DesktopOutlined, + ExperimentOutlined, FileDoneOutlined, UnorderedListOutlined, UserOutlined, @@ -31,6 +32,12 @@ const menuConfig = [ icon: UnorderedListOutlined, roles: ["LEADER", "DEVICE_ADMIN"], }, + { + path: "/device-manage", + label: "设备管理", + icon: ExperimentOutlined, + roles: ["DEVICE_ADMIN"], + }, { path: "/userdetail", label: "个人信息", diff --git a/src/pages/deviceAdmin/DeviceDetailModal.jsx b/src/pages/deviceAdmin/DeviceDetailModal.jsx new file mode 100644 index 0000000..1cff3af --- /dev/null +++ b/src/pages/deviceAdmin/DeviceDetailModal.jsx @@ -0,0 +1,109 @@ +import { UploadOutlined } from "@ant-design/icons"; +import { Button, Form, Image, Input, Modal, Select, Upload } from "antd"; +import TextArea from "antd/es/input/TextArea"; +import { useEffect, useState } from "react"; +import axiosInstance, { baseURL } from "../../api/axios"; +import { deviceStatusOptions } from "../../config/DeviceStatusConfig"; + +export default function DeviceDetailModal({ + visiable, + device, + onclose, + onSuccess, +}) { + const [form] = Form.useForm(); + const [imageFile, setImageFile] = useState(null); + const [initialValues, setInitialValues] = useState({}); + const [fileList, setFileList] = useState(); + useEffect(() => { + if (device) { + const values = { + name: device.name, + location: device.location, + usageRequirement: device.usageRequirement, + status: device.status, + }; + form.setFieldsValue(values); + setInitialValues(values); + } + }, [device]); + + const handleEdit = async () => { + const values = await form.validateFields(); + const updates = {}; + Object.keys(initialValues).forEach((key) => { + if (values[key] !== initialValues[key]) { + updates[key] = values[key]; + } + }); + + if (Object.keys(updates).length > 0) { + await axiosInstance.put(`/device/${device.deviceId}`, updates); + } + + if (imageFile) { + const formData = new FormData(); + formData.append("image", imageFile); + await axiosInstance.post(`device/${device.deviceId}/image`, formData, { + headers: { + "Content-Type": "multipart/form-data", + }, + }); + } + onSuccess(); + setFileList([]); + form.resetFields(); + onclose(); + }; + + return ( + { + setFileList([]); + form.resetFields(); + onclose(); + }} + onOk={handleEdit} + okText="保存" + > +
+ + + + + + + +