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' }, {