mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-11-30 14:32:09 +08:00
fix(form): tabel复制行不生效
This commit is contained in:
parent
1eeabc8220
commit
6a2436fb99
@ -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>
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user