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.

65 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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],
}