From b32f087e1234cf9ee74a527c0ce9bbaa68301f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E7=BA=AF?= Date: Fri, 5 Mar 2021 17:35:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=20=E4=BC=98=E5=8C=96plugin-layout?= =?UTF-8?q?=EF=BC=8C=E6=8F=92=E4=BB=B6=E7=9A=84=E9=85=8D=E7=BD=AE=20>=20?= =?UTF-8?q?=20=E5=85=B3=E8=81=94=E7=9A=84=E8=B7=AF=E7=94=B1=E5=85=83?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/runtime/helpers/index.js | 46 ++++++------------- packages/fes-template/.fes.js | 8 ++-- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/packages/fes-plugin-layout/src/runtime/helpers/index.js b/packages/fes-plugin-layout/src/runtime/helpers/index.js index d21db0c0..a9795055 100644 --- a/packages/fes-plugin-layout/src/runtime/helpers/index.js +++ b/packages/fes-plugin-layout/src/runtime/helpers/index.js @@ -1,38 +1,17 @@ export const noop = () => {}; const matchName = (config, name) => { - let res; - if (Array.isArray(config)) { - for (let i = 0; i < config.length; i++) { - const item = config[i]; - if (item.meta && item.meta.name === name) { - res = item.meta; - res.path = item.path; - break; - } - if (item.children && item.children.length > 0) { - res = matchName(item.children, name); - if (res) { - break; - } - } - } - } - return res; -}; - -const matchPath = (config, path) => { let res = {}; if (Array.isArray(config)) { for (let i = 0; i < config.length; i++) { const item = config[i]; - if (item.path && item.path === path) { + if (item.meta && item.meta.name === name) { res = item.meta || {}; res.path = item.path; break; } if (item.children && item.children.length > 0) { - res = matchPath(item.children, path); + res = matchName(item.children, name); if (res) { break; } @@ -49,16 +28,21 @@ export const fillMenuData = (menuConfig, routeConfig, dep = 0) => { } const arr = []; if (Array.isArray(menuConfig) && Array.isArray(routeConfig)) { - menuConfig.forEach((item) => { - if (item.path !== undefined && item.path !== null) { - Object.assign(item, matchPath(routeConfig, item.path)); - } else { - Object.assign(item, matchName(routeConfig, item.name)); + menuConfig.forEach((menu) => { + const pageConfig = {}; + if (menu.name) { + Object.assign(pageConfig, matchName(routeConfig, menu.name)); } - if (item.children && item.children.length > 0) { - item.children = fillMenuData(item.children, routeConfig, dep); + // menu的配置优先级高,当menu存在配置时,忽略页面的配置 + Object.keys(pageConfig).forEach((prop) => { + if (menu[prop] === undefined || menu[prop] === null || menu[prop] === '') { + menu[prop] = pageConfig[prop]; + } + }); + if (menu.children && menu.children.length > 0) { + menu.children = fillMenuData(menu.children, routeConfig, dep); } - arr.push(item); + arr.push(menu); }); } return arr; diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index c263bcf1..ab30984a 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -12,7 +12,7 @@ export default { publicPath: '/', access: { roles: { - admin: ["/"] + admin: ["/", "https://www.baidu.com"] } }, request: { @@ -31,10 +31,12 @@ export default { title: "Fes.js", footer: 'Created by MumbelFe', multiTabs: false, + navigation: 'mixin', menus: [{ - name: 'index' + name: 'index', }, { - name: 'onepiece' + name: 'onepiece', + path: 'https://www.baidu.com' }, { name: 'store' }, {