harrywan 2717e539d1 * feat(plugin-layout): layout支持运行时配置menus (#113)
* feat(plugin-layout): 支持运行时配置menus

* refactor(plugin-model): 去掉provide

* refactor(plugin-layout): 优化runtimeConfig,重新实现运行时menus配置方式,修复多页时setup执行两次的bug

* feat(plugin-layout): 菜单支持配置默认展开等

* refactor: 优化
2022-04-11 19:40:16 +08:00

28 lines
777 B
JavaScript

export function getIconNamesFromMenu(data) {
if (!Array.isArray(data)) {
return [];
}
let icons = [];
data.forEach((item = { path: '/' }) => {
if (item.icon) {
const { icon } = item;
// 处理icon
if (icon) {
const urlReg = /^((https?|ftp|file):\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;
if (
typeof icon === 'string'
&& !(urlReg.test(icon) || icon.includes('.svg'))
) {
icons.push(icon);
}
}
}
if (item.children) {
icons = icons.concat(getIconNamesFromMenu(item.children));
}
});
return Array.from(new Set(icons));
}