Skip to content

Commit

Permalink
fix(plugin-access): 修复切换角色时,getAccess 不正确
Browse files Browse the repository at this point in the history
  • Loading branch information
1zumii committed Apr 28, 2024
1 parent 5a041f0 commit 9753913
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 17 additions & 5 deletions packages/fes-plugin-access/src/runtime/core.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { reactive, unref, computed, inject } from "vue";
import createDirective from "./createDirective";
import { computed, reactive, unref } from "vue";
import { isPlainObject } from "{{{ lodashPath }}}";
import createComponent from "./createComponent";
import {isPlainObject} from "{{{ lodashPath }}}";
import createDirective from "./createDirective";

function isPromise(obj) {
return (
Expand All @@ -20,12 +20,23 @@ const state = reactive({
const rolePromiseList = [];
const accessPromiseList = [];

// 预设的 accessId,且不会被移除
const presetAccessIds = []
const setPresetAccess = (access) => {
const accessIds = Array.isArray(access) ? access : [access];
presetAccessIds.push(...accessIds.filter(id => !presetAccessIds.includes(id)));
}

const getAllowAccessIds = () => {
const result = [...presetAccessIds, ...state.currentAccessIds];
const roleAccessIds = state.roles[state.currentRoleId];
if (Array.isArray(roleAccessIds) && roleAccessIds.length > 0) {
return state.currentAccessIds.concat(roleAccessIds);
result.push(...roleAccessIds);
}
return state.currentAccessIds;

return result;
};

const _syncSetAccessIds = (promise) => {
Expand Down Expand Up @@ -144,6 +155,7 @@ export const access = {
setAccess,
match,
getAccess: getAllowAccessIds,
setPresetAccess,
};

export const hasAccessSync = (path) => {
Expand Down
9 changes: 2 additions & 7 deletions packages/fes-plugin-layout/src/runtime/runtime.js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ if (!accessApi) {

export const access = (memo) => {
const runtimeConfig = getConfig();
const accessIds = accessApi.getAccess();
if (!accessIds.includes('/403')) {
accessApi.setAccess(accessIds.concat('/403'));
}
if (!accessIds.includes('/404')) {
accessApi.setAccess(accessIds.concat('/404'));
}
accessApi.setPresetAccess(['/403', '/404']);
return {
unAccessHandler({ router, to, from, next }) {
if (runtimeConfig.unAccessHandler && typeof runtimeConfig.unAccessHandler === 'function') {
Expand Down

0 comments on commit 9753913

Please sign in to comment.