fix(form): tabel复制行不生效

This commit is contained in:
roymondchen 2025-10-23 19:55:52 +08:00
parent 1eeabc8220
commit 6a2436fb99
2 changed files with 20 additions and 6 deletions

View File

@ -43,18 +43,31 @@ const props = defineProps<{
index: number;
row: any;
prop?: string;
sortKey?: string;
}>();
const mForm = inject<FormState | undefined>('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;
};
</script>

View File

@ -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,