From 0b1c464e2c7796d7826be2f110c3f39beefa633d Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Sat, 4 Nov 2023 17:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90issues/828=E3=80=91=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=8D=A1=E6=AD=BB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Table/src/hooks/useCustomSelection.tsx | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/components/Table/src/hooks/useCustomSelection.tsx b/src/components/Table/src/hooks/useCustomSelection.tsx index 6fe3091..34480c0 100644 --- a/src/components/Table/src/hooks/useCustomSelection.tsx +++ b/src/components/Table/src/hooks/useCustomSelection.tsx @@ -432,6 +432,7 @@ export function useCustomSelection( // 设置选择的key function setSelectedRowKeys(rowKeys: string[]) { + const isSomeRowKeys = selectedKeys.value === rowKeys; selectedKeys.value = rowKeys; const allSelectedRows = findNodeAll( toRaw(unref(flattedData)).concat(toRaw(unref(selectedRows))), @@ -445,14 +446,33 @@ export function useCustomSelection( const found = allSelectedRows.find((item) => getRecordKey(item) === key); found && trueSelectedRows.push(found); }); - // update-begin--author:liaozhiyang---date:20230823---for:【QQYUN-6283】点击表格清空,rowSelect里面的selectedRowKeys没置空。 - // update-begin--author:liaozhiyang---date:20230811---for:【issues/657】浏览器卡死问题 - if (trueSelectedRows.length || !rowKeys.length) { + // update-begin--author:liaozhiyang---date:20231103---for:【issues/828】解决卡死问题 + if (!(isSomeRowKeys && equal(selectedRows.value, trueSelectedRows))) { selectedRows.value = trueSelectedRows; emitChange(); } - // update-end--author:liaozhiyang---date:20230811---for:【issues/657】】浏览器卡死问题 - // update-end--author:liaozhiyang---date:20230823---for:【QQYUN-6283】点击表格清空,rowSelect里面的selectedRowKeys没置空。 + // update-end--author:liaozhiyang---date:20231103---for:【issues/828】解决卡死问题 + } + /** + *2023-11-03 + *廖志阳 + *检测selectedRows.value和trueSelectedRows是否相等,防止死循环 + */ + function equal(oldVal, newVal) { + let oldKeys = [], + newKeys = []; + if (oldVal.length === newVal.length) { + oldKeys = oldVal.map((item) => getRecordKey(item)); + newKeys = newVal.map((item) => getRecordKey(item)); + for (let i = 0, len = oldKeys.length; i < len; i++) { + const findItem = newKeys.find((item) => item === oldKeys[i]); + if (!findItem) { + return false; + } + } + return true; + } + return false; } function getSelectRows() {