Commit 6b244022 by 高源

加入退出登录接口

parent 33d487e1
<!doctype html>
<html lang="zh-cmn-Hans">
<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" />
<link rel="icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
<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">
</head>
<body>
......
......@@ -46,3 +46,11 @@ export function fetchRefreshToken(refreshToken: string) {
export function fetchCustomBackendError(code: string, msg: string) {
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';
import { useLoading } from '@sa/hooks';
import { SetupStoreId } from '@/enum';
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 { $t } from '@/locales';
import { useRouteStore } from '../route';
......@@ -43,8 +43,25 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
async function resetStore() {
const authStore = useAuthStore();
try {
// 调用退出接口
const { error } = await fetchLogout();
if (!error) {
// 清除存储
clearAuthStorage();
// 重置store
authStore.$reset();
if (!route.meta.constant) {
await toLogin();
}
tabStore.cacheTabs();
routeStore.resetStore();
}
} catch (err) {
// 即使退出接口失败,也要清除本地状态
clearAuthStorage();
authStore.$reset();
if (!route.meta.constant) {
......@@ -54,6 +71,7 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
tabStore.cacheTabs();
routeStore.resetStore();
}
}
/**
* Login
......
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