From 1b0d3409bb9da3f9b4f91121fbc1035fc0b7df7b Mon Sep 17 00:00:00 2001 From: 1zumii <524123601@qq.com> Date: Mon, 29 Apr 2024 10:47:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(plugin-access):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=A7=92=E8=89=B2=E6=97=B6=EF=BC=8CgetAccess?= =?UTF-8?q?=20=E4=B8=8D=E6=AD=A3=E7=A1=AE=20(#240)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fes-plugin-access/src/runtime/core.tpl | 22 ++++++++++++++----- .../src/runtime/runtime.js.tpl | 9 ++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/fes-plugin-access/src/runtime/core.tpl b/packages/fes-plugin-access/src/runtime/core.tpl index 6ed11d9d..eac5cc69 100644 --- a/packages/fes-plugin-access/src/runtime/core.tpl +++ b/packages/fes-plugin-access/src/runtime/core.tpl @@ -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 ( @@ -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) => { @@ -144,6 +155,7 @@ export const access = { setAccess, match, getAccess: getAllowAccessIds, + setPresetAccess, }; export const hasAccessSync = (path) => { diff --git a/packages/fes-plugin-layout/src/runtime/runtime.js.tpl b/packages/fes-plugin-layout/src/runtime/runtime.js.tpl index e1890177..807762b9 100644 --- a/packages/fes-plugin-layout/src/runtime/runtime.js.tpl +++ b/packages/fes-plugin-layout/src/runtime/runtime.js.tpl @@ -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') {