@aplus-frontend/ui
Version:
79 lines (78 loc) • 1.98 kB
TypeScript
import { Ref } from 'vue';
import { ApTableProps } from '../../ap-table';
import { Recordable } from '../../type';
import { AgGridRowSelection } from '../interface';
import { Key } from '../../ap-table/components/interface';
export interface RowSelectionReturnType<RecordType = any> {
selectedRows: Ref<Partial<RecordType>[]>;
selectedRowKeys: Ref<Key[]>;
/**
* 选中某行
* @param item
* @returns
*/
select: (item: RecordType) => void;
/**
* 取消选中某行
* @param item
* @returns
*/
unSelect: (item: RecordType) => void;
/**
* 某行是否被选中
* @param item
* @returns
*/
isSelected: (item: RecordType) => boolean;
/**
* 选中当前所有数据
* @returns
*/
selectAll: () => void;
/**
* 取消选中当前所有数据
* @returns
*/
unSelectAll: () => void;
/**
* 清空所有选中
* @returns
*/
clearAll: () => void;
/**
* 切换某行的选中状态
* @param item
* @returns
*/
toggleSelect: (item: RecordType) => void;
/**
* 多项选中
* @param items
* @returns
*/
selectMulti: (items: RecordType[]) => void;
/**
* 多项反选
* @param items
* @returns
*/
unSelectMulti: (items: RecordType[]) => void;
/**
* 通过key勾选多条数据
* @param keys
* @returns
*/
selectMultiByKeys: (keys: (string | number)[]) => void;
}
type RowSelectionParams<T> = AgGridRowSelection<T> & {
/**
* 数据源(如果是后端分页,则表示当页数据,否则是全量数据)
*/
dataSource: Ref<T[]>;
/**
* 同Table的rowkey
*/
rowKey: ApTableProps['rowKey'];
};
declare const useGridRowSelection: <RecordType extends Recordable = Recordable>(props: RowSelectionParams<RecordType>) => RowSelectionReturnType<RecordType>;
export default useGridRowSelection;