You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
import router from "./router";
|
|
import store from "./store";
|
|
import { Message } from "element-ui";
|
|
import NProgress from "nprogress";
|
|
import "nprogress/nprogress.css";
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
// 踢出系统
|
|
function kickOut() {
|
|
// console.log(123132);
|
|
if (process.env.NODE_ENV === "production") {
|
|
setTimeout(() => {
|
|
location.href = location.origin + "/login";
|
|
}, 2000);
|
|
}
|
|
}
|
|
// const whiteList = [
|
|
// "/404",
|
|
// "/401",
|
|
// '/drugArchives',
|
|
// "/cosmeticsArchives",
|
|
// "/cosmeticsDetail",
|
|
// "/health",
|
|
// "/zyzj",
|
|
// ];
|
|
NProgress.configure({ showSpinner: false });
|
|
router.beforeEach((to, from, next) => {
|
|
NProgress.start();
|
|
// if(from.path =='/cosmeticsDetail' || to.path =='/cosmeticsDetail' ){
|
|
// console.log(798,from);
|
|
// from.meta.keepAlive = true
|
|
// // store.commit('SET_ROUTWESHOW')
|
|
// }else{
|
|
// from.meta.keepAlive = true
|
|
// }
|
|
if(JSON.stringify(to.query) != '{}'){
|
|
console.log(777,to.query);
|
|
for (const key in to.query) {
|
|
if(key == "cpbq"){
|
|
if(to.query[key]){
|
|
to.query[key] = to.query[key].split(",")
|
|
}
|
|
}
|
|
}
|
|
store.commit('ADD_QUERY',to.query)
|
|
}
|
|
if (to.query.token) {
|
|
localStorage.setItem('MSSM-LIAONING__TOKEN', to.query.token)
|
|
}
|
|
let token = localStorage.getItem('MSSM-LIAONING__TOKEN')
|
|
if (token) {
|
|
if (store.state.myselfPermission.routerList.length == 0) {
|
|
|
|
store.dispatch("GetPermission").then((res) => {
|
|
// 获取查询参数
|
|
next({ path: to.path });
|
|
// next();
|
|
}).catch((error) => {
|
|
kickOut();
|
|
});
|
|
|
|
} else {
|
|
let current = store.state.myselfPermission.routerList.filter(
|
|
(item) => item.path == to.path || from.path == "/"
|
|
);
|
|
if (current.length > 0) {
|
|
next();
|
|
} else {
|
|
next();
|
|
|
|
//根据参数判断是否可以跳
|
|
// if (to.query.type && to.path == '/cosmeticsDetail') {
|
|
// next();
|
|
// } else {
|
|
// Message.error("无权限访问!");
|
|
// }
|
|
}
|
|
}
|
|
} else {
|
|
// 没有token
|
|
Message.error("获取令牌失败!");
|
|
kickOut();
|
|
}
|
|
});
|
|
|
|
router.afterEach(() => {
|
|
NProgress.done();
|
|
}); |