dz-hooks
Version:
Vue3的实用Hooks集合
108 lines (96 loc) • 2.58 kB
TypeScript
export { useRequest, useRequestProvider } from 'vue-request';
import { Ref } from 'vue';
declare type Value = string | number | Date;
interface Options {
format?: string;
method?: 'format' | 'millisecond' | 'second' | 'minute' | 'hour' | 'date' | 'day' | 'month' | 'year';
methodParam?: number;
}
declare function useDate(value?: Value | undefined, options?: Options): {
readonly data: any;
refresh: (refreshValue?: Value) => void;
};
/**
* 处理防抖值
* @param value
* @param delay
* @returns
*/
declare const useDebounce: <T>(value: any, delay?: number | undefined) => any;
declare type Fn = (...[]: any[]) => any;
/**
* 处理防抖函数
* @param fn
* @param delay
* @returns
*/
declare const useDebounceFn: (fn: Fn, delay?: number | undefined) => {
run: () => void;
};
/**
* 处理防抖值
* @param value
* @param delay
* @returns
*/
declare const useThrottle: <T>(value: any, delay?: number | undefined) => any;
/**
* 处理节流函数
* @param fn
* @param delay
* @returns
*/
declare const useThrottleFn: (fn: Fn, delay?: number | undefined) => {
run: () => void;
};
interface Actions {
toggle: () => void;
setTrue: () => void;
setFalse: () => void;
}
declare function useBoolean(value?: boolean): [Ref<boolean>, Actions];
declare function useModalFn(): {
editId: any;
visible: any;
openModal: (id: any) => void;
closeModal: () => void;
onCancel: (fn: Function) => Promise<void>;
onOk: (fn: Function) => Promise<void>;
};
interface OptionsType extends PageType {
listKey?: string;
pageNumSendKey?: string;
pageSizeSendKey?: string;
pageNumKey?: string;
pageSizeKey?: string;
totalKey?: string;
requestList: Function;
defaultParams?: object;
}
interface PageType {
pageNum: number;
pageSize: number;
}
declare const usePagination: (options: OptionsType) => {
pageNum: any;
pageSize: any;
total: any;
onCurrentChange: (page: number) => void;
onSizeChange: (size: number) => void;
fetchData: () => void;
pageDatas: any;
};
interface UseFormTableOptionsType extends OptionsType {
formRef: Ref;
}
declare const useFormTable: (options: UseFormTableOptionsType) => {
pageNum: any;
pageSize: any;
total: any;
reset: () => void;
onCurrentChange: (page: number) => void;
onSizeChange: (size: number) => void;
fetchData: () => void;
pageDatas: any;
};
export { useBoolean, useDate, useDebounce, useDebounceFn, useFormTable, useModalFn, usePagination, useThrottle, useThrottleFn };