|
|
@ -14,6 +14,7 @@ NProgress.configure({ |
|
|
|
const whiteList = ['/login','/callback'] // no redirect whitelist
|
|
|
|
const noUserMsg = '获取用户信息失败,请重新登录 !' |
|
|
|
const getErrMsg = '数据获取失败 !' |
|
|
|
const hasToken = getToken() |
|
|
|
|
|
|
|
// 跳转登录页
|
|
|
|
const pageToLogin = (to, from, next) => { |
|
|
@ -33,9 +34,12 @@ const pageToLogin = (to, from, next) => { |
|
|
|
const toPageInit = async (to, from, next) => { |
|
|
|
|
|
|
|
// 获取用户信息
|
|
|
|
let _username = localStorage.getItem("isLoginTokenName")//登录成功且token通过后的登录名
|
|
|
|
if(_username && _username != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){ |
|
|
|
await store.dispatch('user/getUserInfo',_username) |
|
|
|
// let _userName = localStorage.getItem("isLoginTokenName")//使用用户名获取
|
|
|
|
// if(_userName && _userName != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
|
|
|
|
// await store.dispatch('user/getUserInfo',_userName)//使用用户名获取
|
|
|
|
let _user_access = hasToken.substring(hasToken.indexOf(" ") + 1,hasToken.length) |
|
|
|
if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){ |
|
|
|
await store.dispatch('user/getUserInfoByToken',_user_access) |
|
|
|
.then(()=>{ |
|
|
|
toNextHandle(to, from, next) |
|
|
|
}) |
|
|
@ -66,10 +70,17 @@ const toNextHandle = async (to, from, next) => { |
|
|
|
// 获取菜单数据
|
|
|
|
if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){ |
|
|
|
isFresh = true |
|
|
|
await store.dispatch('permission/getApiColumnsNames').catch(()=>{ |
|
|
|
Message.error(getErrMsg) |
|
|
|
NProgress.done() |
|
|
|
}) |
|
|
|
await store.dispatch('permission/getApiColumnsNames') |
|
|
|
.then(res=>{ |
|
|
|
// 没有权限(token失效处理)
|
|
|
|
if(!res || res.length <=0){ |
|
|
|
store.dispatch("user/logout") |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(()=>{ |
|
|
|
Message.error(getErrMsg) |
|
|
|
NProgress.done() |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// 获取枚举数据
|
|
|
@ -95,7 +106,6 @@ router.beforeEach(async (to, from, next) => { |
|
|
|
// set page title
|
|
|
|
document.title = getPageTitle() |
|
|
|
|
|
|
|
const hasToken = getToken() |
|
|
|
// 判断是否自动登录
|
|
|
|
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName |
|
|
|
|
|
|
|