Merge pull request 'feat: 添加子表格复制功能' (#364) from feat_copyTable into @hera/dev
Reviewed-on: daoyoucloud/tachycode#364
This commit is contained in:
commit
1e9baa0f6b
@ -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<ArrayField>();
|
||||
@ -118,6 +118,23 @@ const useTableColumns = (props: { showDel?: boolean; isSubTable?: boolean }) =>
|
||||
fixed: 'right',
|
||||
render: (v, record, index) => {
|
||||
return (
|
||||
<>
|
||||
<CopyOutlined
|
||||
style={{ cursor: 'pointer', marginRight: '10px' }}
|
||||
onClick={() => {
|
||||
action(() => {
|
||||
if (!Array.isArray(field.value)) {
|
||||
field.value = [];
|
||||
}
|
||||
spliceArrayState(field as any, {
|
||||
startIndex: index + 1,
|
||||
insertCount: 1,
|
||||
});
|
||||
field.value.splice(index + 1, 0, markRecordAsNew(_.cloneDeep(record)));
|
||||
return field.onInput(field.value);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<DeleteOutlined
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
@ -133,6 +150,7 @@ const useTableColumns = (props: { showDel?: boolean; isSubTable?: boolean }) =>
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user