iv-npm
Version:
公共通用包
199 lines (181 loc) • 7.04 kB
TypeScript
export { TreeList } from '../types/index.js';
import * as vue from 'vue';
import { Component } from 'vue';
export { divide, minus, plus, round, strip, times } from 'number-precision';
declare function arrToTree(list: any[], parentMark: string, childrenMark: string): any;
interface TreeList {
parentId: string | null;
id: string;
children?: TreeList[];
}
/**
* 数组转树结构(多级)
* 根据parentId===id进行判断
*/
declare function tranListToTreeData<T extends TreeList>(list: T[]): T[];
/**
* 树结构添加属性,返回新数组。
*/
declare function addPropertyToTree<T extends {
id: string;
children?: T[];
[key: string]: any;
}>(list: T[], formatValue: (cn: T, pn?: T) => any, parentNode?: T): T[];
/**
* 树结构删除一个或者多个元素,返回新数组。
*/
declare function removeElementsWithDescendants<T extends {
id: string;
children?: T[];
[key: string]: any;
}>(list: T[], predicate: (item: T) => boolean): T[];
/**
* 树结构查询单个元素
*/
declare function findTree<T extends {
id: string;
children?: T[];
}>(id: string, list: T[], idName?: any): any;
/**
* 树结构查找多个元素。
*/
declare function findNodesByIds<T extends {
id: string;
children?: T[];
[key: string]: any;
}>(tree: T[], ids: string[], findName?: string, foundNodes?: T[]): T[];
/**
* @description 计算两个数字的百分百比
* @param {Number} complete 分子
* @param {Number} need 分母
* @return {Number} complete / need
*/
declare const formatPercentage: (complete: number, need: number) => number;
/**
* @description 计算数组之和
* @param {Number[]} number[]
* @return {Number}
*/
declare const arraySum: (arr: number[]) => number;
/**
* @description 计算数组某个字段之和
* @param {object[]} object[]
* @return {Number}
*/
declare const arraySumByKey: (arr: any[], key: string) => number;
/**
* @description 对比两个数组某个字段之和是否相同
* @param {object[]} object1[]
* @param {object[]} object2[]
* @return {Number}
*/
declare const isArraySumCompared: (arr1: any[], arr2: any[], key1: string, key2?: string) => boolean;
/**
* @description 格式化数字,增加千分位标记和保留小数
* @param {Number} num
* @param {Number} suffix 默认保留两位小数
* @return {String}
*/
declare const numFormat: (num: number, suffix?: number) => string;
/**
* 检查对象是否为普通对象(使用“{}”或“new Object”创建)
* */
declare function isPlainObject(obj: object): boolean;
/**
* 是否是一个对象
* */
declare const isObject: (val: unknown) => val is Record<any, any>;
/**
* 是否是一个时间对象
* */
declare function isDate(val: any): boolean;
/**
* 是否是一个URLSearchParams
* */
declare function isURLSearchParams(val: any): boolean;
declare const assign: {
<T extends {}, U>(target: T, source: U): T & U;
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
<T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
(target: object, ...sources: any[]): any;
};
declare function filterOptionHeadle(key: string): (input: string, option: any) => any;
declare function buildURL(url: string, params: any): string;
declare function apiConfiger(config: any): any;
declare type HostKey = "BASE_URL" | "MRP_URL" | "MRP2_URL" | "ASSET_URL" | "ASSETS_URL" | "GATEWAY_URL" | "SFM_URL" | "CCFLOW_URL" | "SHARECOOL_URL" | "PDM_URL";
declare function hostConfiger(key: HostKey): string;
declare type formatType = {
date: string;
time: string;
week: string;
};
/**
* 函数重载,根据不同参数返回不同类型
*/
declare function dateFormat(): formatType;
declare function dateFormat(data: Date | string, format: string): string;
declare function yearMonthFormat(data?: Date): string | formatType;
declare function yearMonthDayFormat(data?: Date): string | formatType;
declare function onChangeTail(item: any[]): (key: string, cb?: Function) => number;
interface MenuItem {
label: string;
onClick: () => void;
hidden?: boolean;
}
declare function useContextMenu(component: Component): {
showMenu: (event: MouseEvent, menuItems: MenuItem[]) => void;
ContextMenuWrapper: vue.DefineComponent<{}, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}, {}>;
};
declare enum ProjectStausEnum {
"待开工" = 0,
"在建" = 1,
"完工未结算" = 2,
"完工已结算" = 4,
"已销项" = 8
}
declare enum SignStatusEnum {
"待签约" = 1,
"已签约" = 2,
"已完结" = 4,
"诉讼中" = 8
}
declare enum LineIDEnum {
"tx01" = 1,
"tx02" = 2,
"tx03" = 4,
"tx04" = 8,
"tx05" = 16
}
/**
* @description 将金额转换为大写,最大九位数。不足用¥填充
* @param amount
* */
declare function getAmountByUnit(amount: number): string;
/**
* @description 将金额保留两位小数。如果包含元字,处理结果也会返回元
* @param amount
* */
declare const amountToFixed: (_v?: number | string) => string | 0;
/**
* @description 将金额加千分符并保留两位小数。如果包含元字,处理结果也会返回元
* @param amount
* */
declare const amountToThousandthFixed: (num?: number | string, fixed?: number) => string | 0;
/**
* btoa: 将字符串进行 Base64 编码。
* atob: 将 Base64 编码的数据解码为原始字符串。
* 这些函数只能处理 UTF-8 兼容的字符,如果是非 ASCII 字符,需要先进行 UTF-8 编码.
*
*/
declare function encryptionStr(data: string | null | undefined): string | null | undefined;
declare function decryptionStr(encodedData: string | null | undefined): string | null | undefined;
/**
* 正则匹配规则:
* (\d{3}) 捕获前三位不变。
* \d{4} 匹配中间的四位数字并将其替换为 ****。
* (\d{4,}) 匹配最后的四位或更多位数(如 0980 或 0980000)。
*/
declare function maskPhoneNumber(phoneNumber: string): string;
declare function maskIDCard(idCard: string): string;
declare function maskBankCard(bankCard: string): string;
export { LineIDEnum, ProjectStausEnum, SignStatusEnum, addPropertyToTree, amountToFixed, amountToThousandthFixed, apiConfiger, arrToTree, arraySum, arraySumByKey, assign, buildURL as buildUrl, dateFormat, decryptionStr, encryptionStr, filterOptionHeadle, findNodesByIds, findTree, formatPercentage, formatType, getAmountByUnit, hostConfiger, isArraySumCompared, isDate, isObject, isPlainObject, isURLSearchParams, maskBankCard, maskIDCard, maskPhoneNumber, numFormat, onChangeTail, removeElementsWithDescendants, tranListToTreeData, useContextMenu, yearMonthDayFormat, yearMonthFormat };