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

83 lines
2.1 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";
}
}
2 years ago
NProgress.configure({ showSpinner: false });
const whiteList = [
2 years ago
// "/login",
// "/register",
2 years ago
"/index",
2 years ago
'/drugArchives',
'/cosmeticsArchives',
'/health',
'/productInfo',
'/cosmeticsDetail'
2 years ago
];
router.beforeEach((to, from, next) => {
NProgress.start();
if (getToken()) {
2 years ago
console.log('有token');
2 years ago
to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
/* has token*/
if (to.path === "/login") {
next({ path: "/" });
NProgress.done();
2 years ago
} else {
next();
2 years ago
}
} else {
2 years ago
next()
2 years ago
// 没有token
2 years ago
// if (whiteList.indexOf(to.path) !== -1) {
// next()
// let token = localStorage.getItem("MSSM-LIAONING__TOKEN");
// if (token) {
// if (store.state.myselfPermission.routerList.length > 0) {
// let current = store.state.myselfPermission.routerList.filter(
// (item) => item.path == to.path || from.path == "/"
// );
// if (current.length > 0) {
// next();
// } else {
// next();
// // Message.error("无权限访问!");
// }
// } else {
// store
// .dispatch("GetPermission")
// .then((res) => {
// console.log(res);
// if (res.length > 0) {
// next({ path: res });
// } else {
// kickOut();
// }
// })
// .catch((error) => {
// kickOut();
// });
// }
// } else {
// //没有token踢出去
// Message.error("获取令牌失败!");
// kickOut();
// }
// } else {
// // kickOut();
// NProgress.done();
// }
2 years ago
}
});
router.afterEach(() => {
NProgress.done();
2 years ago
});