-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Authorized common component
- Loading branch information
Showing
7 changed files
with
61 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script setup lang="ts"> | ||
import { AuthorizedProps } from '~/types' | ||
defineOptions({ name: 'Authorize' }) | ||
const props = defineProps<AuthorizedProps>() | ||
const permission = toRef(props, 'permission') | ||
const { isHavePermission } = usePermission(permission.value) | ||
</script> | ||
|
||
<template> | ||
<slot v-if="isHavePermission" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface AuthorizedProps { | ||
permission: string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
<script setup lang="ts"> | ||
import Authorized from '~/components/common/Authorized.vue' | ||
</script> | ||
|
||
<template> | ||
<div | ||
class="w-full h-40 flex flex-col items-center justify-center | ||
text-base space-y-4 rounded-sm border border-vBorderLight dark:border-vBorderDark" | ||
class="w-full h-40 flex flex-col items-center justify-center text-base | ||
space-y-4 rounded-sm border border-vBorderLight dark:border-vBorderDark" | ||
> | ||
<NButton | ||
v-permission="['sys:admin:*']" | ||
type="primary" | ||
> | ||
超级管理员按钮 | ||
</NButton> | ||
<NButton | ||
v-permission="['sys:user:*']" | ||
type="primary" | ||
> | ||
普通管理员按钮 | ||
</NButton> | ||
<div class="text-sm"> | ||
按钮级别权限提供三种方式: 指定权限、组件权限和钩子函数 | ||
</div> | ||
|
||
<div> | ||
<NButton | ||
v-permission="['sys:admin:*']" | ||
type="primary" | ||
> | ||
指令权限-超级管理员按钮 | ||
</NButton> | ||
<NButton | ||
v-permission="['sys:user:*']" | ||
type="primary" | ||
> | ||
指令权限-普通管理员按钮 | ||
</NButton> | ||
</div> | ||
|
||
<div> | ||
<Authorized :permission="['sys:admin:*']"> | ||
<NButton type="primary"> | ||
组件权限-超级管理员按钮 | ||
</NButton> | ||
</Authorized> | ||
<Authorized :permission="['sys:user:*']"> | ||
<NButton type="primary"> | ||
组件权限-普通管理员按钮 | ||
</NButton> | ||
</Authorized> | ||
</div> | ||
</div> | ||
</template> |