浏览代码

fix(table): fix `getSelectRows` for treeTable

修复getSelectRows不支持树形表格子级数据的问题

fixed: #1003
无木 3 年之前
父节点
当前提交
f2b8bb43a0
共有 2 个文件被更改,包括 14 次插入9 次删除
  1. 1 0
      CHANGELOG.zh_CN.md
  2. 13 9
      src/components/Table/src/hooks/useRowSelection.ts

+ 1 - 0
CHANGELOG.zh_CN.md

@@ -13,6 +13,7 @@
   - 修复全屏模式下看不到子组件弹出层(popconfirm 以及 select、treeSelect 等编辑组件)的问题
   - 修复启用`expandRowByClick`时,点击不可展开的行可能会导致样式错误的问题
   - 修复`pagination`属性动态改变不生效的问题
+  - 修复`getSelectRows`不支持树形表格子级数据的问题
 - **Dark Theme** 黑暗主题下的配色问题修正
   - 修复`Tree`组件被选中节点的背景颜色
   - 修复`Alert`组件的颜色配置

+ 13 - 9
src/components/Table/src/hooks/useRowSelection.ts

@@ -1,8 +1,9 @@
 import { isFunction } from '/@/utils/is';
 import type { BasicTableProps, TableRowSelection } from '../types/table';
-import { computed, ref, unref, ComputedRef, Ref, toRaw, watch, nextTick } from 'vue';
+import { computed, ComputedRef, nextTick, Ref, ref, toRaw, unref, watch } from 'vue';
 import { ROW_KEY } from '../const';
 import { omit } from 'lodash-es';
+import { findNodeAll } from '/@/utils/helper/treeHelper';
 
 export function useRowSelection(
   propsRef: ComputedRef<BasicTableProps>,
@@ -21,11 +22,12 @@ export function useRowSelection(
     return {
       selectedRowKeys: unref(selectedRowKeysRef),
       hideDefaultSelections: false,
-      onChange: (selectedRowKeys: string[], selectedRows: Recordable[]) => {
-        selectedRowKeysRef.value = selectedRowKeys;
-        selectedRowRef.value = selectedRows;
+      onChange: (selectedRowKeys: string[]) => {
+        setSelectedRowKeys(selectedRowKeys);
+        // selectedRowKeysRef.value = selectedRowKeys;
+        // selectedRowRef.value = selectedRows;
       },
-      ...omit(rowSelection === undefined ? {} : rowSelection, ['onChange']),
+      ...omit(rowSelection, ['onChange']),
     };
   });
 
@@ -64,11 +66,13 @@ export function useRowSelection(
 
   function setSelectedRowKeys(rowKeys: string[]) {
     selectedRowKeysRef.value = rowKeys;
-
-    const rows = toRaw(unref(tableData)).filter((item) =>
-      rowKeys.includes(item[unref(getRowKey) as string])
+    selectedRowRef.value = findNodeAll(
+      toRaw(unref(tableData)),
+      (item) => rowKeys.includes(item[unref(getRowKey) as string]),
+      {
+        children: propsRef.value.childrenColumnName ?? 'children',
+      }
     );
-    selectedRowRef.value = rows;
   }
 
   function setSelectedRows(rows: Recordable[]) {