From aa8ac55c2827d64e70d8c3d9c322b7f222af092b Mon Sep 17 00:00:00 2001 From: wjh Date: Wed, 13 Mar 2024 17:52:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schema-component/antd/table-v2/Table.tsx | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx index fd8852a60..e301467e6 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx @@ -1,4 +1,4 @@ -import { DeleteOutlined, MenuOutlined } from '@ant-design/icons'; +import { DeleteOutlined, MenuOutlined, CopyOutlined } from '@ant-design/icons'; import { TinyColor } from '@ctrl/tinycolor'; import { SortableContext, SortableContextProps, useSortable } from '@dnd-kit/sortable'; import { css } from '@emotion/css'; @@ -29,7 +29,7 @@ import { useToken } from '../__builtins__'; import { SubFormProvider } from '../association-field/hooks'; import { ColumnFieldProvider } from './components/ColumnFieldProvider'; import { extractIndex, isCollectionFieldComponent, isColumnComponent } from './utils'; -import { isNewRecord } from '../../../data-source/collection-record/isNewRecord'; +import { isNewRecord, markRecordAsNew } from '../../../data-source/collection-record/isNewRecord'; const useArrayField = (props) => { const field = useField(); @@ -118,21 +118,32 @@ const useTableColumns = (props: { showDel?: boolean; isSubTable?: boolean }) => fixed: 'right', render: (v, record, index) => { return ( - { - action(() => { - const index = dataSource.indexOf(record); - spliceArrayState(field as any, { - startIndex: index, - deleteCount: 1, + <> + { + action(() => { + field.value = field.value || []; + field.value.push(markRecordAsNew({ ...JSON.parse(JSON.stringify(record)) })); }); - field.value.splice(index, 1); - field.initialValue?.splice(index, 1); - return field.onInput(field.value); - }); - }} - /> + }} + /> + { + action(() => { + const index = dataSource.indexOf(record); + spliceArrayState(field as any, { + startIndex: index, + deleteCount: 1, + }); + field.value.splice(index, 1); + field.initialValue?.splice(index, 1); + return field.onInput(field.value); + }); + }} + /> + ); }, }); @@ -248,6 +259,7 @@ export const Table: any = observer( } = { ...others1, ...others2 } as any; const field = useArrayField(others); const columns = useTableColumns(others); + const schema = useFieldSchema(); const collection = useCollection_deprecated(); const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';