From a8a898971a07681d358456392991d20993fac573 Mon Sep 17 00:00:00 2001 From: 2betop <2698393+2betop@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:19:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20inputTable=20?= =?UTF-8?q?=E9=9D=9E=E6=9C=80=E5=90=8E=E4=B8=80=E9=A1=B5=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=87=BA=E7=8E=B0=E5=88=9D=E5=A7=8B=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis/src/renderers/Form/InputTable.tsx | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/amis/src/renderers/Form/InputTable.tsx b/packages/amis/src/renderers/Form/InputTable.tsx index 46d2b5e0462..0f8d3d9d5a2 100644 --- a/packages/amis/src/renderers/Form/InputTable.tsx +++ b/packages/amis/src/renderers/Form/InputTable.tsx @@ -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)) { @@ -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));