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

357 lines
7.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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; // 允许其他可能的类型
// 定义 getFileSuffix 函数可能返回的常见类型
type FileSuffix
= | "jpg"
| "jpeg"
| "png"
| "mp4"
| "mp3"
| "pdf"
| "doc"
| "docx"
| "xls"
| "xlsx"
| "txt"
| "zip"
| "rar"
| "tar"
| string; // 允许其他可能的类型
/**
* 计算序号
*/
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: {
/** 查找的字符串 */
str: string;
/** 查找的字符 */
char: string;
/** 第几次出现 */
num: number;
}): 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: {
/** 分页的数组 */
list: any[];
/** 当前页 */
currentPage: number | string;
/** 每页条数 */
pageSize: number | string;
}): T[];
/**
* 获取文件后缀
*/
export function getFileSuffix(name: string): FileSuffix;
/**
* 获取文件名称
*/
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?: {
/** 附件路径字段名 */
pathKey?: string;
/** 附件名称字段名 */
nameKey?: string;
/** 附件id字段名 */
idKey?: string;
},
): (T & { url: string; name: string; id: any })[];
/**
* 翻译状态
*/
export function getLabelName<T>(options: {
/** 状态 */
status: number | string;
/** 翻译的数组 */
list: any[];
/** id字段名 */
idKey?: string;
/** name字段名 */
nameKey?: string;
}): 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: {
/** 获取的数组 */
list: any[];
/** 获取的值 */
value: any[];
/** 获取的id字段名 */
idKey?: string;
}): T[];
/**
* json转换为树形结构
*/
export function listTransTree<T>(options: {
/** 需要转换的json */
json: any[];
/** id字段 */
idKey: string;
/** 父级id字段 */
parentIdKey: string;
/** 子级字段 */
childrenKey: string;
}): T[];
/**
* 将值转换为"是"/"否"显示文本
*/
export function isEmptyToWhether(
value: any,
options?: {
/** 真值时显示的文本 */
yesText?: string;
/** 假值时显示的文本 */
noText?: string;
/** 判断为真的值 */
yesValue?: string | number;
},
): 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;
/**
* base64转File对象
*/
export function base642File(base64: string, filename?: string): File;
/**
* 获取树形节点路径
*/
export function getTreeNodePaths<T extends Record<string, any> = Record<string, any>>(
options: {
/** 树形数据 */
data: any[];
/** 目标节点ID */
targetId: string | number;
/** id字段名 */
idKey: string;
/** 子节点字段名 */
childrenKey: string;
/** 路径数组 */
path?: any[];
/** 是否包含自身 */
isIncludeOneself?: boolean;
},
): T[] | null;
/**
* 根据 level 属性处理树数据,添加 isLeaf 属性控制节点是否可展开
*/
export function processTreeDataByLevel(
options: {
/** 树形数据 */
data: any[];
/** 层级限制 */
level?: number;
/** 子节点字段名 */
childrenKey: string;
/** 当前层级 */
currentLevel?: number;
},
): {
/** 是否为叶子节点 */
isLeaf: boolean;
/** 子节点 */
[key: string]: any;
}[];
/**
* 根据 onlyLastLevel 属性处理树数据,添加 selectable 属性控制节点是否可选择
*/
export function processTreeDataForOnlyLastLevel(
options: {
/** 树形数据 */
data: any[];
/** 子节点字段名 */
childrenKey: string;
/** 是否只允许选择最后一级 */
onlyLastLevel?: boolean;
},
): {
/** 是否允许选择 */
selectable: boolean;
/** 子节点 */
[key: string]: any;
}[];
/**
* 验证结束时间是否大于开始时间
*/
export function validatorEndTime(timeStart: string, message: string): {
validator: (_: any, value: any) => Promise<void | string>;
};
/**
* 验证时间是否大于等于当前时间
*/
export function validatorTimeGTCurrentDay(message: string): {
validator: (_: any, value: any) => Promise<void | string>;
};
/**
* 动态加载js资源
*/
export function dynamicLoadJs(url: string): Promise<void>;
/**
* 动态加载css资源
*/
export function dynamicLoadCss(url: string): Promise<void>;
/**
* 是否空html用于给富文本编辑器使用
*/
export function normalizeEmptyHtml(html: string): string;