From 167493795083bfe85fe771c3d363638b56c45393 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Fri, 26 Apr 2024 13:44:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E4=BA=BA=E5=91=98=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=87=8D=E7=BD=AE=E6=9C=AA=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=EF=BC=88selectedRowKeys.value=3D[]=EF=BC=8Cwatch=E6=B2=A1?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=88=B0=E5=8A=A0deep=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Table/src/hooks/useCustomSelection.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/components/Table/src/hooks/useCustomSelection.tsx b/src/components/Table/src/hooks/useCustomSelection.tsx index 09dce32..bb2c363 100644 --- a/src/components/Table/src/hooks/useCustomSelection.tsx +++ b/src/components/Table/src/hooks/useCustomSelection.tsx @@ -2,7 +2,7 @@ import type { BasicColumn } from '/@/components/Table'; import type { Ref, ComputedRef } from 'vue'; import type { BasicTableProps, PaginationProps, TableRowSelection } from '/@/components/Table'; import { computed, nextTick, onUnmounted, ref, toRaw, unref, watch, watchEffect } from 'vue'; -import { omit } from 'lodash-es'; +import { omit, isEqual } from 'lodash-es'; import { throttle } from 'lodash-es'; import { Checkbox, Radio } from 'ant-design-vue'; import { isFunction } from '/@/utils/is'; @@ -128,17 +128,44 @@ export function useCustomSelection( }); // 监听传入的selectedRowKeys + // update-begin--author:liaozhiyang---date:20240306---for:【QQYUN-8390】部门人员组件点击重置未清空(selectedRowKeys.value=[],watch没监听到加deep) watch( () => unref(propsRef)?.rowSelection?.selectedRowKeys, (val: string[]) => { // 解决selectedRowKeys在页面调用处使用ref失效 const value = unref(val); - if (Array.isArray(value)) { + if (Array.isArray(value) && !sameArray(value, selectedKeys.value)) { setSelectedRowKeys(value); } }, - { immediate: true } + { + immediate: true, + deep: true + } ); + // update-end--author:liaozhiyang---date:20240306---for:【QQYUN-8390】部门人员组件点击重置未清空(selectedRowKeys.value=[],watch没监听到加deep) + + /** + * 2024-03-06 + * liaozhiyang + * 判断是否同一个数组 (引用地址,长度,元素位置信息相同才是同一个数组。数组元素只有字符串) + */ + function sameArray(a, b) { + if (a === b) { + if (a.length === b.length) { + return a.toString() === b.toString(); + } else { + return false; + } + } else { + // update-begin--author:liaozhiyang---date:20240425---for:【QQYUN-9123】popupdict打开弹窗打开程序运行 + if (isEqual(a, b)) { + return true; + } + // update-end--author:liaozhiyang---date:20240425---for:【QQYUN-9123】popupdict打开弹窗打开程序运行 + return false; + } + } // 当任意一个变化时,触发同步检测 watch([selectedKeys, selectedRows], () => {