Skip to content

Commit

Permalink
删除多余的依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jan 5, 2023
1 parent e2c5c88 commit de2b5a6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/transformRoute/transformRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function formatter(
...finallyItem,
path: finallyItem.path || finallyItem.originPath,
} as MenuDataItem;

if (!item.children && item[childrenPropsName]) {
item.children = item[childrenPropsName];
delete item[childrenPropsName];
Expand All @@ -212,7 +213,7 @@ function formatter(
})

.map((item = { path: '/' }) => {
const routerChildren = item.children || [];
const routerChildren = item.children || item[childrenPropsName] || [];
const path = mergePath(item.path, parent ? parent.path : '/');
const { name } = item;
const locale = getItemLocaleName(item, parentName || 'menu');
Expand Down Expand Up @@ -296,8 +297,7 @@ const defaultFilterMenuData = (menuData: MenuDataItem[] = []): MenuDataItem[] =>
)
.map((item: MenuDataItem) => {
const newItem = { ...item };
const routerChildren = newItem.children || [];
// 兼容一下使用了 children 的旧版,有空删除一下
const routerChildren = newItem.children || item[childrenPropsName] || [];
delete newItem[childrenPropsName];
if (
notNullArray(routerChildren) &&
Expand Down Expand Up @@ -351,7 +351,8 @@ const getBreadcrumbNameMap = (
const routerMap = new RouteListMap<MenuDataItem>();
const flattenMenuData = (data: MenuDataItem[], parent?: MenuDataItem) => {
data.forEach((menuItem) => {
const routerChildren = menuItem.children || [];
const routerChildren =
menuItem.children || menuItem[childrenPropsName] || [];
if (notNullArray(routerChildren)) {
flattenMenuData(routerChildren, menuItem);
}
Expand All @@ -367,7 +368,7 @@ const getBreadcrumbNameMap = (
const clearChildren = (menuData: MenuDataItem[] = []): MenuDataItem[] => {
return menuData
.map((item: MenuDataItem) => {
const routerChildren = item.children;
const routerChildren = item.children || item[childrenPropsName];
if (notNullArray(routerChildren)) {
const newChildren = clearChildren(routerChildren);
if (newChildren.length) return { ...item };
Expand Down

0 comments on commit de2b5a6

Please sign in to comment.