feat(form,tdesign-vue-next-adapter): table 多选框放到默认的操作前面,支持配置copy的干预函数

This commit is contained in:
roymondchen 2025-12-19 20:19:55 +08:00
parent f7811fdb24
commit 5fe91e89b7
4 changed files with 28 additions and 12 deletions

View File

@ -716,6 +716,7 @@ export interface TableConfig extends FormItem {
selection?: (mForm: FormState | undefined, data: any) => boolean | boolean | 'single';
/** 新增的默认行 */
defaultAdd?: (mForm: FormState | undefined, data: any) => any;
copyHandler?: (mForm: FormState | undefined, data: any) => any;
onSelect?: (mForm: FormState | undefined, data: any) => any;
defautSort?: SortProp;
defaultSort?: SortProp;

View File

@ -63,7 +63,18 @@ const removeHandler = (index: number) => {
};
const copyHandler = (index: number) => {
const inputs = cloneDeep(props.model[props.name][index]);
let inputs = cloneDeep(props.model[props.name][index]);
if (typeof props.config.copyHandler === 'function') {
const modelName = props.name || props.config.name || '';
inputs = props.config.copyHandler(mForm, {
model: props.model[modelName],
prop: props.prop,
formValue: mForm?.values,
inputs,
});
}
const { length } = props.model[props.name];
if (props.sortKey && length) {
inputs[props.sortKey] = props.model[props.name][length - 1][props.sortKey] - 1;

View File

@ -101,6 +101,17 @@ export const useTableColumns = (
});
}
if (selection.value) {
columns.push({
props: {
align: 'center',
headerAlign: 'center',
type: 'selection',
width: 45,
},
});
}
let actionFixed: 'left' | 'right' | undefined = props.config.fixed === false ? undefined : 'left';
if (typeof props.config.fixed === 'string' && ['left', 'right'].includes(props.config.fixed)) {
@ -159,17 +170,6 @@ export const useTableColumns = (
});
}
if (selection.value) {
columns.push({
props: {
align: 'center',
headerAlign: 'center',
type: 'selection',
width: 45,
},
});
}
if (props.showIndex && props.config.showIndex) {
columns.push({
props: {

View File

@ -60,6 +60,10 @@ const tableColumns = computed(() => {
align: item.props?.align,
};
if (item.props.type === 'selection') {
column.type = 'multiple';
}
//
if (item.cell) {
column.cell = (h: any, { row, rowIndex }: any) => {