import Vue from "vue";
import Router from "vue-router";
import store from "@/store";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import { getToken } from "@/utils/auth";
import { getMenuInfo } from "@/api/menu.js";
// import { MENU_TYPE } from '@/optionsCfg/Constants'
// import Cookies from 'js-cookie'
// import { Decrypt } from '@/utils/crypto'
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading
Vue.use(Router);
/* Layout */
// import Layout from '../views/layout/Layout'
/**
* hidden: true if `hidden:true` will not show in the sidebar(default is false)
* redirect: noredirect if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name' the name is used by <keep-alive> (must set!!!)
* meta : {
title: 'title' the name show in submenu and breadcrumb (recommend set)
icon: 'svg-name' the icon show in the sidebar,
}
**/
// const _import = require('./_import_development')
const Login = process.config.indexPage || "Login";
export const constantRouterMap = [
{
path: "/",
redirect: "/backend",
},
{
path: "/backend",
component: () => import("@/pages/common/Backend"),
},
{
path: "/login",
component: () => import(`@/pages/common/${Login}`),
},
{
path: "*",
component: () => import("@/pages/common/404"),
},
{
path: "/404",
component: () => import("@/pages/common/404"),
},
];
const router = new Router({
// mode: 'history', //后端支持可开
scrollBehavior: () => ({ y: 0 }),
routes: constantRouterMap,
});
const whiteList = ["/login", "/404"];
router.beforeEach(async (to, from, next) => {
NProgress.start();
if (getToken()) {
if (!store.getters.userInfo) {
await store.dispatch("appInit");
}
try {
// 首次进入页面或者刷新页面时获取菜单列表
let res = await getMenuInfo();
if (Object.keys(res).length > 0) {
const realMenuList = res.menuList.filter((v) => v.code !== "PERM_10158");
// // 巡检规则
// realMenuList[2].children.push({
// "code": "PERM_12222",
// "parentCode": "PERM_10000",
// "title": "巡检规则",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/inspect/InspectionRules"
// })
// // 任务管理
// realMenuList[2].children.push({
// "code": "PERM_13333",
// "parentCode": "PERM_10000",
// "title": "任务管理",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/inspect/TaskManage"
// })
// // 日常巡查
// realMenuList[2].children.push({
// "code": "PERM_14444",
// "parentCode": "PERM_10000",
// "title": "日常巡查",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/conservation-management/DailyInspectionV3"
// })
// // 雨季巡查
// realMenuList[2].children.push({
// "code": "PERM_15555",
// "parentCode": "PERM_10000",
// "title": "雨季巡查",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/conservation-management/RainyInspection"
// })
// 声光监测管理
// realMenuList[3].children.push({
// "code": "PERM_166666",
// "parentCode": "PERM_10000",
// "title": "声光监测管理",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/sound-light-monitoring/SoundLightMonitoringManagement"
// })
// 检查评定 -> 检查统计
// realMenuList[2].children.push({
// "code": "PERM_1111",
// "parentCode": "PERM_10000",
// "title": "检查统计",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/inspect/CheckStatistics"
// })
// 增加测点维护,开发模式使用
// realMenuList[1].children.push({
// "code":"PERM_1111",
// "parentCode":"PERM_10000",
// "title":"测点维护",
// "resourceType":"2",
// "icon":"iconrenyuanjibenxinxi",
// "componentPath":"@/pages/point-management/MointorPointMaintenance"
// })
// 程序日志管理
// realMenuList[realMenuList.length - 1].children.push({
// "code": "PERM_10282",
// "parentCode": "PERM_10000",
// "title": "程序日志管理",
// "resourceType": "2",
// "icon": "iconcalendar",
// "componentPath": "@/pages/system-management/application-log/AppLog"
// }, {
// "code": "PERM_10344",
// "parentCode": "PERM_10000",
// "title": "审计日志管理",
// "resourceType": "2",
// "icon": "iconcalendar",
// "componentPath": "@/pages/system-management/auditlogs-management/AudiLogsManagement"
// })
// 监测雷达,开发模式使用
// realMenuList[1].children.push({
// "code":"PERM_1111",
// "parentCode":"PERM_10000",
// "title":"监测雷达",
// "resourceType":"2",
// "icon":"iconrenyuanjibenxinxi",
// "componentPath":"@/pages/radar-monitoring/RadarMonitoring.vue"
// })
// insar管理,开发模式使用 ================
// realMenuList[1].children.push({
// "code": "PERM_1111",
// "parentCode": "PERM_10000",
// "title": "insar管理",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/insar-management/InsarManagement.vue"
// })
// realMenuList[1].children.push({
// "code": "PERM_2222",
// "parentCode": "PERM_12222",
// "title": "insarprotobuf监测",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/insar-data-show/InsarDataShowForProtoBuf.vue"
// })
// realMenuList[1].children.push({
// "code": "PERM_22221",
// "parentCode": "PERM_12222",
// "title": "基础数据库V2",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/basic-information/BasicInformationV2.vue"
// })
// realMenuList[1].children.push({
// "code": "PERM_22222",
// "parentCode": "PERM_12222",
// "title": "基础数据库V3",
// "resourceType": "2",
// "icon": "iconrenyuanjibenxinxi",
// "componentPath": "@/pages/basic-information/BasicInformationV3.vue"
// })
// 储存菜单和功能列表
store.commit("SET_FUNCTION", res.functionList);
store.commit("SET_BACKENDMENULIST", realMenuList);
}
} catch (e) {
console.warn(e);
// ElementUI.Message.error(e && e.message);
await store.dispatch("LogOut");
location.reload();
}
/**
* 已登录,拦截登录页
*/
if (to.path === "/login") {
/**
* 存在token时,如果是虎门则直接跳转登录页,否则跳转首页
*/
switch (process.config.projectCode) {
case "humen":
store
.dispatch("LogOut")
.then(() => {
// 增加延迟显示退出登录提示, reload 为了重新实例化vue-router对象 避免bug
setTimeout(() => void location.reload(), 500);
})
.catch((e) => {
console.error(e);
});
break;
default:
next("/");
}
NProgress.done();
/**
* 判断权限能不能进去后台管理系统
*/
// } else if (to.path === `/${MENU_TYPE.MENU_BACKEND}`) {
// if (JSON.parse(Decrypt(Cookies.get('IS_ADMIN')))) {
// next()
// } else {
// // 无权限跳转404页
// next({ path: '*' })
// NProgress.done()
// }
} else {
next();
}
} else {
if (whiteList.includes(to.path)) {
next();
} else {
next("/login");
NProgress.done();
}
}
});
router.afterEach(() => {
NProgress.done();
});
export default router;以下面这个为例子
if (sysMenu.title === "系统管理") {
sysMenu.children.push({
code: "featureValueConfig",
title: "特征值查询与分析",
icon: "iconcailiaodan",
componentPath: "@/pages/system-management/eigenValue-management/EigenValueManagement"
});
}如何在index.js里加入@/page/building/projectManagement路径的界面