diff --git a/src/api/axios.js b/src/api/axios.js index 95c4862..df4372f 100644 --- a/src/api/axios.js +++ b/src/api/axios.js @@ -39,6 +39,7 @@ axiosInstance.interceptors.response.use( if (status === 403) { message.error("请登录后重试"); store.dispatch(logout()); + window.location.href = "/login"; } } } diff --git a/src/components/ApprovalTable.jsx b/src/components/ApprovalTable.jsx new file mode 100644 index 0000000..3da6381 --- /dev/null +++ b/src/components/ApprovalTable.jsx @@ -0,0 +1,119 @@ +import { Button, message, Space, Table } from "antd"; +import Column from "antd/es/table/Column"; +import { useEffect, useState } from "react"; +import { useSelector } from "react-redux"; +import axiosInstance from "../api/axios"; +import { selectUserId } from "../features/auth/authSlice"; + +export default function ApprovalTable({ showNeedAssist }) { + const [reservations, setReservations] = useState([]); + const [pagination, setPagination] = useState({ + current: 1, + pageSize: 10, + total: 0, + }); + + const userId = useSelector(selectUserId); + + const fetchData = async (pagination) => { + const data = await axiosInstance.get(`/reservation/approval/${userId}`, { + params: { + page: pagination.current, + size: pagination.pageSize, + }, + }); + + setReservations(data.records); + setPagination({ + ...pagination, + total: data.total, + }); + }; + + useEffect(() => { + fetchData(pagination); + }, []); + + const handlePageChange = (pagination) => { + fetchData(pagination); + }; + + const handleApproval = (reservationId, isApprove, needAssist) => { + axiosInstance.post("/approval", { + userId, + reservationId, + isApprove, + needAssist, + }); + + message.success("审核成功"); + const newPagination = { + ...pagination, + current: 1, + }; + setPagination(newPagination); + fetchData(newPagination); + }; + + // "预约人、所属团队、联系方式、预约设备、预约时间: 设备详情、" + return ( + + + + + + + + { + return ( + + + {showNeedAssist && ( + + )} + + + ); + }} + /> +
+ ); +} diff --git a/src/config/menuConfig.js b/src/config/menuConfig.js index 019faee..b4e32f7 100644 --- a/src/config/menuConfig.js +++ b/src/config/menuConfig.js @@ -18,12 +18,7 @@ const menuConfig = [ icon: UnorderedListOutlined, roles: ["USER"], }, - { - path: "/user/userdetail", - label: "个人信息", - icon: UserOutlined, - roles: ["USER"], - }, + { path: "/leader/approval", label: "预约审批", @@ -36,6 +31,18 @@ const menuConfig = [ icon: UnorderedListOutlined, roles: ["LEADER"], }, + { + path: "/device-admin/approval", + label: "预约审批", + icon: FileDoneOutlined, + roles: ["DEVICE_ADMIN"], + }, + { + path: "/userdetail", + label: "个人信息", + icon: UserOutlined, + roles: ["USER", "DEVICE_ADMIN"], + }, ]; export default menuConfig; diff --git a/src/pages/user/UserDetail.jsx b/src/pages/UserDetail.jsx similarity index 97% rename from src/pages/user/UserDetail.jsx rename to src/pages/UserDetail.jsx index 24c63f2..59d3a30 100644 --- a/src/pages/user/UserDetail.jsx +++ b/src/pages/UserDetail.jsx @@ -2,8 +2,8 @@ import { Button, Col, Form, Input, message, Row } from "antd"; import { useForm } from "antd/es/form/Form"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; -import axiosInstance from "../../api/axios"; -import { selectUserId } from "../../features/auth/authSlice"; +import axiosInstance from "../api/axios"; +import { selectUserId } from "../features/auth/authSlice"; export default function UserDetail() { const [form] = useForm(); diff --git a/src/pages/deviceAdmin/Approval.jsx b/src/pages/deviceAdmin/Approval.jsx new file mode 100644 index 0000000..ebf7768 --- /dev/null +++ b/src/pages/deviceAdmin/Approval.jsx @@ -0,0 +1,5 @@ +import ApprovalTable from "../../components/ApprovalTable"; + +export default function DeviceAdminApproval() { + return ; +} diff --git a/src/pages/leader/Approval.jsx b/src/pages/leader/Approval.jsx index 002e5f8..3420380 100644 --- a/src/pages/leader/Approval.jsx +++ b/src/pages/leader/Approval.jsx @@ -1,102 +1,5 @@ -import { Button, message, Space, Table } from "antd"; -import Column from "antd/es/table/Column"; -import { useEffect, useState } from "react"; -import { useSelector } from "react-redux"; -import axiosInstance from "../../api/axios"; -import { selectUserId } from "../../features/auth/authSlice"; +import ApprovalTable from "../../components/ApprovalTable"; export default function LeaderApproval() { - const [reservations, setReservations] = useState([]); - const [pagination, setPagination] = useState({ - current: 1, - pageSize: 10, - total: 0, - }); - - const userId = useSelector(selectUserId); - - const fetchData = async (pagination) => { - const data = await axiosInstance.get(`/reservation/leader/${userId}`, { - params: { - page: pagination.current, - size: pagination.pageSize, - }, - }); - - setReservations(data.records); - setPagination({ - ...pagination, - total: data.total, - }); - }; - - useEffect(() => { - fetchData(pagination); - }, []); - - const handlePageChange = (pagination) => { - fetchData(pagination); - }; - - const handleApproval = (reservationId, isApprove) => { - axiosInstance.post("/approval/leader", { - leaderId: userId, - reservationId, - isApprove, - }); - - message.success("审核成功"); - const newPagination = { - ...pagination, - current: 1, - }; - setPagination(newPagination); - fetchData(newPagination); - }; - - // "预约人、所属团队、联系方式、预约设备、预约时间: 设备详情、" - return ( - - - - - - - - { - return ( - - - - - ); - }} - /> -
- ); + return ; } diff --git a/src/router/index.jsx b/src/router/index.jsx index 364f7d8..5a3f688 100644 --- a/src/router/index.jsx +++ b/src/router/index.jsx @@ -1,12 +1,13 @@ import { createBrowserRouter, Navigate } from "react-router-dom"; -import Login from "../pages/Login"; -import ProtectedRoute from "./ProtectedRoute"; import CommonLayout from "../layouts/CommonLayout"; -import Reserve from "../pages/user/Reserve"; -import MyReservation from "../pages/user/MyReservation"; -import UserDetail from "../pages/user/UserDetail"; +import DeviceAdminApproval from "../pages/deviceAdmin/Approval"; import LeaderApproval from "../pages/leader/Approval"; import LeaderMyApproval from "../pages/leader/MyApproval"; +import Login from "../pages/Login"; +import MyReservation from "../pages/user/MyReservation"; +import Reserve from "../pages/user/Reserve"; +import UserDetail from "../pages/UserDetail"; +import ProtectedRoute from "./ProtectedRoute"; const router = createBrowserRouter([ { @@ -33,10 +34,6 @@ const router = createBrowserRouter([ path: "my-reservation", element: , }, - { - path: "userdetail", - element: , - }, ], }, { @@ -53,6 +50,21 @@ const router = createBrowserRouter([ }, ], }, + { + path: "device-admin", + element: , + children: [ + { + path: "approval", + element: , + }, + ], + }, + + { + path: "userdetail", + element: , + }, ], }, ]);