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",