|
|
|
@ -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[]) { |
|
|
|
|