From 6a2436fb99f15cdf662f39fd86952955fb78a9d2 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 23 Oct 2025 19:55:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(form):=20tabel=E5=A4=8D=E5=88=B6=E8=A1=8C?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form/src/table/ActionsColumn.vue | 23 +++++++++++++++++----- packages/form/src/table/useTableColumns.ts | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/form/src/table/ActionsColumn.vue b/packages/form/src/table/ActionsColumn.vue index 94a72bdc..f6976cb3 100644 --- a/packages/form/src/table/ActionsColumn.vue +++ b/packages/form/src/table/ActionsColumn.vue @@ -43,18 +43,31 @@ const props = defineProps<{ index: number; row: any; prop?: string; + sortKey?: string; }>(); const mForm = inject('mForm'); const removeHandler = (index: number) => { if (props.disabled) return; - props.model[props.name].splice(index, 1); - emit('change', props.model[props.name]); + emit('change', props.model[props.name].toSpliced(index, 1)); }; const copyHandler = (index: number) => { - props.model[props.name].push(cloneDeep(props.model[props.name][index])); + const inputs = cloneDeep(props.model[props.name][index]); + const { length } = props.model[props.name]; + if (props.sortKey && length) { + inputs[props.sortKey] = props.model[props.name][length - 1][props.sortKey] - 1; + } + + emit('change', [...props.model[props.name], inputs], { + changeRecords: [ + { + propPath: `${props.prop}.${props.model[props.name].length}`, + value: inputs, + }, + ], + }); }; // 希望支持单行可控制是否显示删除按钮,不会影响现有逻辑 @@ -63,7 +76,7 @@ const showDelete = (index: number) => { if (deleteFunc && typeof deleteFunc === 'function') { return deleteFunc(props.model[props.name], index, mForm?.values); } - return true; + return props.config.delete ?? true; }; const copyable = (index: number) => { @@ -79,6 +92,6 @@ const copyable = (index: number) => { index, }); } - return true; + return props.config.copyable ?? true; }; diff --git a/packages/form/src/table/useTableColumns.ts b/packages/form/src/table/useTableColumns.ts index d3b63880..ba975a0b 100644 --- a/packages/form/src/table/useTableColumns.ts +++ b/packages/form/src/table/useTableColumns.ts @@ -91,7 +91,7 @@ export const useTableColumns = ( props: { label: '操作', fixed: props.config.fixed === false ? undefined : 'left', - width: props.config.operateColWidth || 100, + width: props.config.operateColWidth || 112, align: 'center', }, cell: ({ row, $index }: any) => @@ -102,6 +102,7 @@ export const useTableColumns = ( config: props.config, prop: props.prop, disabled: props.disabled, + sortKey: props.sortKey, name: modelName.value, currentPage: currentPage.value, pageSize: pageSize.value,