From 9435b480abaec54151496b6f3afdaa5d1d654408 Mon Sep 17 00:00:00 2001 From: mfish Date: Thu, 15 Dec 2022 18:30:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3deleteTableRecord=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=A0=91=E5=BD=A2=E8=A1=A8=E6=A0=BC=E7=9A=84=E8=A1=8C?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=8C=E6=97=A0=E6=B3=95=E6=89=BE=E5=88=B0=E5=AD=90?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=9A=84=E9=97=AE=E9=A2=98=20(#2461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(axiosSuccess): 操作成功后根据传入提示模式进行相应 * fix(axiosRetry): 解决get重试请求返回的headers造成无法成功请求的问题 * fix(axiosRetry): 参数首字母小写 * fix(useDataSource): 解决deleteTableRecord删除树形表格的行记录时,无法删除,无法找到子节点的问题 --- .../Table/src/hooks/useDataSource.ts | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 7d6c00af..0e86e1cf 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -165,30 +165,42 @@ export function useDataSource( const rowKeyName = unref(getRowKey); if (!rowKeyName) return; const rowKeys = !Array.isArray(rowKey) ? [rowKey] : rowKey; - for (const key of rowKeys) { - let index: number | undefined = dataSourceRef.value.findIndex((row) => { - let targetKeyName: string; - if (typeof rowKeyName === 'function') { - targetKeyName = rowKeyName(row); - } else { - targetKeyName = rowKeyName as string; - } - return row[targetKeyName] === key; - }); - if (index >= 0) { - dataSourceRef.value.splice(index, 1); + + function deleteRow(data, key) { + const row: { index: number; data: [] } = findRow(data, key); + if (row === null || row.index === -1) { + return; } - index = unref(propsRef).dataSource?.findIndex((row) => { - let targetKeyName: string; - if (typeof rowKeyName === 'function') { - targetKeyName = rowKeyName(row); - } else { - targetKeyName = rowKeyName as string; + row.data.splice(row.index, 1); + + function findRow(data, key) { + if (data === null || data === undefined) { + return null; } - return row[targetKeyName] === key; - }); - if (typeof index !== 'undefined' && index !== -1) - unref(propsRef).dataSource?.splice(index, 1); + for (let i = 0; i < data.length; i++) { + const row = data[i]; + let targetKeyName: string = rowKeyName as string; + if (isFunction(rowKeyName)) { + targetKeyName = rowKeyName(row); + } + if (row[targetKeyName] === key) { + return { index: i, data }; + } + if (row.children?.length > 0) { + console.log(row.children, i); + const result = findRow(row.children, key); + if (result != null) { + return result; + } + } + } + return null; + } + } + + for (const key of rowKeys) { + deleteRow(dataSourceRef.value, key); + deleteRow(unref(propsRef).dataSource, key); } setPagination({ total: unref(propsRef).dataSource?.length, -- GitLab