import Vue from "vue";
|
import VueRouter from "vue-router";
|
import Layouts from "../layouts";
|
import Parent from "../layouts/components/AppContent"
|
import store from "../store";
|
|
Vue.use(VueRouter);
|
const originalPush = VueRouter.prototype.push
|
VueRouter.prototype.push = function push(location) {
|
return originalPush.call(this, location).catch(err => err)
|
}
|
|
/**
|
* path: "/login", ------页面地址
|
component: () => import("../views/login"), ------组件地址
|
name: "Login", ------组件名称 缓存时需要 唯一性
|
meta: {
|
title: "登录", ------页面标题
|
icon: "el-icon-user-solid", ------菜单图标
|
oneself: true, ------是否在单独页面打开
|
hide: true, ------是否隐藏改菜单
|
keepAlive: true, ------是否缓存
|
}
|
*/
|
|
const routes = [
|
{
|
path: "/",
|
redirect: "login",
|
component: Layouts,
|
children: [
|
{
|
path: "/login",
|
meta: {
|
title: "登录",
|
oneself: true,
|
hide: true,
|
},
|
component: () => import("../views/login"),
|
},
|
{
|
path: "/projectList",
|
meta: {
|
title: "项目组管理",
|
},
|
component: Parent,
|
children: [
|
{
|
path: "list",
|
name: "ProjectList",
|
meta: {
|
title: "项目组管理",
|
keepAlive: true,
|
},
|
component: () => import("../views/projectList"),
|
}
|
]
|
},
|
],
|
},
|
];
|
|
const router = new VueRouter({
|
mode: "history",
|
base: process.env.BASE_URL,
|
routes,
|
});
|
|
// 前置路由拦截器
|
router.beforeEach((to, from, next) => {
|
// 设置当前页签名称
|
document.title = to.meta.title || '实验室流程';
|
|
// 判断是否需要缓存
|
if (to.meta.keepAlive) {
|
store.commit('SET_KEEPALIVELIST', [...store.state.keepAliveList, to.name])
|
}
|
// 设置标签列表
|
if (!to.meta.hide || !to.meta.oneself) {
|
// 判断是否存在
|
let isExist = store.state.tagList.some(item => item.path === to.path)
|
if (!isExist) {
|
store.commit('SET_TAGLIST', [...store.state.tagList, to])
|
}
|
}
|
next()
|
|
// 没有登录并且要去的页面不是登录页面,在强制跳转到登录
|
// if (to.path === "/login") {
|
// localStorage.removeItem('userInfo')
|
// next()
|
// } else if (!localStorage.getItem('userInfo')) {
|
// next('/login')
|
// } else {
|
// // 判断是否拥有要跳转菜单权限
|
// let menus = store.state.menus
|
// if (to.meta.hasOwnProperty('privilege') && !menus.includes(to.meta.privilege)) {
|
// return
|
// }
|
// 设置标签列表
|
// if (!to.meta.hide || !to.meta.oneself) {
|
// // 判断是否存在
|
// let isExist = store.state.tagList.some(item => item.path === to.path)
|
// if (!isExist) {
|
// store.commit('SET_TAGLIST', [...store.state.tagList, to])
|
// }
|
// }
|
// // 判断是否需要缓存
|
// if (to.meta.keepAlive) {
|
// store.commit('SET_KEEPALIVELIST', [...store.state.keepAliveList, to.name])
|
// }
|
// next()
|
// }
|
});
|
|
export default router;
|