fix: 优化plugin-layout,插件的配置 > 关联的路由元信息

This commit is contained in:
万纯 2021-03-05 17:35:38 +08:00
parent 1a406164d5
commit b32f087e12
2 changed files with 20 additions and 34 deletions

View File

@ -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;

View File

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