Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1bc4eefe
authored
Feb 29, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复记住密码失效的问题
parent
560a336f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
47 deletions
+19
-47
src/hooks/web/useCache.ts
+9
-3
src/store/modules/user.ts
+0
-13
src/utils/auth.ts
+6
-27
src/views/Login/components/LoginForm.vue
+4
-4
No files found.
src/hooks/web/useCache.ts
View file @
1bc4eefe
...
...
@@ -7,13 +7,18 @@ import WebStorageCache from 'web-storage-cache'
type
CacheType
=
'localStorage'
|
'sessionStorage'
export
const
CACHE_KEY
=
{
IS_DARK
:
'isDark'
,
// 用户相关
ROLE_ROUTERS
:
'roleRouters'
,
USER
:
'user'
,
// 系统设置
IS_DARK
:
'isDark'
,
LANG
:
'lang'
,
THEME
:
'theme'
,
LAYOUT
:
'layout'
,
ROLE_ROUTERS
:
'roleRouters'
,
DICT_CACHE
:
'dictCache'
DICT_CACHE
:
'dictCache'
,
// 登录表单
LoginForm
:
'loginForm'
,
TenantId
:
'tenantId'
}
export
const
useCache
=
(
type
:
CacheType
=
'localStorage'
)
=>
{
...
...
@@ -30,4 +35,5 @@ export const deleteUserCache = () => {
const
{
wsCache
}
=
useCache
()
wsCache
.
delete
(
CACHE_KEY
.
USER
)
wsCache
.
delete
(
CACHE_KEY
.
ROLE_ROUTERS
)
// 注意,不要清理 LoginForm 登录表单
}
src/store/modules/user.ts
View file @
1bc4eefe
...
...
@@ -13,20 +13,12 @@ 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'
,
{
...
...
@@ -39,11 +31,6 @@ export const useUserStore = defineStore('admin-user', {
avatar
:
''
,
nickname
:
''
,
deptId
:
0
},
rememberMe
:
{
enable
:
true
,
username
:
''
,
password
:
''
}
}),
getters
:
{
...
...
src/utils/auth.ts
View file @
1bc4eefe
import
{
useCache
}
from
'@/hooks/web/useCache'
import
{
useCache
,
CACHE_KEY
}
from
'@/hooks/web/useCache'
import
{
TokenType
}
from
'@/api/login/types'
import
{
decrypt
,
encrypt
}
from
'@/utils/jsencrypt'
...
...
@@ -36,8 +36,6 @@ export const formatToken = (token: string): string => {
}
// ========== 账号相关 ==========
const
LoginFormKey
=
'LOGINFORM'
export
type
LoginFormType
=
{
tenantName
:
string
username
:
string
...
...
@@ -46,7 +44,7 @@ export type LoginFormType = {
}
export
const
getLoginForm
=
()
=>
{
const
loginForm
:
LoginFormType
=
wsCache
.
get
(
LoginFormKey
)
const
loginForm
:
LoginFormType
=
wsCache
.
get
(
CACHE_KEY
.
LoginForm
)
if
(
loginForm
)
{
loginForm
.
password
=
decrypt
(
loginForm
.
password
)
as
string
}
...
...
@@ -55,38 +53,19 @@ export const getLoginForm = () => {
export
const
setLoginForm
=
(
loginForm
:
LoginFormType
)
=>
{
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
=
()
=>
{
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
=
()
=>
{
return
wsCache
.
get
(
TenantIdKey
)
return
wsCache
.
get
(
CACHE_KEY
.
TenantId
)
}
export
const
setTenantId
=
(
username
:
string
)
=>
{
wsCache
.
set
(
TenantIdKey
,
username
)
}
export
const
removeTenantId
=
()
=>
{
wsCache
.
delete
(
TenantIdKey
)
wsCache
.
set
(
CACHE_KEY
.
TenantId
,
username
)
}
src/views/Login/components/LoginForm.vue
View file @
1bc4eefe
...
...
@@ -188,7 +188,7 @@ const loginData = reactive({
username
:
'admin'
,
password
:
'admin123'
,
captchaVerification
:
''
,
rememberMe
:
false
rememberMe
:
true
// 默认记录我。如果不需要,可手动修改
}
})
...
...
@@ -218,14 +218,14 @@ const getTenantId = async () => {
}
}
// 记住我
const
get
Cooki
e
=
()
=>
{
const
get
LoginFormCach
e
=
()
=>
{
const
loginForm
=
authUtil
.
getLoginForm
()
if
(
loginForm
)
{
loginData
.
loginForm
=
{
...
loginData
.
loginForm
,
username
:
loginForm
.
username
?
loginForm
.
username
:
loginData
.
loginForm
.
username
,
password
:
loginForm
.
password
?
loginForm
.
password
:
loginData
.
loginForm
.
password
,
rememberMe
:
loginForm
.
rememberMe
?
true
:
false
,
rememberMe
:
loginForm
.
rememberMe
,
tenantName
:
loginForm
.
tenantName
?
loginForm
.
tenantName
:
loginData
.
loginForm
.
tenantName
}
}
...
...
@@ -320,7 +320,7 @@ watch(
}
)
onMounted
(()
=>
{
get
Cooki
e
()
get
LoginFormCach
e
()
getTenantByWebsite
()
})
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment