修复用户退出登录时,把 LANG、THEME、LAYOUT、IS_DARK 给清空的问题

pull/305/MERGE
YunaiV 2024-02-29 22:23:10 +08:00
parent f413556c73
commit 560a336f8c
4 changed files with 27 additions and 10 deletions

View File

@ -13,7 +13,7 @@ import { getAccessToken, getRefreshToken, getTenantId, removeToken, setToken } f
import errorCode from './errorCode' import errorCode from './errorCode'
import { resetRouter } from '@/router' 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 tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
const { result_code, base_url, request_timeout } = config const { result_code, base_url, request_timeout } = config
@ -217,9 +217,8 @@ const handleAuthorized = () => {
confirmButtonText: t('login.relogin'), confirmButtonText: t('login.relogin'),
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
const { wsCache } = useCache()
resetRouter() // 重置静态路由表 resetRouter() // 重置静态路由表
wsCache.clear() deleteUserCache() // 删除用户缓存
removeToken() removeToken()
isRelogin.show = false isRelogin.show = false
// 干掉token后再走一次路由让它过router.beforeEach的校验 // 干掉token后再走一次路由让它过router.beforeEach的校验

View File

@ -25,3 +25,9 @@ export const useCache = (type: CacheType = 'localStorage') => {
wsCache wsCache
} }
} }
export const deleteUserCache = () => {
const { wsCache } = useCache()
wsCache.delete(CACHE_KEY.USER)
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
}

View File

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { resetRouter } from '@/router' import { resetRouter } from '@/router'
import { useCache } from '@/hooks/web/useCache' import { deleteUserCache } from '@/hooks/web/useCache'
import { useLockStore } from '@/store/modules/lock' import { useLockStore } from '@/store/modules/lock'
import { useNow } from '@/hooks/web/useNow' import { useNow } from '@/hooks/web/useNow'
import { useDesign } from '@/hooks/web/useDesign' import { useDesign } from '@/hooks/web/useDesign'
@ -10,8 +10,6 @@ import avatarImg from '@/assets/imgs/avatar.gif'
const tagsViewStore = useTagsViewStore() const tagsViewStore = useTagsViewStore()
const { wsCache } = useCache()
const { replace } = useRouter() const { replace } = useRouter()
const userStore = useUserStore() const userStore = useUserStore()
@ -52,7 +50,7 @@ async function unLock() {
async function goLogin() { async function goLogin() {
await userStore.loginOut().catch(() => {}) await userStore.loginOut().catch(() => {})
// //
wsCache.clear() deleteUserCache() //
tagsViewStore.delAllViews() tagsViewStore.delAllViews()
resetRouter() // resetRouter() //
lockStore.resetLockInfo() lockStore.resetLockInfo()

View File

@ -1,7 +1,7 @@
import { store } from '../index' import { store } from '@/store'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { getAccessToken, removeToken } from '@/utils/auth' import { getAccessToken, removeToken } from '@/utils/auth'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache'
import { getInfo, loginOut } from '@/api/login' import { getInfo, loginOut } from '@/api/login'
const { wsCache } = useCache() const { wsCache } = useCache()
@ -13,11 +13,20 @@ interface UserVO {
deptId: number deptId: number
} }
interface RememberMeInfo {
enable: boolean // 是否记住我
username: string
password: string
}
interface UserInfoVO { interface UserInfoVO {
// USER 缓存
permissions: string[] permissions: string[]
roles: string[] roles: string[]
isSetUser: boolean isSetUser: boolean
user: UserVO user: UserVO
// REMEMBER_ME 缓存
rememberMe: RememberMeInfo
} }
export const useUserStore = defineStore('admin-user', { export const useUserStore = defineStore('admin-user', {
@ -30,6 +39,11 @@ export const useUserStore = defineStore('admin-user', {
avatar: '', avatar: '',
nickname: '', nickname: '',
deptId: 0 deptId: 0
},
rememberMe: {
enable: true,
username: '',
password: ''
} }
}), }),
getters: { getters: {
@ -80,7 +94,7 @@ export const useUserStore = defineStore('admin-user', {
async loginOut() { async loginOut() {
await loginOut() await loginOut()
removeToken() removeToken()
wsCache.clear() deleteUserCache() // 删除用户缓存
this.resetState() this.resetState()
}, },
resetState() { resetState() {