修复用户退出登录时,把 LANG、THEME、LAYOUT、IS_DARK 给清空的问题
(cherry picked from commit 560a336f8c
)
This commit is contained in:
parent
109b558d32
commit
6b320e9d72
@ -13,7 +13,7 @@ import { getAccessToken, getRefreshToken, getTenantId, removeToken, setToken } f
|
||||
import errorCode from './errorCode'
|
||||
|
||||
import { resetRouter } from '@/router'
|
||||
import { useCache } from '@/hooks/web/useCache'
|
||||
import { deleteUserCache } from '@/hooks/web/useCache'
|
||||
|
||||
const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
|
||||
const { result_code, base_url, request_timeout } = config
|
||||
@ -217,9 +217,8 @@ const handleAuthorized = () => {
|
||||
confirmButtonText: t('login.relogin'),
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
const { wsCache } = useCache()
|
||||
resetRouter() // 重置静态路由表
|
||||
wsCache.clear()
|
||||
deleteUserCache() // 删除用户缓存
|
||||
removeToken()
|
||||
isRelogin.show = false
|
||||
// 干掉token后再走一次路由让它过router.beforeEach的校验
|
||||
|
@ -25,3 +25,9 @@ export const useCache = (type: CacheType = 'localStorage') => {
|
||||
wsCache
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteUserCache = () => {
|
||||
const { wsCache } = useCache()
|
||||
wsCache.delete(CACHE_KEY.USER)
|
||||
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import { resetRouter } from '@/router'
|
||||
import { useCache } from '@/hooks/web/useCache'
|
||||
import { deleteUserCache } from '@/hooks/web/useCache'
|
||||
import { useLockStore } from '@/store/modules/lock'
|
||||
import { useNow } from '@/hooks/web/useNow'
|
||||
import { useDesign } from '@/hooks/web/useDesign'
|
||||
@ -10,8 +10,6 @@ import avatarImg from '@/assets/imgs/avatar.gif'
|
||||
|
||||
const tagsViewStore = useTagsViewStore()
|
||||
|
||||
const { wsCache } = useCache()
|
||||
|
||||
const { replace } = useRouter()
|
||||
|
||||
const userStore = useUserStore()
|
||||
@ -52,7 +50,7 @@ async function unLock() {
|
||||
async function goLogin() {
|
||||
await userStore.loginOut().catch(() => {})
|
||||
// 登出后清理
|
||||
wsCache.clear()
|
||||
deleteUserCache() // 清空用户缓存
|
||||
tagsViewStore.delAllViews()
|
||||
resetRouter() // 重置静态路由表
|
||||
lockStore.resetLockInfo()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { store } from '../index'
|
||||
import { store } from '@/store'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getAccessToken, removeToken } from '@/utils/auth'
|
||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||
import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache'
|
||||
import { getInfoApi, loginOutApi } from '@/api/login'
|
||||
|
||||
const { wsCache } = useCache()
|
||||
@ -13,11 +13,20 @@ interface UserVO {
|
||||
deptId: number
|
||||
}
|
||||
|
||||
interface RememberMeInfo {
|
||||
enable: boolean // 是否记住我
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
interface UserInfoVO {
|
||||
// USER 缓存
|
||||
permissions: string[]
|
||||
roles: string[]
|
||||
isSetUser: boolean
|
||||
user: UserVO
|
||||
// REMEMBER_ME 缓存
|
||||
rememberMe: RememberMeInfo
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('admin-user', {
|
||||
@ -30,6 +39,11 @@ export const useUserStore = defineStore('admin-user', {
|
||||
avatar: '',
|
||||
nickname: '',
|
||||
deptId: 0
|
||||
},
|
||||
rememberMe: {
|
||||
enable: true,
|
||||
username: '',
|
||||
password: ''
|
||||
}
|
||||
}),
|
||||
getters: {
|
||||
@ -80,7 +94,7 @@ export const useUserStore = defineStore('admin-user', {
|
||||
async loginOut() {
|
||||
await loginOutApi()
|
||||
removeToken()
|
||||
wsCache.clear()
|
||||
deleteUserCache() // 删除用户缓存
|
||||
this.resetState()
|
||||
},
|
||||
resetState() {
|
||||
|
Loading…
Reference in New Issue
Block a user