refactor(projects): mock权限相关数据优化

This commit is contained in:
Soybean
2022-04-26 00:12:20 +08:00
parent 5c75e9d958
commit 41e46a5d80
12 changed files with 915 additions and 17 deletions

View File

@ -8,7 +8,7 @@
:value="auth.userInfo.userRole"
class="w-120px"
size="small"
:options="roleList"
:options="options"
@update:value="auth.updateUserRole"
/>
<div class="py-12px">
@ -17,7 +17,7 @@
<div>
<n-button v-permission="'super'" class="mr-12px">super可见</n-button>
<n-button v-permission="'admin'" class="mr-12px">admin可见</n-button>
<n-button v-permission="['admin', 'test']">admin和test可见</n-button>
<n-button v-permission="['admin', 'user']">admin和test可见</n-button>
</div>
<div class="py-12px">
<n-gradient-text type="primary" :size="20">权限函数 hasPermission</n-gradient-text>
@ -25,7 +25,7 @@
<n-space>
<n-button v-if="hasPermission('super')">super可见</n-button>
<n-button v-if="hasPermission('admin')">admin可见</n-button>
<n-button v-if="hasPermission(['admin', 'test'])">admin和test可见</n-button>
<n-button v-if="hasPermission(['admin', 'user'])">admin和user可见</n-button>
</n-space>
</n-card>
</div>
@ -33,6 +33,8 @@
<script setup lang="ts">
import { watch } from 'vue';
import type { SelectOption } from 'naive-ui';
import { EnumUserRole } from '@/enum';
import { useAppStore, useAuthStore } from '@/store';
import { usePermission } from '@/composables';
@ -40,12 +42,19 @@ const app = useAppStore();
const auth = useAuthStore();
const { hasPermission } = usePermission();
const roleList = [
{ label: '超级管理员', value: 'super' },
{ label: '管理员', value: 'admin' },
{ label: '测试', value: 'test' }
interface RoleList {
label: string;
value: keyof typeof EnumUserRole;
}
const roleList: RoleList[] = [
{ label: EnumUserRole.super, value: 'super' },
{ label: EnumUserRole.admin, value: 'admin' },
{ label: EnumUserRole.user, value: 'user' }
];
const options: SelectOption[] = roleList as unknown as SelectOption[];
watch(
() => auth.userInfo.userRole,
async () => {