diff --git a/packages/fes-plugin-access/package.json b/packages/fes-plugin-access/package.json index 605c9778..e27c1890 100644 --- a/packages/fes-plugin-access/package.json +++ b/packages/fes-plugin-access/package.json @@ -26,6 +26,9 @@ "publishConfig": { "access": "public" }, + "dependencies": { + "lodash": "^4.17.15" + }, "peerDependencies": { "@fesjs/fes": "^2.0.0-rc.0", "vue": "^3.0.5" diff --git a/packages/fes-plugin-access/src/runtime/core.tpl b/packages/fes-plugin-access/src/runtime/core.tpl index cd0c9c3c..322b9f59 100644 --- a/packages/fes-plugin-access/src/runtime/core.tpl +++ b/packages/fes-plugin-access/src/runtime/core.tpl @@ -1,6 +1,7 @@ import { reactive, unref, computed, inject } from "vue"; import createDirective from "./createDirective"; import createComponent from "./createComponent"; +import isPlainObject from "lodash/isPlainObject"; const accessKey = Symbol("plugin-access"); @@ -50,16 +51,21 @@ const setAccess = (accessIds) => { if (isPromise(accessIds)) { return _syncSetAccessIds(accessIds); } + if(isPlainObject(accessIds)){ + if(accessIds.accessIds){ + setAccess(accessIds.accessIds); + } + if(accessIds.roleId){ + setRole(accessIds.roleId); + } + return + } if (!Array.isArray(accessIds)) { - throw new Error("[plugin-access]: argument to the setAccess() must be array or promise"); + throw new Error("[plugin-access]: argument to the setAccess() must be array or promise or object"); } state.currentAccessIds = accessIds; }; -const getAccess = () => { - return state.currentAccessIds.slice(0) -} - const _syncSetRoleId = (promise) => { rolePromiseList.push(promise); promise @@ -143,7 +149,7 @@ export const access = { isDataReady, setRole, setAccess, - getAccess, + getAccess: getAllowAccessIds, }; export const useAccess = (path) => {