|
1
|
<template>
|
vben
authored
|
2
3
|
<PageWrapper
title="前端权限示例"
|
vben
authored
|
4
|
contentBackground
|
vben
authored
|
5
6
7
|
contentClass="p-4"
content="由于刷新的时候会请求用户信息接口,会根据接口重置角色信息,所以刷新后界面会恢复原样,如果不需要,可以注释 src/layout/default/index内的获取用户信息接口"
>
|
|
8
9
10
|
<CurrentPermissionMode />
<p>
|
Vben
authored
|
11
|
当前角色: <a> {{ userStore.getRoleList }} </a>
|
|
12
13
14
15
16
|
</p>
<Alert class="mt-4" type="info" message="点击后请查看左侧菜单变化" show-icon />
<div class="mt-4">
权限切换(请先切换权限模式为前端角色权限模式):
|
vben
authored
|
17
|
<Space>
|
vben
authored
|
18
|
<a-button @click="changeRole(RoleEnum.SUPER)" :type="isSuper ? 'primary' : 'default'">
|
|
19
20
|
{{ RoleEnum.SUPER }}
</a-button>
|
vben
authored
|
21
|
<a-button @click="changeRole(RoleEnum.TEST)" :type="isTest ? 'primary' : 'default'">
|
|
22
23
|
{{ RoleEnum.TEST }}
</a-button>
|
vben
authored
|
24
|
</Space>
|
|
25
|
</div>
|
vben
authored
|
26
|
</PageWrapper>
|
|
27
28
29
|
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue';
|
vben
authored
|
30
|
import { Alert, Space } from 'ant-design-vue';
|
Vben
authored
|
31
|
import { useUserStore } from '/@/store/modules/user';
|
|
32
33
|
import { RoleEnum } from '/@/enums/roleEnum';
import { usePermission } from '/@/hooks/web/usePermission';
|
vben
authored
|
34
|
import { PageWrapper } from '/@/components/Page';
|
vben
authored
|
35
|
import CurrentPermissionMode from '../CurrentPermissionMode.vue';
|
|
36
37
|
export default defineComponent({
|
vben
authored
|
38
|
components: { Space, Alert, CurrentPermissionMode, PageWrapper },
|
|
39
40
|
setup() {
const { changeRole } = usePermission();
|
Vben
authored
|
41
42
|
const userStore = useUserStore();
|
|
43
44
45
|
return {
userStore,
RoleEnum,
|
Vben
authored
|
46
47
|
isSuper: computed(() => userStore.getRoleList.includes(RoleEnum.SUPER)),
isTest: computed(() => userStore.getRoleList.includes(RoleEnum.TEST)),
|
|
48
49
50
51
52
|
changeRole,
};
},
});
</script>
|
nebv
authored
|
53
54
|
<style lang="less" scoped>
.demo {
|
Vben
authored
|
55
|
background-color: @component-background;
|
nebv
authored
|
56
57
|
}
</style>
|