mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2025-05-14 04:36:14 +08:00
凭证过期重新登录后执行上一次请求
This commit is contained in:
parent
1c4bfc10fd
commit
361dd1116c
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { Message, MessageBox } from 'element-ui'
|
import { Message, MessageBox } from 'element-ui'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
@ -45,51 +44,55 @@ service.interceptors.response.use(
|
|||||||
* You can also judge the status by HTTP Status Code
|
* You can also judge the status by HTTP Status Code
|
||||||
*/
|
*/
|
||||||
response => {
|
response => {
|
||||||
const res = response.data
|
return new Promise((reslove, reject) => {
|
||||||
// if the custom code is not 1, it is judged as an error.
|
const res = response.data
|
||||||
if (res.code !== 200) {
|
if (res.code !== 200) {
|
||||||
var duration = 5
|
var duration = 5
|
||||||
if (res.code === 402) {
|
if (res.code === 402) {
|
||||||
duration = 1
|
duration = 1
|
||||||
MessageBox.prompt('凭证已过期,请输入密码重新登录', '提示', {
|
MessageBox.prompt(`当前账号:${store.getters.username}凭证已过期,请输入密码重新登录`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '退出',
|
cancelButtonText: '退出',
|
||||||
inputType: 'password'
|
inputType: 'password',
|
||||||
}).then(({ value }) => {
|
closeOnClickModal: false,
|
||||||
store.dispatch('user/login', {
|
beforeClose: (action, instance, done) => {
|
||||||
username: store.getters.username,
|
if (action === 'confirm') {
|
||||||
password: value
|
store.dispatch('user/login', {
|
||||||
}).then((res) => {
|
username: store.getters.username,
|
||||||
console.log(res)
|
password: instance.inputValue
|
||||||
})
|
}).then((res) => {
|
||||||
}).catch(() => {
|
if (res) {
|
||||||
store.dispatch('user/logout').then(() => {
|
done()
|
||||||
location.reload()
|
service(response.config).then(ret => reslove(ret))
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
return
|
} else if (action === 'cancel') {
|
||||||
}
|
store.dispatch('user/logout').then(() => {
|
||||||
if (isShowMsg === false) {
|
location.reload()
|
||||||
Message({
|
})
|
||||||
message: res.message || 'Error',
|
} else {
|
||||||
type: 'error',
|
done()
|
||||||
duration: duration * 1000,
|
}
|
||||||
showClose: true,
|
|
||||||
onClose: function() {
|
|
||||||
isShowMsg = false
|
|
||||||
if (res.code === 402) {
|
|
||||||
store.dispatch('user/logout').then(() => {
|
|
||||||
location.reload()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
isShowMsg = true
|
if (isShowMsg === false && res.code !== 402) {
|
||||||
|
Message({
|
||||||
|
message: res.message || 'Error',
|
||||||
|
type: 'error',
|
||||||
|
duration: duration * 1000,
|
||||||
|
showClose: true,
|
||||||
|
onClose: function() {
|
||||||
|
isShowMsg = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
isShowMsg = true
|
||||||
|
// reslove(res)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reslove(res)
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error(res.message || 'Error'))
|
})
|
||||||
} else {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
// console.log('err' + error) // for debug
|
// console.log('err' + error) // for debug
|
||||||
|
Loading…
x
Reference in New Issue
Block a user