From 42aba5e50b3ebf78c4a8f446584ceed03838bd3a Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Tue, 14 Mar 2023 15:41:58 +0800 Subject: [PATCH] feat: expand and collapse are only displayed in the tree table --- .../schema-initializer/SchemaInitializer.tsx | 108 +++++++++--------- .../buttons/TableActionInitializers.tsx | 9 +- 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/packages/core/client/src/schema-initializer/SchemaInitializer.tsx b/packages/core/client/src/schema-initializer/SchemaInitializer.tsx index ac206dac44..3e6fbd76eb 100644 --- a/packages/core/client/src/schema-initializer/SchemaInitializer.tsx +++ b/packages/core/client/src/schema-initializer/SchemaInitializer.tsx @@ -47,59 +47,63 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => { } }; const renderItems = (items: any) => { - return items?.map((item, indexA) => { - if (item.type === 'divider') { - return ; - } - if (item.type === 'item' && item.component) { - const Component = findComponent(item.component); - item.key = `${item.key || item.title}-${indexA}`; - return ( - Component && ( - - { + return v?.visible ? v.visible() : true; + }) + ?.map((item, indexA) => { + if (item.type === 'divider') { + return ; + } + if (item.type === 'item' && item.component) { + const Component = findComponent(item.component); + item.key = `${item.key || item.title}-${indexA}`; + return ( + Component && ( + - - ) - ); - } - if (item.type === 'itemGroup') { - return ( - !!item.children?.length && ( - - {renderItems(item.children)} - - ) - ); - } - if (item.type === 'subMenu') { - return ( - !!item.children?.length && ( - - {renderItems(item.children)} - - ) - ); - } - }); + > + + + ) + ); + } + if (item.type === 'itemGroup') { + return ( + !!item.children?.length && ( + + {renderItems(item.children)} + + ) + ); + } + if (item.type === 'subMenu') { + return ( + !!item.children?.length && ( + + {renderItems(item.children)} + + ) + ); + } + }); }; const menu = {renderItems(items)}; if (!designable && props.designable !== true) { diff --git a/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx index 74b53bce9c..68a025b64f 100644 --- a/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx @@ -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; + }, }, ], },