mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
Merge branch 'next' into develop
This commit is contained in:
commit
01adbb92ed
@ -49,7 +49,7 @@ export const SchemaInitializerItemGroupInternal = () => {
|
|||||||
const itemConfig: any = useSchemaInitializerItem<SchemaInitializerItemGroupProps>();
|
const itemConfig: any = useSchemaInitializerItem<SchemaInitializerItemGroupProps>();
|
||||||
|
|
||||||
const searchedChildren = useMenuSearch(itemConfig);
|
const searchedChildren = useMenuSearch(itemConfig);
|
||||||
if (itemConfig.name !== 'displayFields') {
|
if (itemConfig.name && itemConfig.name !== 'displayFields') {
|
||||||
return <SchemaInitializerItemGroup {...itemConfig} />;
|
return <SchemaInitializerItemGroup {...itemConfig} />;
|
||||||
}
|
}
|
||||||
/* eslint-disable react/no-children-prop */
|
/* eslint-disable react/no-children-prop */
|
||||||
|
@ -123,62 +123,59 @@ export const useMenuSearch = (props: { children: any[]; showType?: boolean; hide
|
|||||||
// 最终结果项
|
// 最终结果项
|
||||||
const resultItems = useMemo<MenuProps['items']>(() => {
|
const resultItems = useMemo<MenuProps['items']>(() => {
|
||||||
const res = [];
|
const res = [];
|
||||||
if (!hideSearch && (items.length > 10 || searchValue)) {
|
try {
|
||||||
res.push({
|
// 如果满足条件则显示搜索框
|
||||||
key: `search-${uid()}`,
|
if (!hideSearch && (items.length > 10 || searchValue)) {
|
||||||
Component: () => (
|
res.push({
|
||||||
<SearchFields
|
key: `search-${uid()}`,
|
||||||
name={name}
|
Component: () => (
|
||||||
value={searchValue}
|
<SearchFields name={name} value={searchValue} onChange={(val: string) => setSearchValue(val)} />
|
||||||
onChange={(val: string) => {
|
),
|
||||||
setSearchValue(val);
|
onClick({ domEvent }) {
|
||||||
}}
|
domEvent.stopPropagation();
|
||||||
/>
|
},
|
||||||
),
|
...(showType ? { isMenuType: true } : {}),
|
||||||
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: () => (
|
||||||
|
<div onClick={(e) => e.stopPropagation()}>
|
||||||
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
...(showType ? { isMenuType: true } : {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
res.push(...limitedSearchedItems);
|
res.push(...limitedSearchedItems);
|
||||||
} else {
|
|
||||||
res.push({
|
|
||||||
key: 'empty',
|
|
||||||
style: {
|
|
||||||
height: 150,
|
|
||||||
},
|
|
||||||
Component: () => (
|
|
||||||
<div onClick={(e) => e.stopPropagation()}>
|
|
||||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
...(showType ? { isMenuType: true } : {}),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}, [hideSearch, limitedSearchedItems, searchValue, showType]);
|
}, [hideSearch, limitedSearchedItems, searchValue, showType]);
|
||||||
|
|
||||||
const result = processedResult(resultItems, showType, hideSearch, name);
|
return children ? resultItems : undefined;
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user