106 lines
3.3 KiB
JavaScript
106 lines
3.3 KiB
JavaScript
import DashboardOutlined from "@mui/icons-material/DashboardOutlined";
|
|
import HistoryOutlined from "@mui/icons-material/HistoryOutlined";
|
|
import Inventory2Outlined from "@mui/icons-material/Inventory2Outlined";
|
|
import LoginOutlined from "@mui/icons-material/LoginOutlined";
|
|
import ManageAccountsOutlined from "@mui/icons-material/ManageAccountsOutlined";
|
|
import MenuOpenOutlined from "@mui/icons-material/MenuOpenOutlined";
|
|
import NotificationsNoneOutlined from "@mui/icons-material/NotificationsNoneOutlined";
|
|
import ReceiptLongOutlined from "@mui/icons-material/ReceiptLongOutlined";
|
|
import ShieldOutlined from "@mui/icons-material/ShieldOutlined";
|
|
import SettingsApplicationsOutlined from "@mui/icons-material/SettingsApplicationsOutlined";
|
|
|
|
export const navItems = [
|
|
{ id: "overview", code: "overview", label: "总览", path: "/overview", icon: DashboardOutlined },
|
|
{ id: "services", code: "services", label: "服务管理", path: "/services", icon: Inventory2Outlined },
|
|
{
|
|
id: "system",
|
|
code: "system",
|
|
label: "系统管理",
|
|
icon: SettingsApplicationsOutlined,
|
|
children: [
|
|
{ id: "system-users", code: "system-users", label: "用户管理", path: "/system/users", icon: ManageAccountsOutlined },
|
|
{ id: "system-roles", code: "system-roles", label: "角色配置", path: "/system/roles", icon: ShieldOutlined },
|
|
{ id: "system-menus", code: "system-menus", label: "菜单权限", path: "/system/menus", icon: MenuOpenOutlined }
|
|
]
|
|
},
|
|
{
|
|
id: "logs",
|
|
code: "logs",
|
|
label: "日志审计",
|
|
icon: HistoryOutlined,
|
|
children: [
|
|
{ id: "logs-login", code: "logs-login", label: "登录日志", path: "/logs/login", icon: LoginOutlined },
|
|
{ id: "logs-operations", code: "logs-operations", label: "操作日志", path: "/logs/operations", icon: ReceiptLongOutlined }
|
|
]
|
|
},
|
|
{
|
|
id: "notifications",
|
|
code: "notifications",
|
|
label: "通知中心",
|
|
path: "/notifications",
|
|
icon: NotificationsNoneOutlined
|
|
}
|
|
];
|
|
|
|
const iconMap = {
|
|
dashboard: DashboardOutlined,
|
|
history: HistoryOutlined,
|
|
inventory: Inventory2Outlined,
|
|
login: LoginOutlined,
|
|
menu: MenuOpenOutlined,
|
|
notifications: NotificationsNoneOutlined,
|
|
receipt: ReceiptLongOutlined,
|
|
settings: SettingsApplicationsOutlined,
|
|
shield: ShieldOutlined,
|
|
users: ManageAccountsOutlined
|
|
};
|
|
|
|
export function mapBackendMenus(menus = []) {
|
|
return menus.map((item) => ({
|
|
id: item.code || String(item.id),
|
|
code: item.code,
|
|
label: item.label,
|
|
path: item.path,
|
|
icon: iconMap[item.icon] || MenuOpenOutlined,
|
|
permissionCode: item.permissionCode,
|
|
children: item.children?.length ? mapBackendMenus(item.children) : undefined
|
|
}));
|
|
}
|
|
|
|
export function findNavItemById(id, items = navItems) {
|
|
for (const item of items) {
|
|
if (item.id === id) {
|
|
return item;
|
|
}
|
|
|
|
if (item.children?.length) {
|
|
const child = findNavItemById(id, item.children);
|
|
|
|
if (child) {
|
|
return child;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function findNavItemByPath(pathname, items = navItems) {
|
|
let fallback = null;
|
|
|
|
for (const item of items) {
|
|
if (item.path && pathname.startsWith(item.path)) {
|
|
fallback = item;
|
|
}
|
|
|
|
if (item.children?.length) {
|
|
const child = findNavItemByPath(pathname, item.children);
|
|
if (child) {
|
|
return child;
|
|
}
|
|
}
|
|
}
|
|
|
|
return fallback;
|
|
}
|