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
58a3af8c
authored
Mar 11, 2023
by
LinkLi
Committed by
芋道源码
Mar 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
!22 issue#I6KY0M 修复建议
* feat: 增加全局权限判断函数#I6KY0M
parent
7d43157f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
src/utils/permission.ts
+45
-0
No files found.
src/utils/permission.ts
0 → 100644
View file @
58a3af8c
import
{
CACHE_KEY
,
useCache
}
from
'@/hooks/web/useCache'
const
{
t
}
=
useI18n
()
// 国际化
/**
* 字符权限校验
* @param {Array} value 校验值
* @returns {Boolean}
*/
export
function
checkPermi
(
value
:
string
[])
{
if
(
value
&&
value
instanceof
Array
&&
value
.
length
>
0
)
{
const
{
wsCache
}
=
useCache
()
const
permissionDatas
=
value
const
all_permission
=
'*:*:*'
const
permissions
=
wsCache
.
get
(
CACHE_KEY
.
USER
).
permissions
const
hasPermission
=
permissions
.
some
((
permission
)
=>
{
return
all_permission
===
permission
||
permissionDatas
.
includes
(
permission
)
})
return
!!
hasPermission
}
else
{
console
.
error
(
t
(
'permission.hasPermission'
))
return
false
}
}
/**
* 角色权限校验
* @param {string[]} value 校验值
* @returns {Boolean}
*/
export
function
checkRole
(
value
:
string
[])
{
if
(
value
&&
value
instanceof
Array
&&
value
.
length
>
0
)
{
const
{
wsCache
}
=
useCache
()
const
permissionRoles
=
value
const
super_admin
=
'admin'
const
roles
=
wsCache
.
get
(
CACHE_KEY
.
USER
).
roles
const
hasRole
=
roles
.
some
((
role
)
=>
{
return
super_admin
===
role
||
permissionRoles
.
includes
(
role
)
})
return
!!
hasRole
}
else
{
console
.
error
(
t
(
'permission.hasRole'
))
return
false
}
}
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