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; index: number;
row: any; row: any;
prop?: string; prop?: string;
sortKey?: string;
}>(); }>();
const mForm = inject<FormState | undefined>('mForm'); const mForm = inject<FormState | undefined>('mForm');
const removeHandler = (index: number) => { const removeHandler = (index: number) => {
if (props.disabled) return; if (props.disabled) return;
props.model[props.name].splice(index, 1); emit('change', props.model[props.name].toSpliced(index, 1));
emit('change', props.model[props.name]);
}; };
const copyHandler = (index: number) => { 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') { if (deleteFunc && typeof deleteFunc === 'function') {
return deleteFunc(props.model[props.name], index, mForm?.values); return deleteFunc(props.model[props.name], index, mForm?.values);
} }
return true; return props.config.delete ?? true;
}; };
const copyable = (index: number) => { const copyable = (index: number) => {
@ -79,6 +92,6 @@ const copyable = (index: number) => {
index, index,
}); });
} }
return true; return props.config.copyable ?? true;
}; };
</script> </script>

View File

@ -91,7 +91,7 @@ export const useTableColumns = (
props: { props: {
label: '操作', label: '操作',
fixed: props.config.fixed === false ? undefined : 'left', fixed: props.config.fixed === false ? undefined : 'left',
width: props.config.operateColWidth || 100, width: props.config.operateColWidth || 112,
align: 'center', align: 'center',
}, },
cell: ({ row, $index }: any) => cell: ({ row, $index }: any) =>
@ -102,6 +102,7 @@ export const useTableColumns = (
config: props.config, config: props.config,
prop: props.prop, prop: props.prop,
disabled: props.disabled, disabled: props.disabled,
sortKey: props.sortKey,
name: modelName.value, name: modelName.value,
currentPage: currentPage.value, currentPage: currentPage.value,
pageSize: pageSize.value, pageSize: pageSize.value,