zy-react-library/utils/index.d.ts

266 lines
5.3 KiB
TypeScript

import type { BasePaginationConfig } from "../hooks/useTable";
// 定义 getDataType 函数可能返回的所有类型
type DataType
= | "String"
| "Number"
| "Boolean"
| "Symbol"
| "Undefined"
| "Null"
| "Object"
| "Array"
| "Function"
| "Date"
| "RegExp"
| "Error"
| "Map"
| "Set"
| "WeakMap"
| "WeakSet"
| "ArrayBuffer"
| "DataView"
| "Promise"
| "Generator"
| "GeneratorFunction"
| "AsyncFunction"
| "Arguments"
| "Math"
| "JSON"
| "Window"
| "HTMLDocument"
| string; // 允许其他可能的类型
// 为 findCharIndex 函数定义接口类型
interface FindCharIndexOptions {
/** 查找的字符串 */
str: string;
/** 查找的字符 */
char: string;
/** 第几次出现 */
num: number;
}
// 为 paging 函数定义接口类型
interface PagingOptions {
/** 分页的数组 */
list: any[];
/** 当前页 */
currentPage: number | string;
/** 每页条数 */
pageSize: number | string;
}
// 为 addingPrefixToFile 函数定义接口类型
interface AddingPrefixToFileOptions {
/** 附件路径字段名 */
pathKey?: string;
/** 附件名称字段名 */
nameKey?: string;
/** 附件id字段名 */
idKey?: string;
}
// 为 getLabelName 函数定义接口类型
interface GetLabelNameOptions {
/** 状态 */
status: number | string;
/** 翻译的数组 */
list: any[];
/** id字段名 */
idKey?: string;
/** name字段名 */
nameKey?: string;
}
// 为 getSelectAppointItemList 函数定义接口类型
interface GetSelectAppointItemListOptions {
/** 获取的数组 */
list: any[];
/** 获取的值 */
value: any[];
/** 获取的id字段名 */
idKey?: string;
}
// 为 listTransTree 函数定义接口类型
interface ListTransTreeOptions {
/** 需要转换的json */
json: any[];
/** id字段 */
idKey: string;
/** 父级id字段 */
parentIdKey: string;
/** 子级字段 */
childrenKey: string;
}
// 为 isEmptyToWhether 函数定义接口类型
interface IsEmptyToWhetherOptions {
/** 真值时显示的文本 */
yesText?: string;
/** 假值时显示的文本 */
noText?: string;
/** 判断为真的值 */
yesValue?: string | number;
}
/**
* 计算序号
*/
export function serialNumber(
pagination: BasePaginationConfig,
index: number
): number;
/**
* 字符串数组转数组
*/
export function toArrayString(value: string): Array<string>;
/**
* 判断文件后缀名是否符合
*/
export function interceptTheSuffix(name: string, suffix: string): boolean;
/**
* 图片转base64
*/
export function image2Base64(imgUrl: string): Promise<string>;
/**
* 图片转base64 (File对象版本)
*/
export function image2Base642(file: File): Promise<string>;
/**
* 判断图片是否可访问成功
*/
export function checkImgExists(imgUrl: string): Promise<any>;
/**
* 获取数据类型
*/
export function getDataType(data: any): DataType;
/**
* 数组去重
*/
export function ArrayDeduplication<T extends number | string>(arr: T[]): T[];
/**
* 数组对象去重
*/
export function arrayObjectDeduplication<T>(arr: T[], key: string): T[];
/**
* 查找字符串中指定的值第几次出现的位置
*/
export function findCharIndex(options: FindCharIndexOptions): number;
/**
* 生成指定两个值之间的随机数
*/
export function randoms(min: number, max: number): number;
/**
* 千位分隔符
*/
export function numFormat(num: number | string): string;
/**
* 验证是否为空
*/
export function isEmpty(value: any): boolean;
/**
* 获取url参数
*/
export function getUrlParam(key: string): string;
/**
* 数据分页
*/
export function paging<T>(options: PagingOptions): T[];
/**
* 获取文件后缀
*/
export function getFileSuffix(name: string): string;
/**
* 获取文件名称
*/
export function getFileName(name: string): string;
/**
* 读取txt文档
*/
export function readTxtDocument(filePah: string): Promise<string>;
/**
* 将秒转换成时分秒
*/
export function secondConversion(second: string | number): string;
/**
* 附件添加前缀
*/
export function addingPrefixToFile<T extends Record<string, any>>(
list: T[],
options?: AddingPrefixToFileOptions
): (T & { url: string; name: string; imgFilesId: any })[];
/**
* 翻译状态
*/
export function getLabelName<T>(options: GetLabelNameOptions): string | undefined;
/**
* 计算文件大小
*/
export function calculateFileSize(size: number | string): string;
/**
* 根据身份证号获取出生日期和性别
*/
export function idCardGetDateAndGender(idCard: string): { sex: "1" | "0"; date: string };
/**
* 获取select中指定项组成的数组
*/
export function getSelectAppointItemList<T>(options: GetSelectAppointItemListOptions): T[];
/**
* json转换为树形结构
*/
export function listTransTree<T>(options: ListTransTreeOptions): T[];
/**
* 将值转换为"是"/"否"显示文本
*/
export function isEmptyToWhether(
value: any,
options?: IsEmptyToWhetherOptions
): string;
/**
* 生成指定长度的guid
*/
export function createGuid(len?: number): string;
/**
* 获取序号列
*/
export function getIndexColumn(pagination: false | BasePaginationConfig): {
title: string;
key: string;
width: number;
render: (...args: any[]) => number;
};
/**
* 获取文件url
*/
export function getFileUrl(): string;