|
1
|
<template>
|
vben
authored
|
2
|
<PageWrapper contentBackground title="按钮权限控制" contentClass="p-4">
|
|
3
4
5
6
7
|
<Alert message="刷新后会还原" show-icon />
<CurrentPermissionMode />
<p>
|
Vben
authored
|
8
|
当前拥有的code列表: <a> {{ permissionStore.getPermCodeList }} </a>
|
|
9
10
11
12
13
14
15
16
17
18
19
20
21
|
</p>
<Divider />
<Alert class="mt-4" type="info" message="点击后请查看按钮变化" show-icon />
<Divider />
<a-button type="primary" class="mr-2" @click="changePermissionCode('2')">
点击切换按钮权限(用户id为2)
</a-button>
<a-button type="primary" @click="changePermissionCode('1')">
点击切换按钮权限(用户id为1,默认)
</a-button>
<Divider>组件方式判断权限</Divider>
<Authority :value="'1000'">
|
vben
authored
|
22
|
<a-button type="primary" class="mx-4"> 拥有code ['1000']权限可见 </a-button>
|
|
23
24
25
|
</Authority>
<Authority :value="'2000'">
|
vben
authored
|
26
|
<a-button color="success" class="mx-4"> 拥有code ['2000']权限可见 </a-button>
|
|
27
28
29
|
</Authority>
<Authority :value="['1000', '2000']">
|
vben
authored
|
30
|
<a-button color="error" class="mx-4"> 拥有code ['1000','2000']角色权限可见 </a-button>
|
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
</Authority>
<Divider>函数方式方式判断权限</Divider>
<a-button v-if="hasPermission('1000')" type="primary" class="mx-4">
拥有code ['1000']权限可见
</a-button>
<a-button v-if="hasPermission('2000')" color="success" class="mx-4">
拥有code ['2000']权限可见
</a-button>
<a-button v-if="hasPermission(['1000', '2000'])" color="error" class="mx-4">
拥有code ['1000','2000']角色权限可见
</a-button>
<Divider>指令方式方式判断权限(该方式不能动态修改权限.)</Divider>
<a-button v-auth="'1000'" type="primary" class="mx-4"> 拥有code ['1000']权限可见 </a-button>
<a-button v-auth="'2000'" color="success" class="mx-4"> 拥有code ['2000']权限可见 </a-button>
<a-button v-auth="['1000', '2000']" color="error" class="mx-4">
拥有code ['1000','2000']角色权限可见
</a-button>
|
vben
authored
|
54
|
</PageWrapper>
|
|
55
56
57
58
59
60
|
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { Alert, Divider } from 'ant-design-vue';
import CurrentPermissionMode from '../CurrentPermissionMode.vue';
import { usePermission } from '/@/hooks/web/usePermission';
|
vben
authored
|
61
|
import { Authority } from '/@/components/Authority';
|
Vben
authored
|
62
|
import { usePermissionStore } from '/@/store/modules/permission';
|
|
63
|
import { PermissionModeEnum } from '/@/enums/appEnum';
|
vben
authored
|
64
65
|
import { PageWrapper } from '/@/components/Page';
|
|
66
|
export default defineComponent({
|
vben
authored
|
67
|
components: { Alert, PageWrapper, CurrentPermissionMode, Divider, Authority },
|
|
68
69
|
setup() {
const { hasPermission } = usePermission();
|
Vben
authored
|
70
|
const permissionStore = usePermissionStore();
|
|
71
|
|
Vben
authored
|
72
73
|
function changePermissionCode(userId: string) {
permissionStore.changePermissionCode(userId);
|
|
74
|
}
|
Vben
authored
|
75
|
|
|
76
77
78
79
80
81
82
83
84
|
return {
hasPermission,
permissionStore,
changePermissionCode,
PermissionModeEnum,
};
},
});
</script>
|
nebv
authored
|
85
86
|
<style lang="less" scoped>
.demo {
|
Vben
authored
|
87
|
background-color: @component-background;
|
nebv
authored
|
88
89
|
}
</style>
|