Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: 修复 inputTable 非最后一页点击上传并且列中有图片上传时出现新行有初始值的问题 #11386

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1756,40 +1756,6 @@ export default class FormTable<
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 @@ -1805,6 +1771,43 @@ export default class FormTable<
});
} 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
Loading