# 优化登录过期提示
This commit is contained in:
parent
a0fc07809a
commit
e2af5b3fa6
|
@ -64,16 +64,24 @@ service.interceptors.response.use(
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
if (error && error.response) { // 401 token 过期
|
if (error && error.response) { // 401 token 过期
|
||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
MessageBox.confirm('登录过期已被登出,取消继续留在该页面,或者重新登录', '确定登出', {
|
const ret = error.response
|
||||||
confirmButtonText: '重新登录',
|
const url = ret.config.url
|
||||||
cancelButtonText: '取消',
|
const target = '/users/info'
|
||||||
type: 'warning'
|
console.log(url.indexOf(target))
|
||||||
}).then(() => {
|
// check if 401 get /api/users/info/ then redirect to /login
|
||||||
store.dispatch('FedLogOut').then(() => {
|
if (url.indexOf(target) === -1) {
|
||||||
location.reload() // 为了重新实例化vue-router对象 避免bug
|
MessageBox.confirm('登录过期已被登出,取消继续留在该页面,或者重新登录', '确定登出', {
|
||||||
|
confirmButtonText: '重新登录',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
store.dispatch('FedLogOut').then(() => {
|
||||||
|
location.reload() // 为了重新实例化vue-router对象 避免bug
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
return Promise.reject(error)
|
||||||
return Promise.reject(error)
|
}
|
||||||
|
error.message = ret.data.detail
|
||||||
}
|
}
|
||||||
// check login error response from server api
|
// check login error response from server api
|
||||||
const login_error = error.response.data.non_field_errors
|
const login_error = error.response.data.non_field_errors
|
||||||
|
|
Loading…
Reference in New Issue