fix: 登出相关逻辑在并发(非await)情况下重复执行的问题

This commit is contained in:
dap 2024-10-12 11:29:06 +08:00
parent c5fcf50c76
commit 0a27114ea3
2 changed files with 14 additions and 12 deletions

View File

@ -10,6 +10,7 @@
- 登录页面 关闭租户后下拉框没有正常隐藏
- 字典管理 关闭租户不应显示`同步租户字典`按钮
- 登录日志 漏掉了登录日志日期查询
- 登出相关逻辑在并发(非await)情况下重复执行的问题
**OTHERS**

View File

@ -34,8 +34,11 @@ const { apiURL, clientId, enableEncrypt } = useAppConfig(
import.meta.env.PROD,
);
/** 控制是否弹窗 防止登录超时请求多个api会弹窗多次 */
let showTimeoutToast = true;
/**
*
* api 401
*/
let isLogoutProcessing = false;
function createRequestClient(baseURL: string) {
const client = new RequestClient({
@ -234,18 +237,16 @@ function createRequestClient(baseURL: string) {
let timeoutMsg = '';
switch (code) {
case 401: {
// 已经在登出过程中 不再执行
if (isLogoutProcessing) {
return;
}
isLogoutProcessing = true;
const _msg = '登录超时, 请重新登录';
const userStore = useAuthStore();
userStore.logout().then(() => {
/** 只弹窗一次 */
if (showTimeoutToast) {
showTimeoutToast = false;
message.error(_msg);
/** 定时器 3s后再开启弹窗 */
setTimeout(() => {
showTimeoutToast = true;
}, 3000);
}
userStore.logout().finally(() => {
message.error(_msg);
isLogoutProcessing = false;
});
// 不再执行下面逻辑
return;