index.vue 1.9 KB
Newer Older
陈文彬 已提交
1
<template>
2 3 4 5 6 7
  <PageWrapper
    title="前端权限示例"
    contentBackgrond
    contentClass="p-4"
    content="由于刷新的时候会请求用户信息接口,会根据接口重置角色信息,所以刷新后界面会恢复原样,如果不需要,可以注释 src/layout/default/index内的获取用户信息接口"
  >
陈文彬 已提交
8 9 10 11 12 13 14 15 16 17
    <CurrentPermissionMode />

    <p>
      当前角色: <a> {{ userStore.getRoleListState }} </a>
    </p>
    <Alert class="mt-4" type="info" message="点击后请查看左侧菜单变化" show-icon />

    <div class="mt-4">
      权限切换(请先切换权限模式为前端角色权限模式):
      <a-button-group>
V
vben 已提交
18
        <a-button @click="changeRole(RoleEnum.SUPER)" :type="isSuper ? 'primary' : 'default'">
陈文彬 已提交
19 20
          {{ RoleEnum.SUPER }}
        </a-button>
V
vben 已提交
21
        <a-button @click="changeRole(RoleEnum.TEST)" :type="isTest ? 'primary' : 'default'">
陈文彬 已提交
22 23 24 25
          {{ RoleEnum.TEST }}
        </a-button>
      </a-button-group>
    </div>
26
  </PageWrapper>
陈文彬 已提交
27 28 29 30 31 32 33 34
</template>
<script lang="ts">
  import { computed, defineComponent } from 'vue';
  import { Alert } from 'ant-design-vue';
  import CurrentPermissionMode from '../CurrentPermissionMode.vue';
  import { userStore } from '/@/store/modules/user';
  import { RoleEnum } from '/@/enums/roleEnum';
  import { usePermission } from '/@/hooks/web/usePermission';
35
  import { PageWrapper } from '/@/components/Page';
陈文彬 已提交
36 37

  export default defineComponent({
38
    components: { Alert, CurrentPermissionMode, PageWrapper },
陈文彬 已提交
39 40 41 42 43 44 45 46 47 48 49 50
    setup() {
      const { changeRole } = usePermission();
      return {
        userStore,
        RoleEnum,
        isSuper: computed(() => userStore.getRoleListState.includes(RoleEnum.SUPER)),
        isTest: computed(() => userStore.getRoleListState.includes(RoleEnum.TEST)),
        changeRole,
      };
    },
  });
</script>
N
nebv 已提交
51 52 53 54 55
<style lang="less" scoped>
  .demo {
    background: #fff;
  }
</style>