|
|
@ -33,6 +33,8 @@ router.beforeEach(async (to, from, next) => { |
|
|
|
await store.dispatch('definition/getDefinitionConfig') |
|
|
|
} |
|
|
|
|
|
|
|
// 是否已尝试过自动登录
|
|
|
|
const alreadyTryLogin = localStorage.getItem('alreadyTryLogin') |
|
|
|
// 是否有用户信息:
|
|
|
|
const userInfo = store.getters.currentUserInfo |
|
|
|
// 判断是否自动登录
|
|
|
@ -47,11 +49,15 @@ router.beforeEach(async (to, from, next) => { |
|
|
|
next() |
|
|
|
}else{ |
|
|
|
console.log('-------当前路由不是登录页-------') |
|
|
|
if(userInfo){ |
|
|
|
console.log('-------当前有用户信息-------',userInfo) |
|
|
|
if((userInfo && userInfo.id) || alreadyTryLogin == 'true'){ |
|
|
|
if(userInfo && userInfo.id){ |
|
|
|
console.log('-------当前有用户信息-------',userInfo) |
|
|
|
}else{ |
|
|
|
console.log('-------当前没有用户信息,但是已尝试过登录-------') |
|
|
|
} |
|
|
|
next() |
|
|
|
}else{ |
|
|
|
console.log('-------当前没有用户信息-------',userInfo) |
|
|
|
console.log('-------当前没有用户信息-------') |
|
|
|
if(isAutoLogin || to.query.loginName){ |
|
|
|
let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress") |
|
|
|
console.log('-------要求自动登录-------',isAutoLogin,to.query.loginName,_username) |
|
|
@ -66,6 +72,7 @@ router.beforeEach(async (to, from, next) => { |
|
|
|
// login(loginForm).then(()=>{
|
|
|
|
await store.dispatch('user/getUserInfo',_username).then(()=>{ |
|
|
|
console.log("-------用户信息获取成功-------") |
|
|
|
localStorage.setItem('alreadyTryLogin',true) |
|
|
|
next({ |
|
|
|
...to, |
|
|
|
query:{ |
|
|
@ -76,6 +83,7 @@ router.beforeEach(async (to, from, next) => { |
|
|
|
replace: true |
|
|
|
}) |
|
|
|
}).catch(()=>{ |
|
|
|
localStorage.setItem('alreadyTryLogin',true) |
|
|
|
next() |
|
|
|
// next({
|
|
|
|
// path:'/login',
|
|
|
@ -108,6 +116,8 @@ router.beforeEach(async (to, from, next) => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
localStorage.setItem('alreadyTryLogin',false) |
|
|
|
}) |
|
|
|
|
|
|
|
router.afterEach(() => { |
|
|
|