import React from "react"; import { DashboardOutlined, FileProtectOutlined, TeamOutlined, BankOutlined, UserSwitchOutlined, IdcardOutlined, SafetyCertificateOutlined, ToolOutlined, UserOutlined, BarChartOutlined, PieChartOutlined, ExperimentOutlined, } from "@ant-design/icons"; const menuItems = [ { key: "/certificate/container/Supervision", label: "监管端", icon: , children: [ { key: "/certificate/container/Supervision/EnterpriseLicense", label: "企业证照", icon: , children: [ { key: "/certificate/container/Supervision/EnterpriseLicense/EnterpriseLicense", label: "企业证照管理", icon: , }, { key: "/certificate/container/Supervision/EnterpriseLicense/BranchStatistics/List", label: "分公司统计", icon: , }, { key: "/certificate/container/Supervision/EnterpriseLicense/StakeholderStatistics/List", label: "干系人统计", icon: , }, ], }, { key: "/certificate/container/Supervision/PersonnelLicense", label: "人员证照", icon: , children: [ { key: "/certificate/container/Supervision/PersonnelLicense/PersonInCharge/List", label: "负责人", icon: , }, { key: "/certificate/container/Supervision/PersonnelLicense/SecurityAdmini/List", label: "安全管理员", icon: , }, { key: "/certificate/container/Supervision/PersonnelLicense/SpecialDevice/List", label: "特种设备", icon: , }, { key: "/certificate/container/Supervision/PersonnelLicense/SpecialPersonnel/List", label: "特种作业人员", icon: , }, { key: "/certificate/container/Supervision/PersonnelLicense/BranchCompanyStat/List", label: "分公司人员统计", icon: , }, { key: "/certificate/container/Supervision/PersonnelLicense/StakeholderStat/List", label: "干系人人员统计", icon: , }, ], }, ], }, { key: "/certificate/container/BranchCompany", label: "分公司端", icon: , children: [ { key: "/certificate/container/BranchCompany/EnterpriseLicense/EnterpriseLicense", label: "企业证照管理", icon: , }, { key: "/certificate/container/BranchCompany/PersonnelLicense", label: "人员证照", icon: , children: [ { key: "/certificate/container/BranchCompany/PersonnelLicense/PersonInCharge/List", label: "负责人", icon: , }, { key: "/certificate/container/BranchCompany/PersonnelLicense/SecurityAdmini/List", label: "安全管理员", icon: , }, { key: "/certificate/container/BranchCompany/PersonnelLicense/SpecialDevice/List", label: "特种设备", icon: , }, { key: "/certificate/container/BranchCompany/PersonnelLicense/SpecialPersonnel/List", label: "特种作业人员", icon: , }, ], }, ], }, { key: "/certificate/container/Stakeholder", label: "干系人端", icon: , children: [ { key: "/certificate/container/Stakeholder/EnterpriseLicense/EnterpriseLicense", label: "企业证照管理", icon: , }, { key: "/certificate/container/Stakeholder/PersonnelLicense", label: "人员证照", icon: , children: [ { key: "/certificate/container/Stakeholder/PersonnelLicense/PersonInCharge/List", label: "负责人", icon: , }, { key: "/certificate/container/Stakeholder/PersonnelLicense/SecurityAdmini/List", label: "安全管理员", icon: , }, { key: "/certificate/container/Stakeholder/PersonnelLicense/SpecialDevice/List", label: "特种设备", icon: , }, { key: "/certificate/container/Stakeholder/PersonnelLicense/SpecialPersonnel/List", label: "特种作业人员", icon: , }, ], }, ], }, { key: "/certificate/container/Test", label: "测试页面", icon: , }, ]; export default menuItems; /** 扁平化菜单 */ export function flattenMenu(items) { const result = []; function walk(list) { for (const item of list) { result.push(item); if (item.children) walk(item.children); } } walk(items); return result; } /** * 根据路径查找面包屑路径 * 返回从根到叶子节点的菜单项数组 */ export function findMenuPath(path) { function search(items, ancestors) { for (const item of items) { const current = [...ancestors, item]; if (item.key === path) { return current; } if (item.children) { const found = search(item.children, current); if (found) return found; } } return null; } return search(menuItems, []) || []; } /** * 根据路径获取页面标签名 */ export function getPageLabel(path) { const flat = flattenMenu(menuItems); const item = flat.find((m) => m.key === path); return item?.label || path.split("/").filter(Boolean).pop() || "未命名页面"; } /** * 根据路径获取默认展开的菜单项 */ export function getOpenKeys(path) { const breadcrumb = findMenuPath(path); return breadcrumb.slice(0, -1).map((i) => i.key); } /** * 根据路径获取选中的菜单项 */ export function getSelectedKeys(path) { const allPaths = flattenMenu(menuItems).map((m) => m.key); let match = ""; for (const p of allPaths) { if (path.startsWith(p) && p.length > match.length) { match = p; } } return match ? [match] : []; }