import { createRouter, createWebHistory, createWebHashHistory, type RouteRecordRaw } from 'vue-router'; export const stairRouteNames: string[] = [ 'homeOverview', //全站总览 'fireControlIndex', //消防系统 'securityIndex', //安全防范 'monitoringIndex', //在线监测 'environmentIndex', //环境监控 'lightingIndex', //照明控制 'waterSupplyIndex' //给排水系统 ]; // 存储楼梯路由与其子菜单的映射关系 export const stairRouteChildrenMap: Map = new Map(); /** * 递归获取菜单的所有子菜单 name(包括孙菜单) * @param menu - 菜单对象 * @param result - 结果数组 */ function collectAllChildrenNames(menu: any, result: string[]) { if (menu.children && menu.children.length > 0) { menu.children.forEach((child: any) => { result.push(child.name); // 递归收集孙菜单 collectAllChildrenNames(child, result); }); } } /** * 构建楼梯路由与子菜单的映射关系 * 遍历所有路由,找到楼梯路由,收集其所有子菜单和孙菜单的 name * 注意:必须在 constantRoutes 定义之后调用 */ function buildStairRouteMap() { constantRoutes.forEach((route: any) => { // 如果路由有子菜单 if (route.children && route.children.length > 0) { // 先收集当前路由下所有的子菜单(包括递归) const allChildrenNames: string[] = []; collectAllChildrenNames(route, allChildrenNames); // 然后检查这些子菜单中哪些是楼梯路由 route.children.forEach((child: any) => { if (stairRouteNames.includes(child.name)) { // 将这个楼梯路由对应的所有子菜单存入 Map stairRouteChildrenMap.set(child.name, allChildrenNames); } }); } }); } export function isStairRoute(routeName: string): boolean { return stairRouteNames.includes(routeName); } export const constantRoutes: Readonly = [ { path: '/', // redirect: '/home/overall/overview' // redirect: '/home/overview?screen=homeOverview', redirect: '/home', meta: { title: '编辑模式', hidden: true, treeHidden: true, bottomHidden: true } }, { path: '/edit', name: 'edit', component: () => import('@/views/edit/index.vue'), meta: { title: '编辑模式', hidden: true, treeHidden: true, bottomHidden: true } }, { path: '/preview', name: 'preview', component: () => import('@/views/preview/index.vue'), meta: { title: '预览模式', hidden: true, treeHidden: true, bottomHidden: true } }, { path: '/test', name: 'test', component: () => import('@/layout/view_index.vue'), meta: { title: '测试页面', hidden: true, treeHidden: true, bottomHidden: true }, children: [ { path: '/test/overview', name: 'testOverview', component: () => import('@/views/preview/test/index.vue'), meta: { title: '测试页面', hidden: true, treeHidden: true, bottomHidden: true } } ] }, { path: '/home', name: 'home', component: () => import('@/layout/view_index.vue'), meta: { title: '全站总览项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/home/overview', name: 'homeOverview', component: () => import('@/views/preview/home/overview.vue'), meta: { title: '全站总览', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Connection' } }, { path: '/home/globalMessage', name: 'homeGlobalMessage', component: () => import('@/views/preview/home/globalMessage.vue'), meta: { title: '全站报文', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Connection' } }, { path: '/home/exceedMessage', name: 'homeExceedMessage', component: () => import('@/views/preview/home/homeOverrunMessage.vue'), meta: { title: '越权信息', hidden: true, treeHidden: false, bottomHidden: true } }, { path: '/home/exceptionFacility', name: 'homeExceptionFacility', component: () => import('@/views/preview/home/homeExceptionFacility.vue'), meta: { title: '异常设备', hidden: true, treeHidden: false, bottomHidden: true } } ] }, { path: '/fireControl', name: 'fireControl', component: () => import('@/layout/view_index.vue'), meta: { title: '消防系统项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/fireControl/index', name: 'fireControlIndex', component: () => import('@/views/preview/fireControl/index.vue'), meta: { title: '消防系统', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Discount' } }, { path: '/fireControl/alarm', name: 'fireControlAlarm', meta: { title: '火警报警项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Bell' }, children: [ { path: '/fireControl/alarm/index', name: 'fireControlAlarmIndex', component: () => import('@/views/preview/fireControl/alarm/index.vue'), meta: { title: '火灾报警', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Bell' } }, { path: '/fireControl/alarm/host', name: 'fireControlAlarmHost', component: () => import('@/views/preview/fireControl/alarm/host.vue'), meta: { title: '火灾报警主机', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Crop' } }, { path: '/fireControl/alarm/floor', name: 'fireControlAlarmFloor', component: () => import('@/views/preview/fireControl/alarm/floor.vue'), meta: { title: '生产综合楼 1 楼', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'OfficeBuilding' } } ] }, { path: '/fireControl/transformer', name: 'fireControlTransformer', meta: { title: '变压器排油注氮灭火项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'MagicStick' }, children: [ { path: '/fireControl/transformer/index', name: 'fireControlTransformerIndex', component: () => import('@/views/preview/fireControl/alarm/transformer/index.vue'), meta: { title: '变压器排油注氮灭火', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'MagicStick' } }, { path: '/fireFighting/transformer/host', name: 'fireFightingTransformerHost', component: () => import('@/views/preview/fireControl/alarm/transformer/host.vue'), meta: { title: '主机', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Monitor' } }, { path: '/fireFighting/transformer/floor', name: 'fireFightingTransformerFloor', // // src\views\preview\fireControl\alarm\transformer\nitrogen.vue component: () => import('@/views/preview/fireControl/alarm/transformer/nitrogen.vue'), meta: { title: '2 号主变排油注氮灭火', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Brush' } } ] }, { path: '/fireFighting/fireCock', name: 'fireFightingFireCock', component: () => import('@/views/preview/fireControl/alarm/fireHydrant.vue'), meta: { title: '消火栓系统', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Place' } }, { path: '/fireFighting/configuration', name: 'fireFightingConfiguration', component: () => import('@/views/preview/fireControl/alarm/fireExtinguisher.vue'), meta: { title: '灭火器配置', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Files' } }, { path: '/fireFighting/indicate', name: 'fireFightingIndicator', // F:\vue\workspace\maotu-webtopo\src\views\preview\fireControl\alarm\indicate.vue component: () => import('@/views/preview/fireControl/alarm/indicate.vue'), meta: { title: '消防应急照明及疏散指示系统', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Sunset' } } ] }, { path: '/security', name: 'security', meta: { title: '安全防范项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/security/index', name: 'securityIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '安全防范', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'CircleCheck' } }, { path: '/security/perimeter', name: 'securityPerimeter', component: () => import('@/views/edit/index.vue'), meta: { title: '变电站周界', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Money' } }, { path: '/security/infrared', name: 'securityInfrared', component: () => import('@/views/edit/index.vue'), meta: { title: '室内红外双鉴', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'SetUp' } }, { path: '/security/accessControl', name: 'accessControl', meta: { title: '门禁控制项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/security/accessControl/index', name: 'securityAccessControlIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '门禁控制', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Refrigerator' } }, { path: '/security/accessControl/controller', name: 'productionBuildingFirstController', component: () => import('@/views/edit/index.vue'), meta: { title: '生产综合楼一楼门禁控制器 项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'OfficeBuilding' } } ] }, { path: '/security/accessRecords', name: 'accessRecords', component: () => import('@/views/edit/index.vue'), meta: { title: '门禁记录', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Document' } } ] }, { path: '/monitoring', name: 'monitoring', meta: { title: '在线监测项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/monitoring/index', name: 'monitoringIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '在线监测', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Notebook' } }, { path: '/monitoring/oilChromatography', name: 'oilChromatographyOnline', component: () => import('@/views/edit/index.vue'), meta: { title: '油色谱在线监测项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Postcard' }, children: [ { path: '/monitoring/oilChromatography/index', name: 'oilChromatographyIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '油色谱在线监测', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Postcard' } }, { path: '/monitoring/oilChromatography/no2', name: 'no2MainTransformerOilChromatography', component: () => import('@/views/edit/index.vue'), meta: { title: '2 号主变油色谱', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'CollectionTag' } } ] }, { path: '/monitoring/partialDischarge', name: 'mainTransformerPartialDischarge', component: () => import('@/views/edit/index.vue'), meta: { title: '主变局放在线监测项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Reading' }, children: [ { path: '/monitoring/partialDischarge/index', name: 'monitoringPartialDischargeIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '主变局放在线监测', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Filter' } }, { path: '/monitoring/partialDischarge/no2', name: 'no2MainTransformerPartialDischarge', component: () => import('@/views/edit/index.vue'), meta: { title: '2 号主变局放', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'CollectionTag' } } ] }, { path: '/monitoring/gisDischarge', name: 'gisPartialDischarge', component: () => import('@/views/edit/index.vue'), meta: { title: 'GIS局放在线监测项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'PieChart' }, children: [ { path: '/monitoring/gisDischarge/index', name: 'gisPartialDischargeIndex', component: () => import('@/views/edit/index.vue'), meta: { title: 'GIS局放在线监测', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Coin' } }, { path: '/monitoring/gisDischarge/switch2215', name: 'switch2215Interval', component: () => import('@/views/edit/index.vue'), meta: { title: '2215 开关间隔', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'CollectionTag' } } ] }, { path: '/monitoring/arrester', name: 'arresterMonitoring', component: () => import('@/views/edit/index.vue'), meta: { title: '避雷器在线监测项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Lightning' }, children: [ { path: '/monitoring/arrester/index', name: 'arresterMonitoringIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '避雷器在线监测', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Lightning' } }, { path: '/monitoring/arrester/220kv', name: 'arrester220kvMonitoring', component: () => import('@/views/edit/index.vue'), meta: { title: '220kV 避雷器在线监测', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'CollectionTag' } } ] }, { path: '/monitoring/sf6Pressure', name: 'gisSf6Pressure', component: () => import('@/views/edit/index.vue'), meta: { title: 'GIS气室SF6 压力监测项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'ChatSquare' }, children: [ { path: '/monitoring/sf6Pressure/index', name: 'gisSf6PressureIndex', component: () => import('@/views/edit/index.vue'), meta: { title: 'GIS气室SF6 压力监测', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Finished' } }, { path: '/monitoring/sf6Pressure/interval2245', name: 'interval2245', component: () => import('@/views/edit/index.vue'), meta: { title: '2245 甲母联间隔', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'CollectionTag' } } ] }, { path: '/monitoring/sf6Leakage', name: 'sf6Leakage', component: () => import('@/views/edit/index.vue'), meta: { title: '室内SF6 气体泄露监测', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Film' } } ] }, { path: '/environment', name: 'environment', meta: { title: '环境监控项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/environment/index', name: 'environmentIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '环境监控', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'MagicStick' } }, { path: '/environment/weather', name: 'substationWeather', component: () => import('@/views/edit/index.vue'), meta: { title: '站区气象监测', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Cloudy' } }, { path: '/environment/acHeating', name: 'buildingAcHeating', meta: { title: '生产综合楼空调暖通项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Sunrise' }, children: [ { path: '/environment/acHeating/index', name: 'buildingAcHeatingIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '生产综合楼空调暖通', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Sunrise' } }, { path: '/environment/acHeating/building', name: 'productionBuilding', component: () => import('@/views/edit/index.vue'), meta: { title: '生产综合楼', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'OfficeBuilding' } } ] }, { path: '/environment/threshold', name: 'thresholdSetting', component: () => import('@/views/edit/index.vue'), meta: { title: '阈值设置', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Operation' } } ] }, { path: '/lighting', name: 'lighting', meta: { title: '照明控制项目', hidden: false, treeHidden: false, bottomHidden: false }, children: [ { path: '/lighting/index', name: 'lightingIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '照明控制', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Sunny' } }, { path: '/lighting/acHeating', name: 'buildingLightingAcHeating', component: () => import('@/views/edit/index.vue'), meta: { title: '生产综合楼1楼空调暖通', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Sunset' } }, { path: '/lighting/linkage', name: 'linkageConfiguration', component: () => import('@/views/edit/index.vue'), meta: { title: '联动配置', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Operation' } } ] }, { path: '/waterSupply', name: 'waterSupply', meta: { title: '给排水系统项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Operation' }, children: [ { path: '/waterSupply/index', name: 'waterSupplyIndex', component: () => import('@/views/edit/index.vue'), meta: { title: '给排水系统', hidden: true, treeHidden: false, bottomHidden: true, menuIcon: 'Pouring' } }, { path: '/waterSupply/waterSupply', name: 'waterSupplySystem', component: () => import('@/views/edit/index.vue'), meta: { title: '给水系统', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Place' } }, { path: '/waterSupply/drainage', name: 'drainageSystem', component: () => import('@/views/edit/index.vue'), meta: { title: '排水系统', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'MapLocation' } }, { path: '/waterSupply/threshold', name: 'waterThresholdSetting', component: () => import('@/views/edit/index.vue'), meta: { title: '阈值设置', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Setting' } } ] }, { path: '/systemInfo', //F:\vue\workspace\maotu-webtopo\src\views\preview\systemInfo\index.vue name: 'systemInfo', component: () => import('@/layout/view_index.vue'), meta: { title: '系统监控项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Operation' }, children: [ { path: '/systemInfo/index', name: 'systemInfoIndex', component: () => import('@/views/preview/systemInfo/index.vue'), meta: { title: '系统监控', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Setting' } } ] }, { path: '/classify', //F:\vue\workspace\maotu-webtopo\src\views\preview\classify\index.vue name: 'classify', component: () => import('@/layout/view_index.vue'), meta: { title: '设备分类项目', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Operation' }, children: [ { path: '/classify/index', name: 'classifyIndex', component: () => import('@/views/preview/classify/index.vue'), meta: { title: '设备分类', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Setting' } } ] }, { path: '/test', //F:\vue\workspace\maotu-webtopo\src\views\preview\systemInfo\index.vue name: 'test', component: () => import('@/layout/view_index.vue'), meta: { title: '测试页面', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Operation' }, children: [ { path: '/test/index', name: 'testIndex', component: () => import('@/views/preview/test/index.vue'), meta: { title: '测试页面', hidden: false, treeHidden: false, bottomHidden: false, menuIcon: 'Setting' } } ] } ]; // 获取基础路径 - 支持部署到子目录 const getBasePath = () => { // 如果部署在子目录下,需要设置正确的 base 路径 // 例如部署在 /myapp/ 下,则 base 应该是 '/myapp/' const baseUrl = import.meta.env.BASE_URL || '/'; return baseUrl; }; const router = createRouter({ history: createWebHashHistory(getBasePath()), // hash 模式:createWebHashHistory,history 模式:createWebHistory routes: constantRoutes }); // 初始化时构建楼梯路由映射关系 buildStairRouteMap(); export default router;