Commit f2b8bb43a0b9172b9ef9ced8e83bf91143a091d9
1 parent
d2c36180
fix(table): fix `getSelectRows` for treeTable
修复getSelectRows不支持树形表格子级数据的问题 fixed: #1003
Showing
2 changed files
with
14 additions
and
9 deletions
CHANGELOG.zh_CN.md
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | - 修复全屏模式下看不到子组件弹出层(popconfirm 以及 select、treeSelect 等编辑组件)的问题 | 13 | - 修复全屏模式下看不到子组件弹出层(popconfirm 以及 select、treeSelect 等编辑组件)的问题 |
14 | - 修复启用`expandRowByClick`时,点击不可展开的行可能会导致样式错误的问题 | 14 | - 修复启用`expandRowByClick`时,点击不可展开的行可能会导致样式错误的问题 |
15 | - 修复`pagination`属性动态改变不生效的问题 | 15 | - 修复`pagination`属性动态改变不生效的问题 |
16 | + - 修复`getSelectRows`不支持树形表格子级数据的问题 | ||
16 | - **Dark Theme** 黑暗主题下的配色问题修正 | 17 | - **Dark Theme** 黑暗主题下的配色问题修正 |
17 | - 修复`Tree`组件被选中节点的背景颜色 | 18 | - 修复`Tree`组件被选中节点的背景颜色 |
18 | - 修复`Alert`组件的颜色配置 | 19 | - 修复`Alert`组件的颜色配置 |
src/components/Table/src/hooks/useRowSelection.ts
1 | import { isFunction } from '/@/utils/is'; | 1 | import { isFunction } from '/@/utils/is'; |
2 | import type { BasicTableProps, TableRowSelection } from '../types/table'; | 2 | import type { BasicTableProps, TableRowSelection } from '../types/table'; |
3 | -import { computed, ref, unref, ComputedRef, Ref, toRaw, watch, nextTick } from 'vue'; | 3 | +import { computed, ComputedRef, nextTick, Ref, ref, toRaw, unref, watch } from 'vue'; |
4 | import { ROW_KEY } from '../const'; | 4 | import { ROW_KEY } from '../const'; |
5 | import { omit } from 'lodash-es'; | 5 | import { omit } from 'lodash-es'; |
6 | +import { findNodeAll } from '/@/utils/helper/treeHelper'; | ||
6 | 7 | ||
7 | export function useRowSelection( | 8 | export function useRowSelection( |
8 | propsRef: ComputedRef<BasicTableProps>, | 9 | propsRef: ComputedRef<BasicTableProps>, |
@@ -21,11 +22,12 @@ export function useRowSelection( | @@ -21,11 +22,12 @@ export function useRowSelection( | ||
21 | return { | 22 | return { |
22 | selectedRowKeys: unref(selectedRowKeysRef), | 23 | selectedRowKeys: unref(selectedRowKeysRef), |
23 | hideDefaultSelections: false, | 24 | hideDefaultSelections: false, |
24 | - onChange: (selectedRowKeys: string[], selectedRows: Recordable[]) => { | ||
25 | - selectedRowKeysRef.value = selectedRowKeys; | ||
26 | - selectedRowRef.value = selectedRows; | 25 | + onChange: (selectedRowKeys: string[]) => { |
26 | + setSelectedRowKeys(selectedRowKeys); | ||
27 | + // selectedRowKeysRef.value = selectedRowKeys; | ||
28 | + // selectedRowRef.value = selectedRows; | ||
27 | }, | 29 | }, |
28 | - ...omit(rowSelection === undefined ? {} : rowSelection, ['onChange']), | 30 | + ...omit(rowSelection, ['onChange']), |
29 | }; | 31 | }; |
30 | }); | 32 | }); |
31 | 33 | ||
@@ -64,11 +66,13 @@ export function useRowSelection( | @@ -64,11 +66,13 @@ export function useRowSelection( | ||
64 | 66 | ||
65 | function setSelectedRowKeys(rowKeys: string[]) { | 67 | function setSelectedRowKeys(rowKeys: string[]) { |
66 | selectedRowKeysRef.value = rowKeys; | 68 | selectedRowKeysRef.value = rowKeys; |
67 | - | ||
68 | - const rows = toRaw(unref(tableData)).filter((item) => | ||
69 | - rowKeys.includes(item[unref(getRowKey) as string]) | 69 | + selectedRowRef.value = findNodeAll( |
70 | + toRaw(unref(tableData)), | ||
71 | + (item) => rowKeys.includes(item[unref(getRowKey) as string]), | ||
72 | + { | ||
73 | + children: propsRef.value.childrenColumnName ?? 'children', | ||
74 | + } | ||
70 | ); | 75 | ); |
71 | - selectedRowRef.value = rows; | ||
72 | } | 76 | } |
73 | 77 | ||
74 | function setSelectedRows(rows: Recordable[]) { | 78 | function setSelectedRows(rows: Recordable[]) { |