授权认证(Auth)
# 权限相关
# 1、如何判断是否拥有某个按钮权限
在框架中的account
状态里,提供了可以判断用户是否拥有某个按钮权限的 Mutation haButton
,该方法接收一个button
对象。
举个例子,在用户列表里面,有一列是控制用户是否启用状态的 switch 开关,您想对这个开关进行权限验证,那么,您可以这样:
<template>
<dy-container>
<dy-list ref="list" v-bind="list">
<!--启用状态-->
<template v-slot:col-enabled="{row}">
<el-switch
:value="row.enabled"
@change="changeStatus(row)"
:disabled="disabledChangeStatus"
/>
</template>
</dy-list>
</dy-container>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
import { mapActions } from 'vuex'
import page from './page'
// 接口
const api = $api.admin.account
export default {
name: page.name,
data() {
return {
curr: { id: '' },
list: {
title: page.title,
cols,
action: api.query,
model: {
enabled: '',
name: '',
channelCode: ''
}
},
buttons: page.buttons,
disabledChangeStatus: false
}
},
methods: {
...mapActions('app/account', ['hasButton'])
async changeStatus(row) {
await this._confirm(`您确定要${row.enabled ? '禁用' : '启用'}《${row.name}》吗?`, '提示')
api.changeStatus({ id: row.id, enabled: !row.enabled }).then(() => {
row.enabled = !row.enabled
})
}
},
created() {
//设置修改状态按钮权限
this.hasButton(this.buttons.changeStatus).then(r => {
this.disabledChangeStatus = !r
})
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41