This commit is contained in:
zlwu committed 2026-06-24 10:39:55 +08:00
1 parent 93c28759d0
commit b23a2eb350
129 files changed
+28511 -17769

No files matched your search

+25 -23
View File
@@ -121,12 +121,11 @@ export const useUserStore = defineStore(
}
/**
* 退出登录
* 通知后端撤销 Redis 会话,然后清空所有用户相关状态并跳转到登录页
* 清空本地登录态(可选通知后端登出),不跳转页面
*/
const logOut = async () => {
// 先通知后端撤销 Redis 会话(须在清空 token 之前完成,否则请求无 Authorization)
if (accessToken.value) {
const clearSession = async (options?: { notifyServer?: boolean }) => {
const notifyServer = options?.notifyServer !== false
if (notifyServer && accessToken.value) {
try {
await fetchLogout()
} catch {
@@ -134,30 +133,32 @@ export const useUserStore = defineStore(
}
}
info.value = {} as Api.Auth.UserInfo
isSuperAdmin.value = false
menuPermAll.value = false
menuCodes.value = []
isLogin.value = false
accessToken.value = ''
refreshToken.value = ''
searchHistory.value = []
isLock.value = false
lockPassword.value = ''
sessionStorage.removeItem('iframeRoutes')
useMenuStore().setHomePath('')
}
/**
* 退出登录
* 通知后端撤销 Redis 会话,然后清空所有用户相关状态并跳转到登录页
*/
const logOut = async () => {
// 保存当前用户 ID,用于下次登录时判断是否为同一用户
const currentUserId = info.value.userId
if (currentUserId) {
localStorage.setItem(StorageConfig.LAST_USER_ID_KEY, String(currentUserId))
}
// 清空用户信息
info.value = {} as Api.Auth.UserInfo
isSuperAdmin.value = false
menuPermAll.value = false
menuCodes.value = []
// 重置登录状态
isLogin.value = false
// 清空访问令牌
accessToken.value = ''
// 清空刷新令牌
refreshToken.value = ''
searchHistory.value = []
isLock.value = false
lockPassword.value = ''
// 移除iframe路由缓存
sessionStorage.removeItem('iframeRoutes')
// 清空主页路径
useMenuStore().setHomePath('')
await clearSession()
// 重置路由状态
resetRouterState(500)
// 跳转到登录页,携带当前路由作为 redirect 参数
@@ -221,6 +222,7 @@ export const useUserStore = defineStore(
setSearchHistory,
setLockStatus,
setLockPassword,
clearSession,
logOut,
checkAndClearWorktabs
}