Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/jsdom-25.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vince292007 authored Aug 27, 2024
2 parents 315c7e6 + 8adb228 commit 1b2b35d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 7 additions & 3 deletions docs/src/en/guide/in-depth/access.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ const { hasAccessByCodes } = useAccess();

#### Directive Method

> The directive supports binding single or multiple permission codes. For a single one, you can pass a string or an array containing one permission code, and for multiple permission codes, you can pass an array.
```vue
<template>
<Button class="mr-4" v-access:code="['AC_100100']">
Visible to Super account ["AC_1000001"]
<Button class="mr-4" v-access:code="'AC_100100'">
Visible to Super account 'AC_100100'
</Button>
<Button class="mr-4" v-access:code="['AC_100030']">
Visible to Admin account ["AC_100010"]
Expand Down Expand Up @@ -296,9 +298,11 @@ const { hasAccessByRoles } = useAccess();

#### Directive Method

> The directive supports binding single or multiple permission codes. For a single one, you can pass a string or an array containing one permission code, and for multiple permission codes, you can pass an array.
```vue
<template>
<Button class="mr-4" v-access:role="['super']">
<Button class="mr-4" v-access:role="'super'">
Visible to Super account
</Button>
<Button class="mr-4" v-access:role="['admin']">
Expand Down
9 changes: 7 additions & 2 deletions docs/src/guide/in-depth/access.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ const { hasAccessByCodes } = useAccess();

#### 指令方式

> 指令支持绑定单个或多个权限码。单个时可以直接传入字符串或数组中包含一个权限码,多个权限码则传入数组。
```vue
<template>
<Button class="mr-4" v-access:code="['AC_100100']">
Super 账号可见 ["AC_1000001"]
<Button class="mr-4" v-access:code="'AC_100100'">
Super 账号可见 'AC_100100'
</Button>
<Button class="mr-4" v-access:code="['AC_100030']">
Admin 账号可见 ["AC_100010"]
Expand Down Expand Up @@ -294,8 +296,11 @@ const { hasAccessByRoles } = useAccess();

#### 指令方式

> 指令支持绑定单个或多个权限码。单个时可以直接传入字符串或数组中包含一个权限码,多个权限码则传入数组。
```vue
<template>
<Button class="mr-4" v-access:role="'super'"> Super 角色可见 </Button>
<Button class="mr-4" v-access:role="['super']"> Super 角色可见 </Button>
<Button class="mr-4" v-access:role="['admin']"> Admin 角色可见 </Button>
<Button class="mr-4" v-access:role="['user']"> User 角色可见 </Button>
Expand Down
16 changes: 10 additions & 6 deletions packages/effects/access/src/directive.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
/**
* Global authority directive
* Used for fine-grained control of component permissions
* @Example v-auth="RoleEnum.TEST"
* @Example v-access:role="[ROLE_NAME]" or v-access:role="ROLE_NAME"
* @Example v-access:code="[ROLE_CODE]" or v-access:code="ROLE_CODE"
*/
import type { App, Directive, DirectiveBinding } from 'vue';

import { useAccess } from './use-access';

function isAccessible(el: Element, binding: any) {
function isAccessible(
el: Element,
binding: DirectiveBinding<string | string[]>,
) {
const { accessMode, hasAccessByCodes, hasAccessByRoles } = useAccess();

const value = binding.value;

if (!value) {
return;
}
if (!value) return;
const authMethod =
accessMode.value === 'frontend' && binding.arg === 'role'
? hasAccessByRoles
: hasAccessByCodes;

if (!authMethod(value)) {
const values = Array.isArray(value) ? value : [value];

if (!authMethod(values)) {
el?.remove();
}
}
Expand Down

0 comments on commit 1b2b35d

Please sign in to comment.