From c24447cf35a6db0825d87fe32e7a553df8ed7ae2 Mon Sep 17 00:00:00 2001 From: winixt Date: Wed, 23 Aug 2023 18:45:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20plugin=20access=20=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?getRole=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/reference/plugin/plugins/access.md | 10 ++++++++++ packages/fes-plugin-access/src/runtime/core.tpl | 3 +++ packages/fes-template/src/app.jsx | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/reference/plugin/plugins/access.md b/docs/reference/plugin/plugins/access.md index ff6ac204..11c56248 100644 --- a/docs/reference/plugin/plugins/access.md +++ b/docs/reference/plugin/plugins/access.md @@ -227,6 +227,16 @@ import { access } from '@fesjs/fes'; access.setRole('admin'); ``` +#### access.getRole + +- **类型**:函数 +- **详情**:获取当前的角色。 + +```js +import { access } from '@fesjs/fes'; +access.getRole(); +``` + #### access.setAccess - **类型**:函数 diff --git a/packages/fes-plugin-access/src/runtime/core.tpl b/packages/fes-plugin-access/src/runtime/core.tpl index 5164b130..6ed11d9d 100644 --- a/packages/fes-plugin-access/src/runtime/core.tpl +++ b/packages/fes-plugin-access/src/runtime/core.tpl @@ -138,6 +138,9 @@ export const access = { hasAccess, isDataReady, setRole, + getRole: () => { + return state.currentRoleId + }, setAccess, match, getAccess: getAllowAccessIds, diff --git a/packages/fes-template/src/app.jsx b/packages/fes-template/src/app.jsx index fb89d5ec..43cb628f 100644 --- a/packages/fes-template/src/app.jsx +++ b/packages/fes-template/src/app.jsx @@ -6,13 +6,14 @@ import UserCenter from '@/components/userCenter.vue'; export const beforeRender = { loading: , action() { - const { setRole } = accessApi; + const { setRole, getRole } = accessApi; return new Promise((resolve) => { setTimeout(() => { setRole('admin'); resolve({ userName: '李雷', }); + console.log('currentRole', getRole()); createWatermark({ content: '万纯(harrywan)' }); }, 1000); });