Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Y
yishuju-ui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何远江
yishuju-ui
Commits
4ae0bb86
Commit
4ae0bb86
authored
Jan 05, 2025
by
何远江
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加按钮权限指令
parent
f01c34f6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
3 deletions
+29
-3
permission.js
src/directives/permission.js
+19
-0
directives.js
src/plugins/directives.js
+3
-0
auth.js
src/stores/modules/auth.js
+1
-1
index.vue
src/views/system/accountManage/index.vue
+6
-2
No files found.
src/directives/permission.js
0 → 100644
View file @
4ae0bb86
import
{
unref
}
from
'vue'
;
import
{
useAuthStore
}
from
'@/stores/modules/auth'
;
export
default
{
mounted
(
el
,
binding
)
{
const
{
value
}
=
binding
;
// 获取指令的值,例如 v-permission="'create'"
const
{
authButtonListGet
}
=
useAuthStore
();
// 获取用户权限列表
// 如果 value 是数组,则检查是否包含所有权限
if
(
Array
.
isArray
(
value
))
{
const
hasPermission
=
value
.
every
((
perm
)
=>
authButtonListGet
.
includes
(
perm
));
if
(
!
hasPermission
)
{
el
.
parentNode
&&
el
.
parentNode
.
removeChild
(
el
);
}
}
else
if
(
!
authButtonListGet
.
includes
(
value
))
{
el
.
parentNode
&&
el
.
parentNode
.
removeChild
(
el
);
// 从 DOM 中移除元素
}
},
};
src/plugins/directives.js
View file @
4ae0bb86
import
copy
from
'@/directives/copy'
;
import
copy
from
'@/directives/copy'
;
import
debounce
from
'@/directives/debounce'
;
import
debounce
from
'@/directives/debounce'
;
import
throttle
from
'@/directives/throttle'
;
import
throttle
from
'@/directives/throttle'
;
import
permission
from
'@/directives/permission'
;
export
function
setupDirectives
(
app
)
{
export
function
setupDirectives
(
app
)
{
// 复制指令
// 复制指令
...
@@ -9,4 +10,6 @@ export function setupDirectives(app) {
...
@@ -9,4 +10,6 @@ export function setupDirectives(app) {
app
.
directive
(
'debounce'
,
debounce
);
app
.
directive
(
'debounce'
,
debounce
);
// 节流指令
// 节流指令
app
.
directive
(
'throttle'
,
throttle
);
app
.
directive
(
'throttle'
,
throttle
);
// 权限指令
app
.
directive
(
'permission'
,
permission
);
}
}
src/stores/modules/auth.js
View file @
4ae0bb86
...
@@ -7,7 +7,7 @@ export const useAuthStore = defineStore({
...
@@ -7,7 +7,7 @@ export const useAuthStore = defineStore({
id
:
'admin-auth'
,
id
:
'admin-auth'
,
state
:
()
=>
({
state
:
()
=>
({
// 按钮权限列表
// 按钮权限列表
authButtonList
:
{}
,
authButtonList
:
[]
,
// 菜单权限列表
// 菜单权限列表
authMenuList
:
[],
authMenuList
:
[],
// 当前页面的 router name,用来做按钮权限筛选
// 当前页面的 router name,用来做按钮权限筛选
...
...
src/views/system/accountManage/index.vue
View file @
4ae0bb86
...
@@ -2,10 +2,14 @@
...
@@ -2,10 +2,14 @@
<div
class=
"table-box"
>
<div
class=
"table-box"
>
<ProTable
ref=
"proTable"
:config=
"config"
:api=
"getUserPage"
>
<ProTable
ref=
"proTable"
:config=
"config"
:api=
"getUserPage"
>
<template
#
left_buttons
>
<template
#
left_buttons
>
<el-button
type=
"primary"
:icon=
"Plus"
@
click=
"accountFormModalRef?.openModal()"
<el-button
v-permission=
"'AccountAdd'"
type=
"primary"
:icon=
"Plus"
@
click=
"accountFormModalRef?.openModal()"
>
新增
</el-button
>
新增
</el-button
>
>
<el-button
type=
"danger"
:icon=
"Delete"
@
click=
"handleDelete"
>
删除
</el-button>
<el-button
v-permission=
"'AccountDelete'"
type=
"danger"
:icon=
"Delete"
@
click=
"handleDelete"
>
删除
</el-button>
</
template
>
</
template
>
</ProTable>
</ProTable>
...
...
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