@aplus-frontend/ui
Version:
117 lines (116 loc) • 4.68 kB
TypeScript
import { DataIndex } from '@aplus-frontend/antdv/es/vc-table/interface';
import { Ref, ComputedRef } from 'vue';
import { ApTablePaginationConfig, RequestData } from '../interface';
import { Recordable } from '../../type';
import { ApFormSearchFormExpose } from '../../ap-form';
import { TablePaginationConfig } from '@aplus-frontend/antdv';
import { FilterValue, SorterResult, TableCurrentDataSource } from '@aplus-frontend/antdv/es/table/interface';
import { ApColumnType } from '..';
export type UseTablePagingParams<DataType, ParamsType> = {
request: (params: any) => Promise<RequestData<DataType>>;
/**
* 是否手动执行,页面初始化后不执行网络请求,需要手动触发
* @param params
* @returns
*/
manual?: boolean;
/**
* 额外的请求参数
* @description 如果传入响应式数据,将会在数据改变后重新请求
*/
params?: ParamsType | Ref<ParamsType>;
/**
* 默认的数据源(只生效一次)
*/
defaultData?: DataType[];
/**
* 数据请求前格式化请求参数
* @param values
* @returns
*/
formatParams?: (values: any) => any;
/**
* 特殊类型参数类型对照表(会根据该对照表运行默认的参数格式化)
*/
paramsValueTypeMap?: Record<string, any>;
/**
* 重设表单需要忽略的字段
*/
resetFieldsIgnores?: string[];
/**
* 需要后端筛选的字段列表
*/
filterFields?: Ref<DataIndex[]>;
/**
* 需要后端筛选的排序字段列表
*/
sortFields?: Ref<DataIndex[]>;
/**
* 分页相关
*/
pagination?: boolean | ApTablePaginationConfig;
/**
* 样式命名空间
*/
namespace?: 'ap-table' | 'ap-grid';
/**
* 当点击重置时的回调
* @returns
*/
onClickReset?: () => void;
/**
* 当请求结束后触发的事件
* @returns
*/
onAfterRequest?: (records: DataType[]) => void;
};
export type InternalPagingType = Partial<{
current: number;
pageSize: number;
}>;
type InternalDataType<DataType = Recordable> = {
total: number;
records: DataType[];
loading: boolean;
};
export declare const DEFAULT_CURRENT = 1;
export declare const DEFAULT_PAGE_SIZE = 20;
export type OptionalOnTableChange<T extends (...args: any[]) => any> = (...args: Partial<Parameters<T>>) => ReturnType<T>;
export declare const useTablePaging: <DataType = any, ParamsType = Record<string, any>>({ manual, request, params, defaultData, formatParams, paramsValueTypeMap, resetFieldsIgnores, filterFields, sortFields, namespace, pagination, onClickReset, onAfterRequest }: UseTablePagingParams<DataType, ParamsType>) => {
formRef: Ref<ApFormSearchFormExpose | undefined, ApFormSearchFormExpose | undefined>;
submit: () => void;
reset: () => void;
refresh: () => void;
refreshByDelete: (n: number) => void;
data: InternalDataType<DataType>;
handleTableChange: (pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<any> | SorterResult<any>[], extra: TableCurrentDataSource<any>) => void;
handleTableChangeOptional: OptionalOnTableChange<(pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<any> | SorterResult<any>[], extra: TableCurrentDataSource<any>) => void>;
tableProps: ComputedRef<{
loading: boolean;
pagination: {
current: number;
pageSize: number;
total: number;
showSizeChanger: NonNullable<boolean | undefined>;
showQuickJumper: NonNullable<boolean | undefined>;
showLessItems: boolean | undefined;
size: "default" | "small";
pageSizeOptions: (string | number)[];
showTotal: ((total: number) => import("vue/jsx-runtime").JSX.Element) | undefined;
};
onChange: (pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<any> | SorterResult<any>[], extra: TableCurrentDataSource<any>) => void;
dataSource: DataType[];
}>;
dataSource: ComputedRef<DataType[]>;
setDataSource: (dataSource?: DataType[]) => void;
getColumnSFConfig: (column: ApColumnType, append?: boolean) => Recordable;
sortedInfo: Ref<any, any>;
filteredInfo: Ref<any, any>;
getPaging: () => {
current?: number | undefined;
pageSize?: number | undefined;
};
setPaging: (nextPaging: InternalPagingType, refreshImmediately?: boolean) => void;
submitWith: (resetCurrent?: boolean) => void;
};
export {};