import Layout from '@/layout' import router from '@/router/index' import store from '@/store' // 映射文件 const staffManagement = { path: 'personnel', name: 'personnel', component: () => import('@/views/personnel/index'), meta: { title: '员工列表', icon: 'example' } } // 监测因子特效 const wind = { path: 'showSensor/wind', name: 'Main', component: () => import('@/views/main/index'), meta: { title: '实时风场图', icon: 'example' } } const car = { path: 'showSensor/car', name: 'car', component: () => import('@/views/car/index'), meta: { title: '道路尘负荷分析', icon: 'example' } } const UAV = { path: 'showSensor/uav', name: 'uav', component: () => import('@/views/UVA/index'), meta: { title: '无人机轨迹', icon: 'example' } } const heatmap = { path: 'showSensor/heatmap', name: 'heatmap', component: () => import('@/views/heatmap/index'), meta: { title: '污染扩散图', icon: 'example' } } const hexagon = { path: 'showSensor/hexagon', name: 'hexagon', component: () => import('@/views/hexagon/index'), meta: { title: '污染蜂窝图', icon: 'example' } } // 监测因子图表 const tend = { path: 'charts/tend', name: 'tend', component: () => import('@/views/charts/index'), meta: { title: '监测因子趋势', icon: 'example' } } const contrast = { path: 'charts/contrast', name: 'contrast', component: () => import('@/views/contrast/index'), meta: { title: '监测因子对比', icon: 'example' } } const averageContrast = { path: 'charts/averageContrast', name: 'averageContrast', component: () => import('@/views/averageContrast/index'), meta: { title: '监测因子均值对比', icon: 'example' } } const O3 = { path: 'charts/O3', name: 'O3', component: () => import('@/views/O3/index'), meta: { title: '臭氧预测', icon: 'example' } } const airPollutionCalendar = { path: 'charts/airPollutionCalendar', name: 'airPollutionCalendar', component: () => import('@/views/airPollutionCalendar/index'), meta: { title: '空气质量污染日历', icon: 'example' } } // 报表管理 const showMpData = { path: 'report/showMpData', name: 'showMpData', component: () => import('@/views/reportForm/index'), meta: { title: '监测站数据显示', icon: 'example' } } const showGovHourData = { path: 'report/showGovHourData', name: 'showGovHourData', component: () => import('@/views/govReport/index'), meta: { title: '国控站小时报表显示', icon: 'example' } } // 空气质量小时播报 const airQualityReportDisplay = { path: 'report/airQualityReportDisplay', name: 'airQualityReportDisplay', component: () => import('@/views/airQualityReportDisplay/index'), meta: { title: '空气质量小时播报', icon: 'example' } } // 综合分析 // 城市空气质量排行 const cityAirRank = { path: 'analyse/cityAirRank', name: 'cityAirRank', component: () => import('@/views/cityAirRank/index'), meta: { title: '城市空气质量排名', icon: 'example' } } // 城市空气质量同期对比 const cityAirYoyContrast = { path: 'analyse/cityAirYoyContrast', name: 'cityAirYoyContrast', component: () => import('@/views/cityAirRank/cityAirYoyContrast'), meta: { title: '城市空气质量同期对比', icon: 'example' } } const levelStatistic = { path: 'analyse/levelStatistic', name: 'levelStatistic', component: () => import('@/views/levelStatistic/index'), meta: { title: '城市优良天统计', icon: 'example' } } const industryContributionRate = { path: 'analyse/industryContributionRate', name: 'industryContributionRate', component: () => import('@/views/industryContributionRate/index'), meta: { title: '行业贡献率', icon: 'example' } } const regionalContributionRate = { path: 'analyse/regionalContributionRate', name: 'regionalContributionRate', component: () => import('@/views/regionalContributionRate/index'), meta: { title: '区域贡献率', icon: 'example' } } const surveyReport = { path: 'analyse/surveyReport', name: 'surveyReport', component: () => import('@/views/surveyReport/index'), meta: { title: '现场勘察报告', icon: 'example' } } // analyse/air const air = { path: 'analyse/air', name: 'air', component: () => import('@/views/air/index'), meta: { title: '空气质量报告', icon: 'example' } } // 映射路由,存入对象 const ruleMapping = { wind: wind, car: car, UAV: UAV, tend: tend, contrast: contrast, O3: O3, showMpData: showMpData, staffManagement: staffManagement, showGovHourData: showGovHourData, cityAirRank: cityAirRank, levelStatistic: levelStatistic, heatmap: heatmap, hexagon: hexagon, airPollutionCalendar: airPollutionCalendar, averageContrast: averageContrast, industryContributionRate, regionalContributionRate, cityAirYoyContrast: cityAirYoyContrast, surveyReport, air, airQualityReportDisplay } // 网络请求,第一次登陆只有4个路由,所以要添加路由,页面刷新的时候,判断大于4个路由,就不会重新添加。 export function getMenus() { if (router.options.routes.length === 4) { store.dispatch('user/getInfo').then(() => { routerMenus() }) } } // 导出路由菜单 export function routerMenus() { const routersMenu = JSON.parse(store.state.user.menus) // 路由分两块,左侧列表, 最右侧员工下拉菜单 const currentRoutes = router.options.routes if (routersMenu.length > 0) { routersMenu.forEach(item => { if (item.url === 'dropDown') { const child = item.children item.component = Layout item.path = '/' + item.url delete item.url delete item.id delete item.children delete item.label delete item.icon item.hidden = true item.children = [] currentRoutes.splice(currentRoutes.length, 0, item) child.forEach(item1 => { const mapUrl = item1.url.substr(item.path.length, item1.url.length) const temp = ruleMapping[mapUrl] if (temp !== undefined) { currentRoutes[currentRoutes.length - 1].children.push(temp) } else { console.log('存在菜单配置给该用户,但是代码中无该组件') } }) } else { const child = item.children item.component = Layout item.meta = { title: item.label, icon: 'form' } item.path = '/' + item.url delete item.url delete item.id delete item.children delete item.label delete item.icon item.children = [] currentRoutes.splice(currentRoutes.length, 0, item) child.forEach(item1 => { const mapUrl = item1.url.substr(item.path.length, item1.url.length) const temp = ruleMapping[mapUrl] if (temp !== undefined) { currentRoutes[currentRoutes.length - 1].children.push(temp) } else { console.log('存在菜单配置给该用户,但是代码中无该组件') } }) } }) } else { // console.log(666) // const notFound = { // path: '*', // component: () => import('@/views/login/index') // } // currentRoutes.splice(currentRoutes.length, 0, notFound) } router.addRoutes(currentRoutes) }