From bb89a499b506b8196c3c340b7d8421c74cc2c68a Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2698393+2betop@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:35:53 +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=20(#11386)?= 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 6190c3977a3..d5110b5a14e 100644 --- a/packages/amis/src/renderers/Form/InputTable.tsx +++ b/packages/amis/src/renderers/Form/InputTable.tsx @@ -1754,40 +1754,6 @@ export default class FormTable extends React.Component { 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)) { @@ -1803,6 +1769,43 @@ export default class FormTable extends React.Component { }); } 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));