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
Unverified
Commit
bf87c46d
authored
Nov 02, 2024
by
芋道源码
Committed by
Gitee
Nov 02, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!574 【修复】开发模式下从“同时使用了用户信息和权限判断”的页面退出登录时异常问题
Merge pull request !574 from 半栈幼儿员/hotfix/user
parents
458242a2
9b290ae3
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
9 deletions
+15
-9
src/directives/permission/hasPermi.ts
+2
-1
src/directives/permission/hasRole.ts
+2
-1
src/store/modules/permission.ts
+3
-2
src/utils/auth.ts
+2
-1
src/utils/permission.ts
+6
-4
No files found.
src/directives/permission/hasPermi.ts
View file @
bf87c46d
...
...
@@ -8,7 +8,8 @@ export function hasPermi(app: App<Element>) {
const
{
wsCache
}
=
useCache
()
const
{
value
}
=
binding
const
all_permission
=
'*:*:*'
const
permissions
=
wsCache
.
get
(
CACHE_KEY
.
USER
).
permissions
const
userInfo
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
const
permissions
=
userInfo
?.
permissions
||
[]
if
(
value
&&
value
instanceof
Array
&&
value
.
length
>
0
)
{
const
permissionFlag
=
value
...
...
src/directives/permission/hasRole.ts
View file @
bf87c46d
...
...
@@ -8,7 +8,8 @@ export function hasRole(app: App<Element>) {
const
{
wsCache
}
=
useCache
()
const
{
value
}
=
binding
const
super_admin
=
'super_admin'
const
roles
=
wsCache
.
get
(
CACHE_KEY
.
USER
).
roles
const
userInfo
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
const
roles
=
userInfo
?.
roles
||
[]
if
(
value
&&
value
instanceof
Array
&&
value
.
length
>
0
)
{
const
roleFlag
=
value
...
...
src/store/modules/permission.ts
View file @
bf87c46d
...
...
@@ -35,8 +35,9 @@ export const usePermissionStore = defineStore('permission', {
return
new
Promise
<
void
>
(
async
(
resolve
)
=>
{
// 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取
let
res
:
AppCustomRouteRecordRaw
[]
=
[]
if
(
wsCache
.
get
(
CACHE_KEY
.
ROLE_ROUTERS
))
{
res
=
wsCache
.
get
(
CACHE_KEY
.
ROLE_ROUTERS
)
as
AppCustomRouteRecordRaw
[]
const
roleRouters
=
wsCache
.
get
(
CACHE_KEY
.
ROLE_ROUTERS
)
if
(
roleRouters
)
{
res
=
roleRouters
as
AppCustomRouteRecordRaw
[]
}
const
routerMap
:
AppRouteRecordRaw
[]
=
generateRoute
(
res
)
// 动态路由,404一定要放到最后面
...
...
src/utils/auth.ts
View file @
bf87c46d
...
...
@@ -10,7 +10,8 @@ const RefreshTokenKey = 'REFRESH_TOKEN'
// 获取token
export
const
getAccessToken
=
()
=>
{
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错
return
wsCache
.
get
(
AccessTokenKey
)
?
wsCache
.
get
(
AccessTokenKey
)
:
wsCache
.
get
(
'ACCESS_TOKEN'
)
const
accessToken
=
wsCache
.
get
(
AccessTokenKey
)
return
accessToken
?
accessToken
:
wsCache
.
get
(
'ACCESS_TOKEN'
)
}
// 刷新token
...
...
src/utils/permission.ts
View file @
bf87c46d
...
...
@@ -12,8 +12,9 @@ export function checkPermi(value: string[]) {
const
{
wsCache
}
=
useCache
()
const
permissionDatas
=
value
const
all_permission
=
'*:*:*'
const
permissions
=
wsCache
.
get
(
CACHE_KEY
.
USER
).
permissions
const
hasPermission
=
permissions
.
some
((
permission
)
=>
{
const
userInfo
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
const
permissions
=
userInfo
?.
permissions
||
[]
const
hasPermission
=
permissions
.
some
((
permission
:
string
)
=>
{
return
all_permission
===
permission
||
permissionDatas
.
includes
(
permission
)
})
return
!!
hasPermission
...
...
@@ -33,8 +34,9 @@ export function checkRole(value: string[]) {
const
{
wsCache
}
=
useCache
()
const
permissionRoles
=
value
const
super_admin
=
'super_admin'
const
roles
=
wsCache
.
get
(
CACHE_KEY
.
USER
).
roles
const
hasRole
=
roles
.
some
((
role
)
=>
{
const
userInfo
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
const
roles
=
userInfo
?.
roles
||
[]
const
hasRole
=
roles
.
some
((
role
:
string
)
=>
{
return
super_admin
===
role
||
permissionRoles
.
includes
(
role
)
})
return
!!
hasRole
...
...
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