|
@ -16,6 +16,16 @@ const loginErr = '登录失败,请重新登录 !' |
|
|
const getErrMsg = '数据获取失败 !' |
|
|
const getErrMsg = '数据获取失败 !' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 退出登录处理
|
|
|
|
|
|
const logoutHandle = (msg) => { |
|
|
|
|
|
if(msg){ |
|
|
|
|
|
Message.error(msg) |
|
|
|
|
|
} |
|
|
|
|
|
setTimeout(()=>{ |
|
|
|
|
|
store.dispatch("user/logout") |
|
|
|
|
|
},0) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 跳转登录页
|
|
|
// 跳转登录页
|
|
|
const pageToLogin = (to, from, next) => { |
|
|
const pageToLogin = (to, from, next) => { |
|
|
if (whiteList.indexOf(to.path) >= 0 ) { |
|
|
if (whiteList.indexOf(to.path) >= 0 ) { |
|
@ -54,8 +64,7 @@ const toPageInit = async (to, from, next) => { |
|
|
if(getToken()){ |
|
|
if(getToken()){ |
|
|
toNextHandle(to, from, next) |
|
|
toNextHandle(to, from, next) |
|
|
}else{ |
|
|
}else{ |
|
|
Message.error('暂无token,请重新登录') |
|
|
logoutHandle('暂无token,请重新登录') |
|
|
store.dispatch("user/logout") |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -65,11 +74,12 @@ const getErrHandle = (to, from, next) => { |
|
|
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName |
|
|
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName |
|
|
Message.error(getErrMsg) |
|
|
Message.error(getErrMsg) |
|
|
if(!isAutoLogin){ |
|
|
if(!isAutoLogin){ |
|
|
store.dispatch("user/logout") |
|
|
logoutHandle() |
|
|
} |
|
|
} |
|
|
NProgress.done() |
|
|
NProgress.done() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 跳转处理
|
|
|
// 跳转处理
|
|
|
const toNextHandle = async (to, from, next) => { |
|
|
const toNextHandle = async (to, from, next) => { |
|
|
let isFresh = false |
|
|
let isFresh = false |
|
@ -82,14 +92,13 @@ const toNextHandle = async (to, from, next) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取菜单数据 permission_routes
|
|
|
// 获取菜单数据 permission_routes
|
|
|
if(!store.getters.addRoutes || store.getters.addRoutes.length <= 0){ |
|
|
if(!store.getters.hasApiToken){ |
|
|
isFresh = true |
|
|
isFresh = true |
|
|
await store.dispatch('permission/getAppConfig') |
|
|
await store.dispatch('permission/getAppConfig') |
|
|
.then(res=>{ |
|
|
.then((res)=>{ |
|
|
// 没有权限(token失效处理)
|
|
|
// 没有权限(token失效处理)
|
|
|
if(!res || res.length <=0){ |
|
|
if(!res || !res.auth || !res.auth.grantedPolicies || JSON.stringify(res.auth.grantedPolicies) == '{}'){ |
|
|
Message.error('用户无权限或者token失效,请配置权限或重新登录') |
|
|
logoutHandle('用户无权限或者token失效,请配置权限或重新登录') |
|
|
store.dispatch("user/logout") |
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.catch(()=>{ |
|
|
.catch(()=>{ |
|
|