From 09534937dc6bbca89dbec80f7ac97c2c11ec8bcd Mon Sep 17 00:00:00 2001 From: BenjaminNH <1249376374@qq.com> Date: Thu, 31 Jul 2025 11:33:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E6=94=BE=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E9=A2=84=E7=BA=A6=E5=92=8C=E6=88=91=E7=9A=84=E9=A2=84=E7=BA=A6?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=BB=99=E5=9B=A2=E9=98=9F=E8=B4=9F=E8=B4=A3?= =?UTF-8?q?=E4=BA=BA=E5=92=8C=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=8F=9C=E5=8D=95=E6=A0=8F=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/menuConfig.js | 18 +++++++++++++++--- src/layouts/CommonLayout.jsx | 12 +++++++++++- src/router/index.jsx | 4 +++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/config/menuConfig.js b/src/config/menuConfig.js index 004c546..c691869 100644 --- a/src/config/menuConfig.js +++ b/src/config/menuConfig.js @@ -1,5 +1,6 @@ import { ApartmentOutlined, + ContainerOutlined, DesktopOutlined, ExperimentOutlined, FileDoneOutlined, @@ -14,13 +15,15 @@ const menuConfig = [ path: "/user/reserve", label: "设备预约", icon: DesktopOutlined, - roles: ["USER"], + roles: ["USER", "LEADER", "DEVICE_ADMIN"], + order: 4, }, { path: "/user/my-reservation", label: "我的预约", - icon: UnorderedListOutlined, - roles: ["USER"], + icon: ContainerOutlined, + roles: ["USER", "LEADER", "DEVICE_ADMIN"], + order: 5, }, { @@ -28,36 +31,43 @@ const menuConfig = [ label: "预约审批", icon: FileDoneOutlined, roles: ["LEADER", "DEVICE_ADMIN"], + order: 1, }, { path: "/my-approval", label: "审批记录", icon: UnorderedListOutlined, roles: ["LEADER", "DEVICE_ADMIN"], + order: 2, }, { path: "/device-manage", label: "设备管理", icon: ExperimentOutlined, roles: ["DEVICE_ADMIN"], + order: 3, }, { path: "/admin/user-manage", label: "用户管理", icon: UsergroupAddOutlined, roles: ["ADMIN"], + order: 1, }, { label: "数据统计", icon: PieChartOutlined, + order: 2, children: [ { path: "/admin/stats-device", label: "设备统计", + order: 1, }, { path: "/admin/stats-reservation", label: "使用人统计", + order: 2, }, ], roles: ["ADMIN"], @@ -67,12 +77,14 @@ const menuConfig = [ icon: ApartmentOutlined, label: "团队管理", roles: ["ADMIN"], + order: 3, }, { path: "/userdetail", label: "个人信息", icon: UserOutlined, roles: ["USER", "LEADER", "DEVICE_ADMIN", "ADMIN"], + order: 999, }, ]; diff --git a/src/layouts/CommonLayout.jsx b/src/layouts/CommonLayout.jsx index 6ef8a70..d8f8234 100644 --- a/src/layouts/CommonLayout.jsx +++ b/src/layouts/CommonLayout.jsx @@ -44,8 +44,18 @@ export default function CommonLayout() { } }; + // 递归排序函数 + const sortMenu = (menu) => { + return [...menu] + .sort((a, b) => (a.order ?? 999) - (b.order ?? 999)) + .map((item) => ({ + ...item, + children: item.children ? sortMenu(item.children) : undefined, + })); + }; + const buildMenuItems = (menu) => - menu.map((item) => { + sortMenu(menu).map((item) => { if (item.children) { return { key: item.label, // 可改为 item.path 但注意不冲突 diff --git a/src/router/index.jsx b/src/router/index.jsx index 3db1f54..f1660ed 100644 --- a/src/router/index.jsx +++ b/src/router/index.jsx @@ -28,7 +28,9 @@ const router = createBrowserRouter([ children: [ { path: "user", - element: , + element: ( + + ), children: [ { path: "reserve",