diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3d09ce..46220a4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - 登录页面 关闭租户后下拉框没有正常隐藏 - 字典管理 关闭租户不应显示`同步租户字典`按钮 - 登录日志 漏掉了登录日志日期查询 +- 登出相关逻辑在并发(非await)情况下重复执行的问题 **OTHERS** diff --git a/apps/web-antd/src/api/request.ts b/apps/web-antd/src/api/request.ts index 2bdc1c7d..989ddda1 100644 --- a/apps/web-antd/src/api/request.ts +++ b/apps/web-antd/src/api/request.ts @@ -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;