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.
LiaoNingDangAn/src/permission.js

62 lines
1.5 KiB

2 years ago
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";
2 years ago
// 踢出系统
2 years ago
function kickOut() {
if (process.env.NODE_ENV === "production") {
location.href = location.origin + "/login";
}
}
// const whiteList = [
// "/404",
// "/401",
1 year ago
// '/drugArchives',
// "/cosmeticsArchives",
// "/cosmeticsDetail",
// "/health",
// "/zyzj",
// ];
2 years ago
NProgress.configure({ showSpinner: false });
2 years ago
router.beforeEach((to, from, next) => {
NProgress.start();
2 years ago
let token = localStorage.getItem('MSSM-LIAONING__TOKEN')
2 years ago
console.log(to.path);
if (token) {
if (store.state.myselfPermission.routerList.length == 0) {
store.dispatch("GetPermission").then((res) => {
next({path:to.path});
}).catch((error) => {
kickOut();
});
} else {
let current = store.state.myselfPermission.routerList.filter(
(item) => item.path == to.path || from.path == "/"
);
if (current.length > 0) {
next();
} else {
//根据参数判断是否可以跳
if (to.query.type && to.path == '/cosmeticsDetail') {
2 years ago
next();
} else {
Message.error("无权限访问!");
2 years ago
}
}
2 years ago
}
} else {
// 没有token
Message.error("获取令牌失败!");
2 years ago
kickOut();
}
2 years ago
});
router.afterEach(() => {
NProgress.done();
2 years ago
});