FIX API同时返回401时多次执行confirm弹窗

This commit is contained in:
sc 2022-08-26 14:58:10 +08:00
parent f367b3ad1a
commit 530390f9d4
1 changed files with 18 additions and 8 deletions

View File

@ -27,6 +27,9 @@ axios.interceptors.request.use(
}
);
//FIX 多个API同时401时疯狂弹窗BUG
let MessageBox_401_show = false
// HTTP response 拦截器
axios.interceptors.response.use(
(response) => {
@ -45,14 +48,21 @@ axios.interceptors.response.use(
message: error.response.data.message || "Status:500服务器发生错误"
});
} else if (error.response.status == 401) {
ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
type: 'error',
closeOnClickModal: false,
center: true,
confirmButtonText: '重新登录'
}).then(() => {
router.replace({path: '/login'});
}).catch(() => {})
if(!MessageBox_401_show){
MessageBox_401_show = true
ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
type: 'error',
closeOnClickModal: false,
center: true,
confirmButtonText: '重新登录',
beforeClose: (action, instance, done) => {
MessageBox_401_show = false
done()
}
}).then(() => {
router.replace({path: '/login'});
}).catch(() => {})
}
} else {
ElNotification.error({
title: '请求错误',