global.md 1.3 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
## uniIDHasRole

新增于`HBuilderX 3.1.15-alpha`,判断当前用户是否拥有某角色。

> 需要在token内缓存角色权限才可使用,请参考:[缓存角色权限](https://uniapp.dcloud.net.cn/uniCloud/uni-id?id=cachepermissionintoken)

**在模板内使用**

```html
<template>
  <view v-if="uniIDHasRole('admin')">仅管理员可见</view>
</template>
```

**在页面/组件js代码中使用**

```html
<template>
  <view>xxx</view>
</template>
<script>
  export default {
    onLoad(){
      console.log('当前用户是否拥有管理员角色:', this.uniIDHasRole('admin'))
    }
  }
</script>
```

## uniIDHasPermission

新增于`HBuilderX 3.1.15-alpha`,判断当前用户是否拥有某权限,注意:admin角色的用户拥有所有权限

> 需要在token内缓存角色权限才可使用,请参考:[缓存角色权限](https://uniapp.dcloud.net.cn/uniCloud/uni-id?id=cachepermissionintoken)

**在模板内使用**

```html
<template>
  <view v-if="uniIDHasPermission('edit')">拥有编辑权限时可见</view>
</template>
```

**在页面/组件js代码中使用**

```html
<template>
  <view>xxx</view>
</template>
<script>
  export default {
    onLoad(){
      console.log('当前用户是否拥有编辑权限:', this.uniIDHasPermission('edit'))
    }
  }
</script>
```