UNPKG

@aplus-frontend/ui

Version:

72 lines (71 loc) 1.85 kB
import { TableRowSelection } from '@aplus-frontend/antdv/lib/table/interface'; import { ComputedRef, Ref } from 'vue'; import { ApTableProps, ApTableRowSelection } from '../interface'; import { Recordable } from '../../type'; export interface RowSelectionReturnType<RecordType = any> { rowSelection: ComputedRef<TableRowSelection<RecordType>>; selectedRows: Ref<RecordType[]>; /** * 选中某行 * @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; } type RowSelectionParams<T> = Omit<ApTableRowSelection<T>, 'mode'> & { /** * 数据源(如果是后端分页,则表示当页数据,否则是全量数据) */ dataSource: Ref<T[]>; /** * 同Table的rowkey */ rowKey: ApTableProps['rowKey']; }; declare const useTableRowSelection: <RecordType = Recordable>(props: RowSelectionParams<RecordType>) => RowSelectionReturnType<RecordType>; export default useTableRowSelection;