225 lines
6.9 KiB
JavaScript
225 lines
6.9 KiB
JavaScript
import ApartmentOutlined from "@mui/icons-material/ApartmentOutlined";
|
|
import BedroomParentOutlined from "@mui/icons-material/BedroomParentOutlined";
|
|
import CardGiftcardOutlined from "@mui/icons-material/CardGiftcardOutlined";
|
|
import CategoryOutlined from "@mui/icons-material/CategoryOutlined";
|
|
import DashboardOutlined from "@mui/icons-material/DashboardOutlined";
|
|
import GroupsOutlined from "@mui/icons-material/GroupsOutlined";
|
|
import HistoryOutlined from "@mui/icons-material/HistoryOutlined";
|
|
import HubOutlined from "@mui/icons-material/HubOutlined";
|
|
import Inventory2Outlined from "@mui/icons-material/Inventory2Outlined";
|
|
import LoginOutlined from "@mui/icons-material/LoginOutlined";
|
|
import ManageAccountsOutlined from "@mui/icons-material/ManageAccountsOutlined";
|
|
import MapOutlined from "@mui/icons-material/MapOutlined";
|
|
import MenuOpenOutlined from "@mui/icons-material/MenuOpenOutlined";
|
|
import NotificationsNoneOutlined from "@mui/icons-material/NotificationsNoneOutlined";
|
|
import PublicOutlined from "@mui/icons-material/PublicOutlined";
|
|
import ReceiptLongOutlined from "@mui/icons-material/ReceiptLongOutlined";
|
|
import SendOutlined from "@mui/icons-material/SendOutlined";
|
|
import ShieldOutlined from "@mui/icons-material/ShieldOutlined";
|
|
import SettingsApplicationsOutlined from "@mui/icons-material/SettingsApplicationsOutlined";
|
|
import TaskAltOutlined from "@mui/icons-material/TaskAltOutlined";
|
|
import WalletOutlined from "@mui/icons-material/WalletOutlined";
|
|
import { getRouteByMenuCode } from "@/app/router/routeConfig";
|
|
|
|
const deprecatedMenuCodes = new Set(["services"]);
|
|
|
|
const iconMap = {
|
|
apartment: ApartmentOutlined,
|
|
category: CategoryOutlined,
|
|
dashboard: DashboardOutlined,
|
|
gift: CardGiftcardOutlined,
|
|
inventory: Inventory2Outlined,
|
|
network: HubOutlined,
|
|
team: GroupsOutlined,
|
|
history: HistoryOutlined,
|
|
login: LoginOutlined,
|
|
map: MapOutlined,
|
|
menu: MenuOpenOutlined,
|
|
notifications: NotificationsNoneOutlined,
|
|
public: PublicOutlined,
|
|
receipt: ReceiptLongOutlined,
|
|
room: BedroomParentOutlined,
|
|
send: SendOutlined,
|
|
settings: SettingsApplicationsOutlined,
|
|
shield: ShieldOutlined,
|
|
task: TaskAltOutlined,
|
|
users: ManageAccountsOutlined,
|
|
wallet: WalletOutlined
|
|
};
|
|
|
|
export const fallbackNavigation = [
|
|
routeNavItem("overview", { icon: DashboardOutlined }),
|
|
{
|
|
code: "system",
|
|
icon: SettingsApplicationsOutlined,
|
|
id: "system",
|
|
label: "系统管理",
|
|
children: [
|
|
routeNavItem("system-users", { icon: ManageAccountsOutlined }),
|
|
routeNavItem("system-roles", { icon: ShieldOutlined }),
|
|
routeNavItem("system-menus", { icon: MenuOpenOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "app-users",
|
|
icon: ManageAccountsOutlined,
|
|
id: "app-users",
|
|
label: "用户管理",
|
|
children: [
|
|
routeNavItem("app-user-list", { icon: ManageAccountsOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "rooms",
|
|
icon: BedroomParentOutlined,
|
|
id: "rooms",
|
|
label: "房间管理",
|
|
children: [
|
|
routeNavItem("room-list", { icon: BedroomParentOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "app-config",
|
|
icon: SettingsApplicationsOutlined,
|
|
id: "app-config",
|
|
label: "APP配置",
|
|
children: [
|
|
routeNavItem("app-config-h5", { icon: SettingsApplicationsOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "resources",
|
|
icon: Inventory2Outlined,
|
|
id: "resources",
|
|
label: "资源管理",
|
|
children: [
|
|
routeNavItem("resource-list", { icon: Inventory2Outlined }),
|
|
routeNavItem("resource-group-list", { icon: CategoryOutlined }),
|
|
routeNavItem("gift-list", { icon: CardGiftcardOutlined }),
|
|
routeNavItem("resource-grant-list", { icon: SendOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "logs",
|
|
icon: HistoryOutlined,
|
|
id: "logs",
|
|
label: "日志审计",
|
|
children: [
|
|
routeNavItem("logs-login", { icon: LoginOutlined }),
|
|
routeNavItem("logs-operations", { icon: ReceiptLongOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "geo",
|
|
icon: MapOutlined,
|
|
id: "geo",
|
|
label: "地区管理",
|
|
children: [
|
|
routeNavItem("host-org-countries", { icon: PublicOutlined }),
|
|
routeNavItem("host-org-regions", { icon: MapOutlined })
|
|
]
|
|
},
|
|
{
|
|
code: "host-org",
|
|
icon: HubOutlined,
|
|
id: "host-org",
|
|
label: "团队管理",
|
|
children: [
|
|
routeNavItem("host-org-agencies", { icon: ApartmentOutlined }),
|
|
routeNavItem("host-org-bd-leaders", { icon: ShieldOutlined }),
|
|
routeNavItem("host-org-bds", { icon: GroupsOutlined }),
|
|
routeNavItem("host-org-hosts", { icon: ManageAccountsOutlined }),
|
|
routeNavItem("host-org-coin-sellers", { icon: WalletOutlined })
|
|
]
|
|
},
|
|
routeNavItem("notifications", { icon: NotificationsNoneOutlined })
|
|
];
|
|
|
|
export function mapBackendMenus(menus = []) {
|
|
return menus
|
|
.map((item) => {
|
|
if (deprecatedMenuCodes.has(item.code)) {
|
|
return null;
|
|
}
|
|
|
|
const route = item.code ? getRouteByMenuCode(item.code) : undefined;
|
|
const children = item.children?.length ? mapBackendMenus(item.children) : undefined;
|
|
|
|
return {
|
|
children: children?.length ? children : undefined,
|
|
code: item.code,
|
|
icon: iconMap[item.icon] || MenuOpenOutlined,
|
|
id: item.code || String(item.id),
|
|
label: item.label,
|
|
path: route?.path || item.path,
|
|
permissionCode: route?.permission || item.permissionCode
|
|
};
|
|
})
|
|
.filter(Boolean);
|
|
}
|
|
|
|
export function filterNavigationByPermission(items = [], can) {
|
|
return items
|
|
.map((item) => {
|
|
const children = filterNavigationByPermission(item.children || [], can);
|
|
const canViewItem = !item.permissionCode || can(item.permissionCode);
|
|
|
|
if (children.length || (item.path && canViewItem)) {
|
|
return { ...item, children: children.length ? children : undefined };
|
|
}
|
|
|
|
return null;
|
|
})
|
|
.filter(Boolean);
|
|
}
|
|
|
|
export function mergeNavigationItems(primaryItems = [], fallbackItems = []) {
|
|
const merged = primaryItems.map((item) => ({ ...item }));
|
|
const itemByCode = new Map(merged.map((item) => [item.code, item]));
|
|
|
|
fallbackItems.forEach((fallbackItem) => {
|
|
const existing = itemByCode.get(fallbackItem.code);
|
|
if (!existing) {
|
|
merged.push(fallbackItem);
|
|
return;
|
|
}
|
|
|
|
if (fallbackItem.children?.length) {
|
|
existing.children = mergeNavigationItems(existing.children || [], fallbackItem.children);
|
|
}
|
|
});
|
|
|
|
return merged;
|
|
}
|
|
|
|
export function findNavItemByPath(pathname, items = fallbackNavigation) {
|
|
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;
|
|
}
|
|
|
|
function routeNavItem(menuCode, options = {}) {
|
|
const route = getRouteByMenuCode(menuCode);
|
|
return {
|
|
code: menuCode,
|
|
icon: options.icon || MenuOpenOutlined,
|
|
id: menuCode,
|
|
label: route?.label || menuCode,
|
|
path: route?.path,
|
|
permissionCode: route?.permission
|
|
};
|
|
}
|