feat: expand and collapse are only displayed in the tree table

This commit is contained in:
katherinehhh 2023-03-14 15:41:58 +08:00
parent b28b8ba536
commit 42aba5e50b
2 changed files with 64 additions and 53 deletions

View File

@ -47,59 +47,63 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => {
}
};
const renderItems = (items: any) => {
return items?.map((item, indexA) => {
if (item.type === 'divider') {
return <Menu.Divider key={item.key || `item-${indexA}`} />;
}
if (item.type === 'item' && item.component) {
const Component = findComponent(item.component);
item.key = `${item.key || item.title}-${indexA}`;
return (
Component && (
<SchemaInitializerItemContext.Provider
key={item.key}
value={{
index: indexA,
item,
info: item,
insert: insertSchema,
}}
>
<Component
{...item}
item={{
...item,
title: compile(item.title),
return items
.filter((v) => {
return v?.visible ? v.visible() : true;
})
?.map((item, indexA) => {
if (item.type === 'divider') {
return <Menu.Divider key={item.key || `item-${indexA}`} />;
}
if (item.type === 'item' && item.component) {
const Component = findComponent(item.component);
item.key = `${item.key || item.title}-${indexA}`;
return (
Component && (
<SchemaInitializerItemContext.Provider
key={item.key}
value={{
index: indexA,
item,
info: item,
insert: insertSchema,
}}
insert={insertSchema}
/>
</SchemaInitializerItemContext.Provider>
)
);
}
if (item.type === 'itemGroup') {
return (
!!item.children?.length && (
<Menu.ItemGroup key={item.key || `item-group-${indexA}`} title={compile(item.title)}>
{renderItems(item.children)}
</Menu.ItemGroup>
)
);
}
if (item.type === 'subMenu') {
return (
!!item.children?.length && (
<Menu.SubMenu
key={item.key || `item-group-${indexA}`}
title={compile(item.title)}
popupClassName={menuItemGroupCss}
>
{renderItems(item.children)}
</Menu.SubMenu>
)
);
}
});
>
<Component
{...item}
item={{
...item,
title: compile(item.title),
}}
insert={insertSchema}
/>
</SchemaInitializerItemContext.Provider>
)
);
}
if (item.type === 'itemGroup') {
return (
!!item.children?.length && (
<Menu.ItemGroup key={item.key || `item-group-${indexA}`} title={compile(item.title)}>
{renderItems(item.children)}
</Menu.ItemGroup>
)
);
}
if (item.type === 'subMenu') {
return (
!!item.children?.length && (
<Menu.SubMenu
key={item.key || `item-group-${indexA}`}
title={compile(item.title)}
popupClassName={menuItemGroupCss}
>
{renderItems(item.children)}
</Menu.SubMenu>
)
);
}
});
};
const menu = <Menu style={{ maxHeight: '60vh', overflowY: 'auto' }}>{renderItems(items)}</Menu>;
if (!designable && props.designable !== true) {

View File

@ -1,4 +1,5 @@
import { Schema } from '@formily/react';
import { Schema, useFieldSchema } from '@formily/react';
import { useCollection } from '../../';
// 表格操作配置
export const TableActionInitializers = {
@ -56,6 +57,12 @@ export const TableActionInitializers = {
schema: {
'x-align': 'right',
},
visible: () => {
const schema = useFieldSchema();
const collection = useCollection();
const { treeTable } = schema?.parent?.['x-decorator-props'];
return (collection as any).template === 'tree' && treeTable !== false;
},
},
],
},