Commit 6b244022 by 高源

加入退出登录接口

parent 33d487e1
<!doctype html> <!doctype html>
<html lang="zh-cmn-Hans"> <html lang="zh-cmn-Hans">
<head> <head>
<meta name="buildTime" content="2025-02-20 09:28:58"> <meta name="buildTime" content="2025-02-20 16:06:48">
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" href="/favicon.svg" /> <link rel="icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" /> <meta name="color-scheme" content="light dark" />
<title>VueDashboard</title> <title>VueDashboard</title>
<script type="module" crossorigin src="/Content/VueDashboardUi/VueDashboard1/assets/index-u5iQYcYA.js"></script> <script type="module" crossorigin src="/Content/VueDashboardUi/VueDashboard1/assets/index-BTK4dlWY.js"></script>
<link rel="stylesheet" crossorigin href="/Content/VueDashboardUi/VueDashboard1/assets/index-9k_B1ZU8.css"> <link rel="stylesheet" crossorigin href="/Content/VueDashboardUi/VueDashboard1/assets/index-9k_B1ZU8.css">
</head> </head>
<body> <body>
......
...@@ -46,3 +46,11 @@ export function fetchRefreshToken(refreshToken: string) { ...@@ -46,3 +46,11 @@ export function fetchRefreshToken(refreshToken: string) {
export function fetchCustomBackendError(code: string, msg: string) { export function fetchCustomBackendError(code: string, msg: string) {
return request({ url: '/auth/error', params: { code, msg } }); return request({ url: '/auth/error', params: { code, msg } });
} }
/** 退出登录 */
export function fetchLogout() {
return request({
url: '/auth/logout.json',
method: 'post'
});
}
...@@ -4,7 +4,7 @@ import { defineStore } from 'pinia'; ...@@ -4,7 +4,7 @@ import { defineStore } from 'pinia';
import { useLoading } from '@sa/hooks'; import { useLoading } from '@sa/hooks';
import { SetupStoreId } from '@/enum'; import { SetupStoreId } from '@/enum';
import { useRouterPush } from '@/hooks/common/router'; import { useRouterPush } from '@/hooks/common/router';
import { fetchGetUserInfo, fetchLogin } from '@/service/api'; import { fetchGetUserInfo, fetchLogin, fetchLogout } from '@/service/api';
import { localStg } from '@/utils/storage'; import { localStg } from '@/utils/storage';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { useRouteStore } from '../route'; import { useRouteStore } from '../route';
...@@ -43,16 +43,34 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { ...@@ -43,16 +43,34 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
async function resetStore() { async function resetStore() {
const authStore = useAuthStore(); const authStore = useAuthStore();
clearAuthStorage(); try {
// 调用退出接口
const { error } = await fetchLogout();
if (!error) {
// 清除存储
clearAuthStorage();
// 重置store
authStore.$reset();
if (!route.meta.constant) {
await toLogin();
}
authStore.$reset(); tabStore.cacheTabs();
routeStore.resetStore();
}
} catch (err) {
// 即使退出接口失败,也要清除本地状态
clearAuthStorage();
authStore.$reset();
if (!route.meta.constant) { if (!route.meta.constant) {
await toLogin(); await toLogin();
} }
tabStore.cacheTabs(); tabStore.cacheTabs();
routeStore.resetStore(); routeStore.resetStore();
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment