From 79d89005b6f16ece3ca6b21f304b3d09b64bd235 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Sun, 18 May 2025 14:28:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E9=94=99=E8=AF=AF=E7=94=A8=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA(=E5=AE=8C=E5=85=A8=E6=97=A0?= =?UTF-8?q?=E5=A5=88...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/core/auth.ts | 33 ++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts index 989135ba..e3a99ef2 100644 --- a/apps/web-antd/src/api/core/auth.ts +++ b/apps/web-antd/src/api/core/auth.ts @@ -1,7 +1,12 @@ import type { GrantType } from '@vben/common-ui'; +import type { HttpResponse } from '@vben/request'; + +import { h } from 'vue'; import { useAppConfig } from '@vben/hooks'; +import { Modal } from 'ant-design-vue'; + import { requestClient } from '#/api/request'; const { clientId, sseEnable } = useAppConfig( @@ -90,8 +95,32 @@ export async function loginApi(data: AuthApi.LoginParams) { * 用户登出 * @returns void */ -export function doLogout() { - return requestClient.post('/auth/logout'); +export async function doLogout() { + const resp = await requestClient.post>( + '/auth/logout', + null, + { + isTransformResponse: false, + }, + ); + // 无奈之举 对错误用法的提示 + if (resp.code === 401 && import.meta.env.DEV) { + Modal.destroyAll(); + Modal.warn({ + title: '后端配置出现错误', + centered: true, + content: h('div', { class: 'flex flex-col gap-2' }, [ + `检测到你的logout接口返回了401, 导致前端一直进入循环逻辑???`, + ...Array.from({ length: 3 }, () => + h( + 'span', + { class: 'font-bold text-red-500 text-[18px]' }, + '去检查你的后端配置!别盯着前端找问题了!这不是前端问题!', + ), + ), + ]), + }); + } } /**