From 3410454b5951154fe4de0d9e7ddb8d4e0079d2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9D=A4?= <1514100951@qq.com> Date: Tue, 20 Feb 2024 02:13:14 +0000 Subject: [PATCH] =?UTF-8?q?update=20src/components/Table/src/hooks/useRowS?= =?UTF-8?q?election.ts.=20=E8=A1=A8=E6=A0=BC=20rowKey=20=E4=B8=BA=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=97=B6,=E8=8E=B7=E5=8F=96getSelectRows?= =?UTF-8?q?=E4=B8=BA=E7=A9=BAbug,=20=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=ADro?= =?UTF-8?q?wkey=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李坤 <1514100951@qq.com> --- .../Table/src/hooks/useRowSelection.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/Table/src/hooks/useRowSelection.ts b/src/components/Table/src/hooks/useRowSelection.ts index dfd4b6e..ddb72d0 100644 --- a/src/components/Table/src/hooks/useRowSelection.ts +++ b/src/components/Table/src/hooks/useRowSelection.ts @@ -71,18 +71,31 @@ export function useRowSelection( return unref(getAutoCreateKey) ? ROW_KEY : rowKey; }); + function getKey(record: Recordable) { + const rowKey = unref(getRowKey); + + if (isString(rowKey)) { + return record[rowKey]; + } + + if (isFunction(rowKey)) { + return rowKey(record, null); + } + return null; + } + function setSelectedRowKeys(rowKeys: string[] | number[]) { selectedRowKeysRef.value = rowKeys; const allSelectedRows = findNodeAll( toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))), - (item) => rowKeys.includes(item[unref(getRowKey) as string] as never), + (item) => rowKeys.includes(getKey(item)), { children: propsRef.value.childrenColumnName ?? 'children', }, ); const trueSelectedRows: any[] = []; rowKeys.forEach((key: string | number) => { - const found = allSelectedRows.find((item) => item[unref(getRowKey) as string] === key); + const found = allSelectedRows.find((item) => getKey(item) === key); found && trueSelectedRows.push(found); }); selectedRowRef.value = trueSelectedRows; -- Gitee