feat: 开放设备预约和我的预约页面给团队负责人和设备管理员,添加菜单栏排序功能

This commit is contained in:
BenjaminNH 2025-07-31 11:33:32 +08:00
parent 31146a7b6b
commit 09534937dc
3 changed files with 29 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import { import {
ApartmentOutlined, ApartmentOutlined,
ContainerOutlined,
DesktopOutlined, DesktopOutlined,
ExperimentOutlined, ExperimentOutlined,
FileDoneOutlined, FileDoneOutlined,
@ -14,13 +15,15 @@ const menuConfig = [
path: "/user/reserve", path: "/user/reserve",
label: "设备预约", label: "设备预约",
icon: DesktopOutlined, icon: DesktopOutlined,
roles: ["USER"], roles: ["USER", "LEADER", "DEVICE_ADMIN"],
order: 4,
}, },
{ {
path: "/user/my-reservation", path: "/user/my-reservation",
label: "我的预约", label: "我的预约",
icon: UnorderedListOutlined, icon: ContainerOutlined,
roles: ["USER"], roles: ["USER", "LEADER", "DEVICE_ADMIN"],
order: 5,
}, },
{ {
@ -28,36 +31,43 @@ const menuConfig = [
label: "预约审批", label: "预约审批",
icon: FileDoneOutlined, icon: FileDoneOutlined,
roles: ["LEADER", "DEVICE_ADMIN"], roles: ["LEADER", "DEVICE_ADMIN"],
order: 1,
}, },
{ {
path: "/my-approval", path: "/my-approval",
label: "审批记录", label: "审批记录",
icon: UnorderedListOutlined, icon: UnorderedListOutlined,
roles: ["LEADER", "DEVICE_ADMIN"], roles: ["LEADER", "DEVICE_ADMIN"],
order: 2,
}, },
{ {
path: "/device-manage", path: "/device-manage",
label: "设备管理", label: "设备管理",
icon: ExperimentOutlined, icon: ExperimentOutlined,
roles: ["DEVICE_ADMIN"], roles: ["DEVICE_ADMIN"],
order: 3,
}, },
{ {
path: "/admin/user-manage", path: "/admin/user-manage",
label: "用户管理", label: "用户管理",
icon: UsergroupAddOutlined, icon: UsergroupAddOutlined,
roles: ["ADMIN"], roles: ["ADMIN"],
order: 1,
}, },
{ {
label: "数据统计", label: "数据统计",
icon: PieChartOutlined, icon: PieChartOutlined,
order: 2,
children: [ children: [
{ {
path: "/admin/stats-device", path: "/admin/stats-device",
label: "设备统计", label: "设备统计",
order: 1,
}, },
{ {
path: "/admin/stats-reservation", path: "/admin/stats-reservation",
label: "使用人统计", label: "使用人统计",
order: 2,
}, },
], ],
roles: ["ADMIN"], roles: ["ADMIN"],
@ -67,12 +77,14 @@ const menuConfig = [
icon: ApartmentOutlined, icon: ApartmentOutlined,
label: "团队管理", label: "团队管理",
roles: ["ADMIN"], roles: ["ADMIN"],
order: 3,
}, },
{ {
path: "/userdetail", path: "/userdetail",
label: "个人信息", label: "个人信息",
icon: UserOutlined, icon: UserOutlined,
roles: ["USER", "LEADER", "DEVICE_ADMIN", "ADMIN"], roles: ["USER", "LEADER", "DEVICE_ADMIN", "ADMIN"],
order: 999,
}, },
]; ];

View File

@ -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) => const buildMenuItems = (menu) =>
menu.map((item) => { sortMenu(menu).map((item) => {
if (item.children) { if (item.children) {
return { return {
key: item.label, // item.path key: item.label, // item.path

View File

@ -28,7 +28,9 @@ const router = createBrowserRouter([
children: [ children: [
{ {
path: "user", path: "user",
element: <ProtectedRoute allowedRoles={["USER"]} />, element: (
<ProtectedRoute allowedRoles={["USER", "LEADER", "DEVICE_ADMIN"]} />
),
children: [ children: [
{ {
path: "reserve", path: "reserve",