From 117a7f408f1291eb3b4d1fdb6c236d4eddf919c8 Mon Sep 17 00:00:00 2001 From: ZhuRui Date: Fri, 7 Aug 2026 11:26:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=B9=E6=8E=A5=E7=99=BB=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/login/index.ts | 7 +++++++ src/hooks/useAuth.ts | 10 ++++++++-- src/layouts/BasicLayout.tsx | 2 -- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/api/login/index.ts b/src/api/login/index.ts index a5f9cb5..aff4797 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -10,3 +10,10 @@ export const login = (params: { phone: string; password: string }) => { data: LoginResult; }>; }; + +export const logout = () => { + return post(`/op/logout`) as Promise<{ + code: number | string; + msg: string; + }>; +}; diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index 8a81d87..093b576 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -7,6 +7,7 @@ import { usePermissionStore } from '@/stores/permissionStore'; import { useTabsStore } from '@/stores/tabsStore'; import { useUserStore } from '@/stores/userStore'; import { clearAuthDataCache } from '@/api/authCache'; +import { logout as logoutApi } from '@/api/login'; import router from '@/router'; const TOKEN_KEY = 'MY_APP_AUTH_TOKEN'; @@ -66,9 +67,14 @@ function createAuth() { }; /** - * 退出:清除 token → 清除菜单+权限 → 清除动态路由 → 跳转登录页 + * 退出:调用登出接口 → 清除 token → 清除菜单+权限 → 清除动态路由 → 跳转登录页 */ - const logout = () => { + const logout = async () => { + try { + await logoutApi(); + } catch { + // 即使接口失败也要继续清除本地会话 + } clearSession(); router.push('/login'); }; diff --git a/src/layouts/BasicLayout.tsx b/src/layouts/BasicLayout.tsx index bcbd633..ba05f1e 100644 --- a/src/layouts/BasicLayout.tsx +++ b/src/layouts/BasicLayout.tsx @@ -113,8 +113,6 @@ export default defineComponent({ okText: '确认', cancelText: '取消', onOk: () => { - const { clearUser } = useUserStore(); - clearUser(); auth.logout(); }, });