From 3496dd8cd9db23b1a6c2550158cd2937cc9bf352 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Sat, 12 Apr 2025 17:35:28 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/RightContent/AvatarDropdown.tsx | 8 ++++---- react-ui/src/utils/promise.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/react-ui/src/components/RightContent/AvatarDropdown.tsx b/react-ui/src/components/RightContent/AvatarDropdown.tsx index c1450429..ce90efb5 100644 --- a/react-ui/src/components/RightContent/AvatarDropdown.tsx +++ b/react-ui/src/components/RightContent/AvatarDropdown.tsx @@ -2,6 +2,7 @@ import { clearSessionToken } from '@/access'; import { setRemoteMenu } from '@/services/session'; import { logout } from '@/services/system/auth'; import { ClientInfo } from '@/types'; +import { sleep } from '@/utils/promise'; import SessionStorage from '@/utils/sessionStorage'; import { gotoLoginPage, oauthLogout } from '@/utils/ui'; import { LogoutOutlined, UserOutlined } from '@ant-design/icons'; @@ -63,16 +64,15 @@ const AvatarDropdown: React.FC = ({ menu }) => { */ const loginOut = async () => { oauthLogout('http://172.20.32.197:31209/oauth/logout'); - await logout(); + // 至少 1 秒后跳转,希望子系统能完成注销 + await Promise.all([logout(), sleep(1000)]); clearSessionToken(); setRemoteMenu(null); gotoLoginPage(); const clientInfo: ClientInfo = SessionStorage.getItem(SessionStorage.clientInfoKey, true); if (clientInfo) { const { logoutUri } = clientInfo; - setTimeout(async () => { - location.replace(logoutUri); - }, 1000); + location.replace(logoutUri); } }; const actionClassName = useEmotionCss(({ token }) => { diff --git a/react-ui/src/utils/promise.ts b/react-ui/src/utils/promise.ts index 7340e3bf..06724a51 100644 --- a/react-ui/src/utils/promise.ts +++ b/react-ui/src/utils/promise.ts @@ -13,3 +13,16 @@ export async function to(promise: Promise): Promise<[T, null] | [ } export default to; + +/** + * 休眠 + * @param ms - The number of milliseconds to sleep. + * @return A promise that resolves after the specified amount of time. + */ +export function sleep(ms: number) { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, ms); + }); +}