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() { if (process.env.NODE_ENV === "production") { location.href = location.origin + "/login"; } } NProgress.configure({ showSpinner: false }); const routerSList = [ '/drugArchives', '/cosmeticsArchives', '/health', ]; router.beforeEach((to, from, next) => { NProgress.start(); let token = localStorage.getItem('MSSM-LIAONING__TOKEN') if (token) { if(to.path == '/cosmeticsDetail' && routerSList.indexOf(from.path) == -1){ next({ path: '/' }) }else { next() } 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 { Message.error("无权限访问!"); } } else { store .dispatch("GetPermission") .then((res) => { console.log(res); if (res.length > 0) { next(); } else { kickOut(); } }) .catch((error) => { kickOut(); }); } } else { // 没有token Message.error("获取令牌失败!"); kickOut(); NProgress.done(); } }); router.afterEach(() => { NProgress.done(); });