|
@ -14,7 +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) => { |
|
@ -24,7 +24,8 @@ const pageToLogin = (to, from, next) => { |
|
|
NProgress.done() |
|
|
NProgress.done() |
|
|
} else { |
|
|
} else { |
|
|
// other pages that do not have permission to access are redirected to the login page.
|
|
|
// other pages that do not have permission to access are redirected to the login page.
|
|
|
removeToken() |
|
|
// removeToken()
|
|
|
|
|
|
store.dispatch('user/resetToken') |
|
|
next(`/login?redirect=${to.path}`) |
|
|
next(`/login?redirect=${to.path}`) |
|
|
NProgress.done() |
|
|
NProgress.done() |
|
|
} |
|
|
} |
|
@ -32,27 +33,32 @@ const pageToLogin = (to, from, next) => { |
|
|
|
|
|
|
|
|
// 首次进入页面加载数据处理
|
|
|
// 首次进入页面加载数据处理
|
|
|
const toPageInit = async (to, from, next) => { |
|
|
const toPageInit = async (to, from, next) => { |
|
|
|
|
|
// const hasToken = getToken()
|
|
|
// 获取用户信息
|
|
|
// // 获取用户信息
|
|
|
// let _userName = localStorage.getItem("isLoginTokenName")//使用用户名获取
|
|
|
// // 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) |
|
|
// let _user_access = hasToken.substring(hasToken.indexOf(" ") + 1,hasToken.length)
|
|
|
if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){ |
|
|
// if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
|
|
|
await store.dispatch('user/getUserInfoByToken',_user_access) |
|
|
// await store.dispatch('user/getUserInfoByToken',_user_access)
|
|
|
.then(()=>{ |
|
|
// .then(()=>{
|
|
|
toNextHandle(to, from, next) |
|
|
// toNextHandle(to, from, next)
|
|
|
}) |
|
|
// })
|
|
|
.catch(()=>{ |
|
|
// .catch(()=>{
|
|
|
// todo-fast:接口恢复后更改
|
|
|
// // todo-fast:接口恢复后更改
|
|
|
|
|
|
// toNextHandle(to, from, next)
|
|
|
|
|
|
// // Message.error(noUserMsg)
|
|
|
|
|
|
// // pageToLogin(to, from, next)
|
|
|
|
|
|
// })
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
if(getToken()){ |
|
|
toNextHandle(to, from, next) |
|
|
toNextHandle(to, from, next) |
|
|
// Message.error(noUserMsg)
|
|
|
}else{ |
|
|
// pageToLogin(to, from, next)
|
|
|
Message.error('暂无token,请重新登录') |
|
|
}) |
|
|
store.dispatch("user/logout") |
|
|
return |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
toNextHandle(to, from, next) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 跳转处理
|
|
|
// 跳转处理
|
|
@ -67,13 +73,14 @@ const toNextHandle = async (to, from, next) => { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取菜单数据
|
|
|
// 获取菜单数据 permission_routes
|
|
|
if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){ |
|
|
if(!store.getters.addRoutes || store.getters.addRoutes.length <= 0){ |
|
|
isFresh = true |
|
|
isFresh = true |
|
|
await store.dispatch('permission/getApiColumnsNames') |
|
|
await store.dispatch('permission/getAppConfig') |
|
|
.then(res=>{ |
|
|
.then(res=>{ |
|
|
// 没有权限(token失效处理)
|
|
|
// 没有权限(token失效处理)
|
|
|
if(!res || res.length <=0){ |
|
|
if(!res || res.length <=0){ |
|
|
|
|
|
Message.error('用户无权限或者token失效,请重新登录') |
|
|
store.dispatch("user/logout") |
|
|
store.dispatch("user/logout") |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
@ -106,6 +113,8 @@ 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 |
|
|
|
|
|
|
|
@ -131,25 +140,27 @@ router.beforeEach(async (to, from, next) => { |
|
|
console.log('没有token,是登录页,pageToLogin') |
|
|
console.log('没有token,是登录页,pageToLogin') |
|
|
pageToLogin(to, from, next) |
|
|
pageToLogin(to, from, next) |
|
|
} else { |
|
|
} else { |
|
|
// todo:自动登录,即没有密码登录情况处理
|
|
|
// 如果有单点登录方式使用下方配置
|
|
|
mgr.signinRedirect(); //执行重定向
|
|
|
// mgr.signinRedirect(); //执行重定向
|
|
|
|
|
|
if(isAutoLogin){ |
|
|
// if(isAutoLogin){
|
|
|
let _username = localStorage.getItem("isConfigLogin") && localStorage.getItem("isConfigLogin") != 'false' ? localStorage.getItem("configLoginName") : to.query.loginName |
|
|
// let _username = localStorage.getItem("isConfigLogin") && localStorage.getItem("isConfigLogin") != 'false' ? localStorage.getItem("configLoginName") : to.query.loginName
|
|
|
await store.dispatch('user/login', { |
|
|
// await store.dispatch('user/loginOnlyName', {username:_username})
|
|
|
username:_username, |
|
|
// .then(()=>{
|
|
|
password:localStorage.getItem("configLoginPass") |
|
|
// toPageInit(to, from, next)
|
|
|
}) |
|
|
// })
|
|
|
.then(()=>{ |
|
|
// .catch(()=>{
|
|
|
toPageInit(to, from, next) |
|
|
// // todo-fast:接口恢复后更改
|
|
|
}) |
|
|
// toNextHandle(to, from, next)
|
|
|
.catch(()=>{ |
|
|
// // Message.error(noUserMsg)
|
|
|
// todo-fast:接口恢复后更改
|
|
|
// // pageToLogin(to, from, next)
|
|
|
toNextHandle(to, from, next) |
|
|
// })
|
|
|
// Message.error(noUserMsg)
|
|
|
// }else{
|
|
|
|
|
|
// console.log('没有token,不是登录页,不是自动登录,pageToLogin')
|
|
|
|
|
|
// pageToLogin(to, from, next)
|
|
|
// pageToLogin(to, from, next)
|
|
|
// }
|
|
|
}) |
|
|
|
|
|
}else{ |
|
|
|
|
|
console.log('没有token,不是登录页,不是自动登录,pageToLogin') |
|
|
|
|
|
pageToLogin(to, from, next) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|