fix(plugin-access): 修复getAccess的问题

This commit is contained in:
harrywan 2021-04-29 10:59:00 +08:00
parent 463291b08a
commit bdd63e6449
2 changed files with 15 additions and 6 deletions

View File

@ -26,6 +26,9 @@
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"dependencies": {
"lodash": "^4.17.15"
},
"peerDependencies": { "peerDependencies": {
"@fesjs/fes": "^2.0.0-rc.0", "@fesjs/fes": "^2.0.0-rc.0",
"vue": "^3.0.5" "vue": "^3.0.5"

View File

@ -1,6 +1,7 @@
import { reactive, unref, computed, inject } from "vue"; import { reactive, unref, computed, inject } from "vue";
import createDirective from "./createDirective"; import createDirective from "./createDirective";
import createComponent from "./createComponent"; import createComponent from "./createComponent";
import isPlainObject from "lodash/isPlainObject";
const accessKey = Symbol("plugin-access"); const accessKey = Symbol("plugin-access");
@ -50,16 +51,21 @@ const setAccess = (accessIds) => {
if (isPromise(accessIds)) { if (isPromise(accessIds)) {
return _syncSetAccessIds(accessIds); return _syncSetAccessIds(accessIds);
} }
if(isPlainObject(accessIds)){
if(accessIds.accessIds){
setAccess(accessIds.accessIds);
}
if(accessIds.roleId){
setRole(accessIds.roleId);
}
return
}
if (!Array.isArray(accessIds)) { 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; state.currentAccessIds = accessIds;
}; };
const getAccess = () => {
return state.currentAccessIds.slice(0)
}
const _syncSetRoleId = (promise) => { const _syncSetRoleId = (promise) => {
rolePromiseList.push(promise); rolePromiseList.push(promise);
promise promise
@ -143,7 +149,7 @@ export const access = {
isDataReady, isDataReady,
setRole, setRole,
setAccess, setAccess,
getAccess, getAccess: getAllowAccessIds,
}; };
export const useAccess = (path) => { export const useAccess = (path) => {