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