mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
fix(table): selection-change not triggered on row click
修复selection-change事件在点击行来改变勾选时不会被触发的问题
This commit is contained in:
parent
d509e897be
commit
6f845b53bd
@ -1,6 +1,6 @@
|
||||
import { isFunction } from '/@/utils/is';
|
||||
import type { BasicTableProps, TableRowSelection } from '../types/table';
|
||||
import { computed, ref, unref, ComputedRef, Ref, toRaw, watch } from 'vue';
|
||||
import { computed, ref, unref, ComputedRef, Ref, toRaw, watch, nextTick } from 'vue';
|
||||
import { ROW_KEY } from '../const';
|
||||
import { omit } from 'lodash-es';
|
||||
|
||||
@ -24,12 +24,6 @@ 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,
|
||||
});
|
||||
},
|
||||
...omit(rowSelection === undefined ? {} : rowSelection, ['onChange']),
|
||||
};
|
||||
@ -38,7 +32,24 @@ export function useRowSelection(
|
||||
watch(
|
||||
() => unref(propsRef).rowSelection?.selectedRowKeys,
|
||||
(v: string[]) => {
|
||||
selectedRowKeysRef.value = v;
|
||||
setSelectedRowKeys(v);
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => unref(selectedRowKeysRef),
|
||||
() => {
|
||||
nextTick(() => {
|
||||
const { rowSelection } = unref(propsRef);
|
||||
if (rowSelection) {
|
||||
const { onChange } = rowSelection;
|
||||
if (onChange && isFunction(onChange)) onChange(getSelectRowKeys(), getSelectRows());
|
||||
}
|
||||
emit('selection-change', {
|
||||
keys: getSelectRowKeys(),
|
||||
rows: getSelectRows(),
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user