diff --git a/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemGroup.tsx b/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemGroup.tsx index 5a9baacc20..2e07a2adf6 100644 --- a/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemGroup.tsx +++ b/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemGroup.tsx @@ -49,7 +49,7 @@ export const SchemaInitializerItemGroupInternal = () => { const itemConfig: any = useSchemaInitializerItem(); const searchedChildren = useMenuSearch(itemConfig); - if (itemConfig.name !== 'displayFields') { + if (itemConfig.name && itemConfig.name !== 'displayFields') { return ; } /* eslint-disable react/no-children-prop */ diff --git a/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemSearchFields.tsx b/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemSearchFields.tsx index aa4e9d4f0a..65f2457343 100644 --- a/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemSearchFields.tsx +++ b/packages/core/client/src/application/schema-initializer/components/SchemaInitializerItemSearchFields.tsx @@ -123,62 +123,59 @@ export const useMenuSearch = (props: { children: any[]; showType?: boolean; hide // 最终结果项 const resultItems = useMemo(() => { const res = []; - if (!hideSearch && (items.length > 10 || searchValue)) { - res.push({ - key: `search-${uid()}`, - Component: () => ( - { - setSearchValue(val); - }} - /> - ), - onClick({ domEvent }) { - domEvent.stopPropagation(); - }, - ...(showType ? { isMenuType: true } : {}), - }); - } + try { + // 如果满足条件则显示搜索框 + if (!hideSearch && (items.length > 10 || searchValue)) { + res.push({ + key: `search-${uid()}`, + Component: () => ( + setSearchValue(val)} /> + ), + onClick({ domEvent }) { + domEvent.stopPropagation(); + }, + ...(showType ? { isMenuType: true } : {}), + }); + } - if (limitedSearchedItems.length > 0) { + // 如果有匹配的项目,渲染过滤后的项 + if (limitedSearchedItems.length > 0) { + limitedSearchedItems.forEach((item) => { + // 如果是子菜单或分组项,递归处理 + if (['subMenu', 'itemGroup'].includes(item.type)) { + // 避免动态渲染hooks + const childItems = item.children + ? // eslint-disable-next-line react-hooks/rules-of-hooks + useMenuSearch({ + children: item.children, + showType, + hideSearch, + name: item.name, + }) + : []; + res.push({ ...item, children: childItems }); + } else { + res.push(item); + } + }); + } else { + // 没有匹配项时显示空状态 + res.push({ + key: 'empty', + style: { height: 150 }, + Component: () => ( +
e.stopPropagation()}> + +
+ ), + ...(showType ? { isMenuType: true } : {}), + }); + } + } catch (error) { res.push(...limitedSearchedItems); - } else { - res.push({ - key: 'empty', - style: { - height: 150, - }, - Component: () => ( -
e.stopPropagation()}> - -
- ), - ...(showType ? { isMenuType: true } : {}), - }); } - return res; }, [hideSearch, limitedSearchedItems, searchValue, showType]); - const result = processedResult(resultItems, showType, hideSearch, name); - - return children ? result : undefined; -}; - -// 处理嵌套子菜单 -const processedResult = (resultItems, showType, hideSearch, name) => { - return resultItems.map((item: any) => { - if (['subMenu', 'itemGroup'].includes(item.type)) { - const childItems = useMenuSearch({ - children: item.children, - showType, - hideSearch, - name: item.name, - }); - return { ...item, children: childItems }; - } - return item; - }); + return children ? resultItems : undefined; };