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); });