mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-23 17:50:25 +08:00
fix(table): fix rowSelection.onChange not work
修复为table提供rowSelection.onChange时,无法手动变更table的选中项的问题 fixed: #825
This commit is contained in:
parent
99829c79ab
commit
df0f00085c
@ -1,6 +1,8 @@
|
||||
import { isFunction } from '/@/utils/is';
|
||||
import type { BasicTableProps, TableRowSelection } from '../types/table';
|
||||
import { computed, ref, unref, ComputedRef, Ref, toRaw } from 'vue';
|
||||
import { computed, ref, unref, ComputedRef, Ref, toRaw, watch } from 'vue';
|
||||
import { ROW_KEY } from '../const';
|
||||
import { omit } from 'lodash-es';
|
||||
|
||||
export function useRowSelection(
|
||||
propsRef: ComputedRef<BasicTableProps>,
|
||||
@ -22,15 +24,24 @@ export function useRowSelection(
|
||||
onChange: (selectedRowKeys: string[], selectedRows: Recordable[]) => {
|
||||
selectedRowKeysRef.value = selectedRowKeys;
|
||||
selectedRowRef.value = selectedRows;
|
||||
const { onChange } = rowSelection;
|
||||
if (onChange && isFunction(onChange)) onChange(selectedRowKeys, selectedRows);
|
||||
emit('selection-change', {
|
||||
keys: selectedRowKeys,
|
||||
rows: selectedRows,
|
||||
});
|
||||
},
|
||||
...(rowSelection === undefined ? {} : rowSelection),
|
||||
...omit(rowSelection === undefined ? {} : rowSelection, ['onChange']),
|
||||
};
|
||||
});
|
||||
|
||||
watch(
|
||||
() => unref(propsRef).rowSelection?.selectedRowKeys,
|
||||
(v: string[]) => {
|
||||
selectedRowKeysRef.value = v;
|
||||
}
|
||||
);
|
||||
|
||||
const getAutoCreateKey = computed(() => {
|
||||
return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user