Skip to content

Commit

Permalink
fix: 修复 inputTable 非最后一页点击新增出现初始值的问题 (#11386)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Dec 17, 2024
1 parent 8d96ab3 commit bb89a49
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions packages/amis/src/renderers/Form/InputTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1754,40 +1754,6 @@ export default class FormTable extends React.Component<TableProps, TableState> {
const newState = {};
const editIndex = state.editIndex;
const lastModifiedRow = state.lastModifiedRow;

if (editIndex) {
const indexes = editIndex.split('.').map(item => parseInt(item, 10));
let items = state.items.concat();
const origin = getTree(items, indexes);

if (!origin) {
return newState;
}

const value: any = {
...rows
};
const originItems = items;
items = spliceTree(items, indexes, 1, value);
this.reUseRowId(items, originItems, indexes);

Object.assign(newState, {
items,
filteredItems: state.filteredItems.map(a =>
a === origin ? value : a
),
/** 记录最近一次编辑记录,用于取消编辑数据回溯, */
...(lastModifiedRow?.index === editIndex
? {}
: {
lastModifiedRow: origin.hasOwnProperty(PLACE_HOLDER)
? undefined
: {index: editIndex, data: {...origin}}
})
});
return newState;
}

let items = state.items.concat();

if (Array.isArray(rows)) {
Expand All @@ -1803,6 +1769,43 @@ export default class FormTable extends React.Component<TableProps, TableState> {
});
} else {
rowIndexes = this.convertToRawPath(rowIndexes as string, state);

// 修改当前正在编辑的行
if (editIndex && rowIndexes === editIndex) {
const indexes = editIndex
.split('.')
.map(item => parseInt(item, 10));
let items = state.items.concat();
const origin = getTree(items, indexes);

if (!origin) {
return newState;
}

const value: any = {
...rows
};
const originItems = items;
items = spliceTree(items, indexes, 1, value);
this.reUseRowId(items, originItems, indexes);

Object.assign(newState, {
items,
filteredItems: state.filteredItems.map(a =>
a === origin ? value : a
),
/** 记录最近一次编辑记录,用于取消编辑数据回溯, */
...(lastModifiedRow?.index === editIndex
? {}
: {
lastModifiedRow: origin.hasOwnProperty(PLACE_HOLDER)
? undefined
: {index: editIndex, data: {...origin}}
})
});
return newState;
}

const indexes = (rowIndexes as string)
.split('.')
.map(item => parseInt(item, 10));
Expand Down

0 comments on commit bb89a49

Please sign in to comment.