feat: 添加子表格复制功能

This commit is contained in:
wjh 2024-03-13 17:52:32 +08:00
parent 5a7c78d791
commit aa8ac55c28

View File

@ -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 { TinyColor } from '@ctrl/tinycolor';
import { SortableContext, SortableContextProps, useSortable } from '@dnd-kit/sortable'; import { SortableContext, SortableContextProps, useSortable } from '@dnd-kit/sortable';
import { css } from '@emotion/css'; import { css } from '@emotion/css';
@ -29,7 +29,7 @@ import { useToken } from '../__builtins__';
import { SubFormProvider } from '../association-field/hooks'; import { SubFormProvider } from '../association-field/hooks';
import { ColumnFieldProvider } from './components/ColumnFieldProvider'; import { ColumnFieldProvider } from './components/ColumnFieldProvider';
import { extractIndex, isCollectionFieldComponent, isColumnComponent } from './utils'; 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 useArrayField = (props) => {
const field = useField<ArrayField>(); const field = useField<ArrayField>();
@ -118,21 +118,32 @@ const useTableColumns = (props: { showDel?: boolean; isSubTable?: boolean }) =>
fixed: 'right', fixed: 'right',
render: (v, record, index) => { render: (v, record, index) => {
return ( return (
<DeleteOutlined <>
style={{ cursor: 'pointer' }} <CopyOutlined
onClick={() => { style={{ cursor: 'pointer', marginRight: '10px' }}
action(() => { onClick={() => {
const index = dataSource.indexOf(record); action(() => {
spliceArrayState(field as any, { field.value = field.value || [];
startIndex: index, field.value.push(markRecordAsNew({ ...JSON.parse(JSON.stringify(record)) }));
deleteCount: 1,
}); });
field.value.splice(index, 1); }}
field.initialValue?.splice(index, 1); />
return field.onInput(field.value); <DeleteOutlined
}); style={{ cursor: 'pointer' }}
}} onClick={() => {
/> 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; } = { ...others1, ...others2 } as any;
const field = useArrayField(others); const field = useArrayField(others);
const columns = useTableColumns(others); const columns = useTableColumns(others);
const schema = useFieldSchema(); const schema = useFieldSchema();
const collection = useCollection_deprecated(); const collection = useCollection_deprecated();
const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider'; const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';