import {getToken} from "../utils/authUtil" import {loadRoutes} from "../utils/routerUtils" import vue from '../main'; /** * 登录守卫白名单 */ const whiteList = ['/','/threeDimensionalSchool','/dynamic','/traditional'] /** * 登录守卫 */ const loginGuard = (to, from, next, options) => { let toPath = to.path; if(whiteList.indexOf(toPath) !== -1){ //白名单 放行 next(); return } const {store} = options // 如果state已经被持久化到本地存储,可以从state里取值,此时刷新页面vuex的state值不会丢失 const user = store.state.userStore.user; // 判断cookie中是否有人员信息 const hasToken = getToken(); //localStorage和cookie均校验 if (hasToken && user && user.personId) { if(toPath === "/teachingCenter"){ //跳转教学中心 window.location.href="https://www.edusoa.com/dsideal_yy/DataCenter_yp/TeachCenter.html"; return; } if(toPath === "/resourcesCenter"){ //跳转教学中心 window.location.href="https://www.edusoa.com/dsideal_yy/DataCenter_yp/ResourceCenter.html"; return; } if(toPath === "/monitorCenter/information"){ //跳转教学中心 window.location.href="https://www.edusoa.com/dsideal_yy/DataCenter_yp/DataCenter.html"; return; } //如果cookie中有登录信息,且路由为login则跳转到根路由 // 加载动态路由 // loadRoutes(options); if (to.path === '/') { next({path: '/'}) } else { next() } } else { // if (to.name === 'login') { // next(); // } else { // next({replace: true, name: 'login'}); // } //未登录 弹出登录框 //vue.$store.commit('userStore/setShowLoginBox',true); vue.$bus.emit('show-login-panel') } } export default { beforeEachArray: [loginGuard], }