修复记住密码失效的问题
This commit is contained in:
parent
560a336f8c
commit
1bc4eefeab
@ -7,13 +7,18 @@ import WebStorageCache from 'web-storage-cache'
|
|||||||
type CacheType = 'localStorage' | 'sessionStorage'
|
type CacheType = 'localStorage' | 'sessionStorage'
|
||||||
|
|
||||||
export const CACHE_KEY = {
|
export const CACHE_KEY = {
|
||||||
IS_DARK: 'isDark',
|
// 用户相关
|
||||||
|
ROLE_ROUTERS: 'roleRouters',
|
||||||
USER: 'user',
|
USER: 'user',
|
||||||
|
// 系统设置
|
||||||
|
IS_DARK: 'isDark',
|
||||||
LANG: 'lang',
|
LANG: 'lang',
|
||||||
THEME: 'theme',
|
THEME: 'theme',
|
||||||
LAYOUT: 'layout',
|
LAYOUT: 'layout',
|
||||||
ROLE_ROUTERS: 'roleRouters',
|
DICT_CACHE: 'dictCache',
|
||||||
DICT_CACHE: 'dictCache'
|
// 登录表单
|
||||||
|
LoginForm: 'loginForm',
|
||||||
|
TenantId: 'tenantId'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useCache = (type: CacheType = 'localStorage') => {
|
export const useCache = (type: CacheType = 'localStorage') => {
|
||||||
@ -30,4 +35,5 @@ export const deleteUserCache = () => {
|
|||||||
const { wsCache } = useCache()
|
const { wsCache } = useCache()
|
||||||
wsCache.delete(CACHE_KEY.USER)
|
wsCache.delete(CACHE_KEY.USER)
|
||||||
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
|
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
|
||||||
|
// 注意,不要清理 LoginForm 登录表单
|
||||||
}
|
}
|
||||||
|
@ -13,20 +13,12 @@ interface UserVO {
|
|||||||
deptId: number
|
deptId: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RememberMeInfo {
|
|
||||||
enable: boolean // 是否记住我
|
|
||||||
username: string
|
|
||||||
password: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UserInfoVO {
|
interface UserInfoVO {
|
||||||
// USER 缓存
|
// 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', {
|
||||||
@ -39,11 +31,6 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
avatar: '',
|
avatar: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
deptId: 0
|
deptId: 0
|
||||||
},
|
|
||||||
rememberMe: {
|
|
||||||
enable: true,
|
|
||||||
username: '',
|
|
||||||
password: ''
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useCache, CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
import { TokenType } from '@/api/login/types'
|
import { TokenType } from '@/api/login/types'
|
||||||
import { decrypt, encrypt } from '@/utils/jsencrypt'
|
import { decrypt, encrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
@ -36,8 +36,6 @@ export const formatToken = (token: string): string => {
|
|||||||
}
|
}
|
||||||
// ========== 账号相关 ==========
|
// ========== 账号相关 ==========
|
||||||
|
|
||||||
const LoginFormKey = 'LOGINFORM'
|
|
||||||
|
|
||||||
export type LoginFormType = {
|
export type LoginFormType = {
|
||||||
tenantName: string
|
tenantName: string
|
||||||
username: string
|
username: string
|
||||||
@ -46,7 +44,7 @@ export type LoginFormType = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getLoginForm = () => {
|
export const getLoginForm = () => {
|
||||||
const loginForm: LoginFormType = wsCache.get(LoginFormKey)
|
const loginForm: LoginFormType = wsCache.get(CACHE_KEY.LoginForm)
|
||||||
if (loginForm) {
|
if (loginForm) {
|
||||||
loginForm.password = decrypt(loginForm.password) as string
|
loginForm.password = decrypt(loginForm.password) as string
|
||||||
}
|
}
|
||||||
@ -55,38 +53,19 @@ export const getLoginForm = () => {
|
|||||||
|
|
||||||
export const setLoginForm = (loginForm: LoginFormType) => {
|
export const setLoginForm = (loginForm: LoginFormType) => {
|
||||||
loginForm.password = encrypt(loginForm.password) as string
|
loginForm.password = encrypt(loginForm.password) as string
|
||||||
wsCache.set(LoginFormKey, loginForm, { exp: 30 * 24 * 60 * 60 })
|
wsCache.set(CACHE_KEY.LoginForm, loginForm, { exp: 30 * 24 * 60 * 60 })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeLoginForm = () => {
|
export const removeLoginForm = () => {
|
||||||
wsCache.delete(LoginFormKey)
|
wsCache.delete(CACHE_KEY.LoginForm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 租户相关 ==========
|
// ========== 租户相关 ==========
|
||||||
|
|
||||||
const TenantIdKey = 'TENANT_ID'
|
|
||||||
const TenantNameKey = 'TENANT_NAME'
|
|
||||||
|
|
||||||
export const getTenantName = () => {
|
|
||||||
return wsCache.get(TenantNameKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const setTenantName = (username: string) => {
|
|
||||||
wsCache.set(TenantNameKey, username, { exp: 30 * 24 * 60 * 60 })
|
|
||||||
}
|
|
||||||
|
|
||||||
export const removeTenantName = () => {
|
|
||||||
wsCache.delete(TenantNameKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getTenantId = () => {
|
export const getTenantId = () => {
|
||||||
return wsCache.get(TenantIdKey)
|
return wsCache.get(CACHE_KEY.TenantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setTenantId = (username: string) => {
|
export const setTenantId = (username: string) => {
|
||||||
wsCache.set(TenantIdKey, username)
|
wsCache.set(CACHE_KEY.TenantId, username)
|
||||||
}
|
|
||||||
|
|
||||||
export const removeTenantId = () => {
|
|
||||||
wsCache.delete(TenantIdKey)
|
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ const loginData = reactive({
|
|||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'admin123',
|
password: 'admin123',
|
||||||
captchaVerification: '',
|
captchaVerification: '',
|
||||||
rememberMe: false
|
rememberMe: true // 默认记录我。如果不需要,可手动修改
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -218,14 +218,14 @@ const getTenantId = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 记住我
|
// 记住我
|
||||||
const getCookie = () => {
|
const getLoginFormCache = () => {
|
||||||
const loginForm = authUtil.getLoginForm()
|
const loginForm = authUtil.getLoginForm()
|
||||||
if (loginForm) {
|
if (loginForm) {
|
||||||
loginData.loginForm = {
|
loginData.loginForm = {
|
||||||
...loginData.loginForm,
|
...loginData.loginForm,
|
||||||
username: loginForm.username ? loginForm.username : loginData.loginForm.username,
|
username: loginForm.username ? loginForm.username : loginData.loginForm.username,
|
||||||
password: loginForm.password ? loginForm.password : loginData.loginForm.password,
|
password: loginForm.password ? loginForm.password : loginData.loginForm.password,
|
||||||
rememberMe: loginForm.rememberMe ? true : false,
|
rememberMe: loginForm.rememberMe,
|
||||||
tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
|
tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,7 +320,7 @@ watch(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getCookie()
|
getLoginFormCache()
|
||||||
getTenantByWebsite()
|
getTenantByWebsite()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user