优化登录超时逻辑

master
李春波 2 years ago
parent 230792fc3b
commit c0f2a2de07
  1. 10
      front/src/store/modules/user.js
  2. 24
      front/src/utils/request.js
  3. 5
      front/src/views/user/Login.vue

@ -98,6 +98,16 @@ const user = {
}).finally(() => {
})
})
},
// 删除 token
RemoveToken({commit}) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
storage.remove(ACCESS_TOKEN)
resolve()
})
}
}

@ -29,17 +29,33 @@ const errorHandler = (error) => {
message: '404',
description: '请求地址不存在'
})
} else if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
} else if (error.response.status === 401) {
notification.error({
message: 'Unauthorized',
description: 'Authorization verification failed'
message: '登录失效',
description: '登录失效,请重新登录'
})
if (token) {
store.dispatch('Logout').then(() => {
store.dispatch('RemoveToken').then(() => {
setTimeout(() => {
window.location.reload()
}, 1500)
})
} else {
window.location.reload()
}
} else if (error.response.status === 402) {
notification.error({
message: '登录超时',
description: '登录超时,请重新登录'
})
if (token) {
store.dispatch('RemoveToken').then(() => {
setTimeout(() => {
window.location.reload()
}, 1500)
})
} else {
window.location.reload()
}
}
}

@ -116,8 +116,8 @@
<script>
import md5 from 'md5'
import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha'
import { mapActions } from 'vuex'
import { timeFix } from '@/utils/util'
import {mapActions} from 'vuex'
import {timeFix} from '@/utils/util'
// import { getSmsCaptcha, get2step } from '@/api/login'
export default {
@ -247,7 +247,6 @@ export default {
})
},
loginSuccess (res) {
console.log(res)
// check res.homePage define, set $router.push name res.homePage
// Why not enter onComplete
/*

Loading…
Cancel
Save