zzz-pc-view 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +29 -0
- package/src/api/org/list +96 -0
- package/src/api/org/type/list +18 -0
- package/src/api/own +3831 -0
- package/src/decorators/CurdKey/CurdApi.d.ts +221 -0
- package/src/decorators/CurdKey/RequestUtil.d.ts +55 -0
- package/src/decorators/CurdKey/index.d.ts +752 -0
- package/src/decorators/DeclareType.d.ts +35 -0
- package/src/decorators/Decorators.d.ts +5 -0
- package/src/decorators/FilterKey/index.d.ts +283 -0
- package/src/decorators/Loader/index.d.ts +179 -0
- package/src/decorators/NameKey/index.d.ts +68 -0
- package/src/decorators/PrimaryKey/index.d.ts +68 -0
- package/src/decorators/api.d.ts +21 -0
- package/src/decorators/decoratorStoreUtil.d.ts +68 -0
- package/src/decorators/index.d.ts +6 -0
- package/src/decorators/loadStore.d.ts +6 -0
- package/src/decorators/loadUtil.d.ts +25 -0
- package/src/decorators/util.d.ts +27 -0
- package/src/favicon.ico +0 -0
- package/src/index-decorators.d.ts +3 -0
- package/src/index.d.ts +10 -0
- package/src/index.es.js +10035 -0
- package/src/index.umd.js +2 -0
- package/src/pcViews/components/curd/CurdTableView.vue.d.ts +18 -0
- package/src/pcViews/components/curd/CurdView.vue.d.ts +22 -0
- package/src/pcViews/components/curd/CurdViewHandler.d.ts +1208 -0
- package/src/pcViews/components/curd/FilterView.vue.d.ts +19 -0
- package/src/pcViews/components/curd/FilterViewHandler.d.ts +6 -0
- package/src/pcViews/components/curd/index.d.ts +2 -0
- package/src/pcViews/components/forms/RadioButtonGroupView.vue.d.ts +19 -0
- package/src/pcViews/components/forms/SelectView.vue.d.ts +19 -0
- package/src/pcViews/components/forms/VModelView.vue.d.ts +20 -0
- package/src/pcViews/components/forms/index.d.ts +3 -0
- package/src/pcViews/components/index.d.ts +5 -0
- package/src/pcViews/components/layout/DataWrapperView.vue.d.ts +23 -0
- package/src/pcViews/components/layout/LayoutHeader.vue.d.ts +2 -0
- package/src/pcViews/components/layout/LayoutMainView.vue.d.ts +2 -0
- package/src/pcViews/components/layout/index.d.ts +2 -0
- package/src/pcViews/components/slots/VSlotView.vue.d.ts +20 -0
- package/src/pcViews/components/slots/index.d.ts +1 -0
- package/src/pcViews/components/utils.d.ts +33 -0
- package/src/pcViews/index.d.ts +1 -0
- package/src/utils/Date/ZDate.d.ts +557 -0
- package/src/utils/DeclareType.d.ts +39 -0
- package/src/utils/class/bind.d.ts +43 -0
- package/src/utils/class/combine.d.ts +109 -0
- package/src/utils/crypto/index.d.ts +44 -0
- package/src/utils/empty/index.d.ts +18 -0
- package/src/utils/httpRequest/HttpRequestError.d.ts +14 -0
- package/src/utils/httpRequest/httpRequestCreator.d.ts +61 -0
- package/src/utils/httpRequest/httpRequestUtil.d.ts +24 -0
- package/src/utils/httpRequest/index.d.ts +3 -0
- package/src/utils/index.d.ts +11 -0
- package/src/utils/math/toFixed.d.ts +11 -0
- package/src/utils/math/unitConvertor.d.ts +34 -0
- package/src/utils/mock/HttpResponse.d.ts +30 -0
- package/src/utils/mock/createDataTimes.d.ts +20 -0
- package/src/utils/mock/index.d.ts +2 -0
- package/src/utils/reduce/completeByDate.d.ts +51 -0
- package/src/utils/reduce/index.d.ts +9 -0
- package/src/utils/reduce/mappingBuilder.d.ts +69 -0
- package/src/utils/reduce/ratio.d.ts +104 -0
- package/src/utils/reduce/sort.d.ts +12 -0
- package/src/utils/reduce/sumByGroup.d.ts +53 -0
- package/src/utils/reduce/toGroup.d.ts +79 -0
- package/src/utils/reduce/tree.d.ts +570 -0
- package/src/utils/reduce/util.d.ts +14 -0
- package/src/utils/reduce/valueConvertor.d.ts +65 -0
- package/src/utils/reduce/verticalToHorizontal.d.ts +80 -0
- package/src/zzz-frame.css +7 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ClassType } from '../DeclareType';
|
|
2
|
+
/**
|
|
3
|
+
* 定义一个类型别名 `IntersectionOf`,用于计算类型数组 `T` 中所有类型的交集。
|
|
4
|
+
* 如果 `T` 是一个单元素数组 `[Class]`,则返回 `Class`。
|
|
5
|
+
* 如果 `T` 是一个多元素数组 `[First, ...Intermediate]`,则返回 `First` 与 `IntersectionOf<Intermediate>` 的交集。
|
|
6
|
+
* 否则返回 `unknown`。
|
|
7
|
+
*/
|
|
8
|
+
type IntersectionOf<T> = T extends [infer Class] ? Class : T extends [infer First, ...infer Intermediate] ? First & IntersectionOf<Intermediate> : unknown;
|
|
9
|
+
/**
|
|
10
|
+
* 定义一个类型别名 `CombineConstructorParams`,用于获取类型数组 `T` 中每个类的构造函数参数类型。
|
|
11
|
+
* 返回一个对象类型,其键为 `T` 中每个类的索引,值为该类的构造函数参数类型数组。
|
|
12
|
+
*/
|
|
13
|
+
type CombineConstructorParams<T extends ClassType[]> = {
|
|
14
|
+
[K in keyof T]: ConstructorParameters<T[K]>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 定义一个类型别名 `CombineInstance`,用于获取类型数组 `T` 中每个类的实例类型。
|
|
18
|
+
* 返回一个对象类型,其键为 `T` 中每个类的索引,值为该类的实例类型。
|
|
19
|
+
*/
|
|
20
|
+
type CombineInstance<T extends ClassType[]> = {
|
|
21
|
+
[K in keyof T]: InstanceType<T[K]>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 定义一个类型别名 `CombineClassType`,用于描述组合类的类型。
|
|
25
|
+
* 组合类的构造函数接受 `CombineConstructorParams<T>` 作为参数,并返回 `IntersectionOf<CombineInstance<T>>` 类型的实例。
|
|
26
|
+
* 组合类还包含一个静态属性 `InstanceType`,其类型为 `IntersectionOf<CombineInstance<T>>`。
|
|
27
|
+
* 此外,组合类还继承了 `IntersectionOf<T>` 中的所有属性和方法。
|
|
28
|
+
*/
|
|
29
|
+
type CombineClassType<T extends ClassType[]> = {
|
|
30
|
+
new (...args: CombineConstructorParams<T>): IntersectionOf<CombineInstance<T>>;
|
|
31
|
+
InstanceType: IntersectionOf<CombineInstance<T>>;
|
|
32
|
+
} & IntersectionOf<T>;
|
|
33
|
+
/**
|
|
34
|
+
* 定义一个接口 `CombineClass`,用于描述组合类的基本结构。
|
|
35
|
+
* 组合类的构造函数接受任意数量的参数并返回任意类型的值。
|
|
36
|
+
* 组合类还包含一个可选的静态属性 `InstanceType`,其类型为任意类型。
|
|
37
|
+
*/
|
|
38
|
+
export interface CombineClass {
|
|
39
|
+
new (...args: any): any;
|
|
40
|
+
InstanceType?: any;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 定义一个类型别名 `CombineInstanceType`,用于获取组合类 `T` 的实例类型。
|
|
44
|
+
* 如果 `T` 包含一个名为 `InstanceType` 的静态属性,则返回该属性的类型。
|
|
45
|
+
* 否则返回 `T` 的实例类型。
|
|
46
|
+
* @template T - 组合类的类型。
|
|
47
|
+
*/
|
|
48
|
+
export type CombineInstanceType<T extends CombineClass> = {
|
|
49
|
+
[K in keyof T]: K extends 'InstanceType' ? T[K] : never;
|
|
50
|
+
}[keyof T] extends never ? InstanceType<T> : T['InstanceType'];
|
|
51
|
+
/**
|
|
52
|
+
* 定义一个类型别名 `CombinedClassType`,用于描述组合类的类型。
|
|
53
|
+
* 组合类的构造函数接受任意数量的参数,并返回 `CombineInstanceType<T>` 类型的实例。
|
|
54
|
+
* @template T - 组合类的类型。
|
|
55
|
+
*/
|
|
56
|
+
export type CombinedClassType<T extends CombineClass> = {
|
|
57
|
+
new (...args: any): CombineInstanceType<T>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 组合多个类的函数。
|
|
61
|
+
*
|
|
62
|
+
* 该函数接受一个或多个类作为参数,并返回一个新的组合类。
|
|
63
|
+
* 组合类的实例将具有所有输入类的属性和方法。
|
|
64
|
+
*
|
|
65
|
+
* @template T - 输入类的数组类型。
|
|
66
|
+
* @param {...T} Classes - 要组合的类。
|
|
67
|
+
* @example
|
|
68
|
+
combine(
|
|
69
|
+
class A {
|
|
70
|
+
constructor(public a: number) {}
|
|
71
|
+
|
|
72
|
+
get aa() {
|
|
73
|
+
return this.a + 1
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static a = 2
|
|
77
|
+
},
|
|
78
|
+
class B {
|
|
79
|
+
constructor(public b: string) {}
|
|
80
|
+
|
|
81
|
+
get bb() {
|
|
82
|
+
return this.b + '!!'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static b = 'b'
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
* @returns
|
|
89
|
+
class {
|
|
90
|
+
a: number
|
|
91
|
+
get aa() {
|
|
92
|
+
return this.a + 1
|
|
93
|
+
}
|
|
94
|
+
static a = 2
|
|
95
|
+
|
|
96
|
+
b: string
|
|
97
|
+
get bb() {
|
|
98
|
+
return this.b + '!!'
|
|
99
|
+
}
|
|
100
|
+
static b = 'b'
|
|
101
|
+
|
|
102
|
+
constructor(AClassConstructorParams: [number], BClassConstructorParams: [string]) {
|
|
103
|
+
this.a = AClassConstructorParams[0]
|
|
104
|
+
this.b = BClassConstructorParams[0]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
*/
|
|
108
|
+
export declare const combine: <T extends ClassType[]>(...Classes: T) => CombineClassType<T>;
|
|
109
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 使用 DES 算法加密字符串
|
|
3
|
+
*
|
|
4
|
+
* @param {string} secretKey - 用于加密的密钥
|
|
5
|
+
* @param {string} str - 需要加密的字符串
|
|
6
|
+
* @returns {string} - 加密后的字符串
|
|
7
|
+
*
|
|
8
|
+
* @example encrypt('abcdefg', 'Good Day')
|
|
9
|
+
* // 输出: 'mogppK+YrC+iXpgns4wXHg=='
|
|
10
|
+
*/
|
|
11
|
+
export declare const encrypt: (secretKey: string, str: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* 使用 DES 算法解密字符串
|
|
14
|
+
*
|
|
15
|
+
* @param {string} secretKey - 用于解密的密钥
|
|
16
|
+
* @param {string} str - 需要解密的字符串
|
|
17
|
+
* @returns {string} - 解密后的字符串
|
|
18
|
+
*
|
|
19
|
+
* @example decrypt('abcdefg', 'mogppK+YrC+iXpgns4wXHg==')
|
|
20
|
+
* // 输出: 'Good Day'
|
|
21
|
+
*/
|
|
22
|
+
export declare const decrypt: (secretKey: string, str: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* 将对象转换为 URL 查询字符串
|
|
25
|
+
*
|
|
26
|
+
* @param {any} query - 需要转换的对象
|
|
27
|
+
* @param {string} prefix - 查询字符串的前缀,默认为 '?'
|
|
28
|
+
* @returns {string} - 转换后的 URL 查询字符串
|
|
29
|
+
*
|
|
30
|
+
* @example stringify({ name: 'John', age: 30 })
|
|
31
|
+
* // 输出: '?name=John&age=30'
|
|
32
|
+
*/
|
|
33
|
+
export declare const stringify: (query: any, prefix?: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* 将 URL 查询字符串解析为对象
|
|
36
|
+
*
|
|
37
|
+
* @param {string} queryString - 需要解析的 URL 查询字符串
|
|
38
|
+
* @param {string} prefix - 查询字符串的前缀,默认为 '?'
|
|
39
|
+
* @returns {unknown} - 解析后的对象
|
|
40
|
+
*
|
|
41
|
+
* @example parse('?name=John&age=30')
|
|
42
|
+
* // 输出: { name: 'John', age: 30 }
|
|
43
|
+
*/
|
|
44
|
+
export declare const parse: (queryString: string, prefix?: string) => unknown;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 定义一个空函数,用于作为默认的回调函数。
|
|
3
|
+
* 这个函数不执行任何操作,用于在没有提供回调函数时作为默认值。
|
|
4
|
+
* @returns {void} - 不返回任何值。
|
|
5
|
+
*/
|
|
6
|
+
export declare const fn: () => void;
|
|
7
|
+
/**
|
|
8
|
+
* 定义一个空对象,用于作为默认的对象值。
|
|
9
|
+
* 这个对象不包含任何属性,用于在没有提供对象时作为默认值。
|
|
10
|
+
* @type {Object} - 返回一个空对象。
|
|
11
|
+
*/
|
|
12
|
+
export declare const object: {};
|
|
13
|
+
/**
|
|
14
|
+
* 定义一个空数组,用于作为默认的数组值。
|
|
15
|
+
* 这个数组不包含任何元素,用于在没有提供数组时作为默认值。
|
|
16
|
+
* @type {Array} - 返回一个空数组。
|
|
17
|
+
*/
|
|
18
|
+
export declare const list: never[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 定义一个自定义错误类 `HttpRequestError`,它继承自 `Error` 类。
|
|
3
|
+
* 这个类用于表示 HTTP 请求过程中发生的错误。
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpRequestError extends Error {
|
|
6
|
+
code: string | number;
|
|
7
|
+
/**
|
|
8
|
+
* 构造函数,用于创建 `HttpRequestError` 类的实例。
|
|
9
|
+
*
|
|
10
|
+
* @param code - 错误码,可以是字符串或数字类型。
|
|
11
|
+
* @param msg - 错误消息,描述错误的详细信息。
|
|
12
|
+
*/
|
|
13
|
+
constructor(code: string | number, msg: string);
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AxiosRequestConfig, CancelTokenSource, CreateAxiosDefaults, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { HttpRequestError } from './HttpRequestError';
|
|
3
|
+
/**
|
|
4
|
+
* 定义一个接口HttpRequestPromise,它继承自Promise,并包含一个ajaxSource属性,类型为CancelTokenSource。
|
|
5
|
+
* 这个接口通常用于表示一个HTTP请求的Promise对象,并且可以通过ajaxSource属性取消请求。
|
|
6
|
+
*/
|
|
7
|
+
export interface HttpRequestPromise<T = any> extends Promise<T> {
|
|
8
|
+
ajaxSource: CancelTokenSource;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 定义一个接口HttpRequestLoader,它是一个泛型函数,接受一个AxiosRequestConfig类型的参数,并返回一个HttpRequestPromise类型的对象。
|
|
12
|
+
* 这个接口通常用于表示一个HTTP请求的加载器,它可以发送请求并返回一个Promise对象。
|
|
13
|
+
*/
|
|
14
|
+
export interface HttpRequestLoader {
|
|
15
|
+
<T>(config: AxiosRequestConfig): HttpRequestPromise<T>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 定义一个常量TIME_OUT_CODE,它的值为'TIME_OUT',用于表示请求超时的错误码。
|
|
19
|
+
*/
|
|
20
|
+
export declare const ABORTED_CODE = "ABORTED";
|
|
21
|
+
/**
|
|
22
|
+
* 定义一个函数create,它接受一个包含多个属性的对象作为参数,并返回一个HttpRequestLoader类型的函数。
|
|
23
|
+
* 这个函数通常用于创建一个HTTP请求的加载器,它可以根据传入的参数配置axios实例,并处理请求和响应。
|
|
24
|
+
*
|
|
25
|
+
* @param option - 包含多个属性的对象,用于配置axios实例和处理请求和响应。
|
|
26
|
+
* @param option.options 创建axio时的参数
|
|
27
|
+
* @param option.errorDataCode 异常的数据的错误码
|
|
28
|
+
* @param option.requestIntercept 请求栏截器,可选
|
|
29
|
+
* @param option.errorHandler 错误处理回调方法,可选
|
|
30
|
+
* @param option.dataCodeProp 返回数据中的code的属性名,可选,默认为code
|
|
31
|
+
* @param option.dataSuccessCodeRanges 返回数据中的code的正常值的范围的数组,可选,数组中出现[number, number],则code的值判断为在这两个数中间(大于等于和小于等于的关系),如果出现number或string类型,则为等于关系,出现多个则视为或的关系,只要有一个满足则为true
|
|
32
|
+
* @param option.dataMsgProp 返回数据中的message的属性名,可选,默认为msg
|
|
33
|
+
* @param option.dataDataProp 返回数据中的data的属性名,可选,默认为data
|
|
34
|
+
* @returns 一个HttpRequestLoader类型的函数,用于发送HTTP请求。
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
create(
|
|
38
|
+
{
|
|
39
|
+
axiosOptions: {
|
|
40
|
+
baseURL: '/api'
|
|
41
|
+
},
|
|
42
|
+
errorDataCode: 500,
|
|
43
|
+
requestIntercept: (requestConfig) => requestConfig,
|
|
44
|
+
errorHandler: (error) => Promise.reject(error),
|
|
45
|
+
dataCodeProp: 'code',
|
|
46
|
+
dataSuccessCodeRanges: [[200, 300], 0, 'success'],
|
|
47
|
+
dataMsgProp: 'msg',
|
|
48
|
+
dataDataProp: 'data'
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
*/
|
|
52
|
+
export declare const create: (option: {
|
|
53
|
+
axiosOptions: CreateAxiosDefaults;
|
|
54
|
+
errorDataCode: HttpRequestError["code"];
|
|
55
|
+
requestIntercept?(requestConfig: InternalAxiosRequestConfig): InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
|
|
56
|
+
errorHandler?(error: HttpRequestError): Promise<HttpRequestError>;
|
|
57
|
+
dataCodeProp?: string | number;
|
|
58
|
+
dataSuccessCodeRanges?: ([number, number] | number | string)[];
|
|
59
|
+
dataMsgProp?: string | number;
|
|
60
|
+
dataDataProp?: string | number;
|
|
61
|
+
}) => HttpRequestLoader;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HttpRequestPromise } from './httpRequestCreator';
|
|
2
|
+
import { HttpRequestError } from './HttpRequestError';
|
|
3
|
+
/**
|
|
4
|
+
* 绑定then方法到HttpRequestPromise,并返回一个新的HttpRequestPromise。
|
|
5
|
+
* 这个函数用于在HTTP请求的Promise链中添加一个then方法,并确保新的Promise仍然包含ajaxSource属性,以便可以取消请求。
|
|
6
|
+
*
|
|
7
|
+
* @template T - 扩展自HttpRequestPromise的类型。
|
|
8
|
+
* @template M - 一个函数类型,它接受HTTP请求的响应作为参数,并返回一个值或一个Promise。
|
|
9
|
+
* @param {T} request - 原始的HttpRequestPromise。
|
|
10
|
+
* @param {M} then - 要添加到Promise链中的then方法。
|
|
11
|
+
* @returns {HttpRequestPromise<ReturnType<M> extends Promise<infer D> ? D : void>} - 一个新的HttpRequestPromise,包含then方法的结果和原始的ajaxSource属性。
|
|
12
|
+
*/
|
|
13
|
+
export declare const bindThenAjaxSource: <T extends HttpRequestPromise, M extends (response: T extends HttpRequestPromise<infer D> ? D : any) => any>(request: T, then: M) => HttpRequestPromise<ReturnType<M> extends Promise<infer D> ? D : void>;
|
|
14
|
+
/**
|
|
15
|
+
* 绑定catch方法到HttpRequestPromise,并返回一个新的HttpRequestPromise。
|
|
16
|
+
* 这个函数用于在HTTP请求的Promise链中添加一个catch方法,并确保新的Promise仍然包含ajaxSource属性,以便可以取消请求。
|
|
17
|
+
*
|
|
18
|
+
* @template T - 扩展自HttpRequestPromise的类型。
|
|
19
|
+
* @template M - 一个函数类型,它接受HTTP请求的错误对象作为参数,并返回一个值或一个Promise。
|
|
20
|
+
* @param {T} request - 原始的HttpRequestPromise。
|
|
21
|
+
* @param {M} catchFn - 要添加到Promise链中的catch方法。
|
|
22
|
+
* @returns {T} - 一个新的HttpRequestPromise,包含catch方法的结果和原始的ajaxSource属性。
|
|
23
|
+
*/
|
|
24
|
+
export declare const bindCatchAjaxSource: <T extends HttpRequestPromise, M extends (error: HttpRequestError) => any>(request: T, catchFn: M) => T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './DeclareType';
|
|
2
|
+
export * as empty from './empty';
|
|
3
|
+
export * from './class/combine';
|
|
4
|
+
export * from './class/bind';
|
|
5
|
+
export * from './crypto';
|
|
6
|
+
export * from './math/toFixed';
|
|
7
|
+
export * from './math/unitConvertor';
|
|
8
|
+
export * as reduce from './reduce';
|
|
9
|
+
export * from './Date/ZDate';
|
|
10
|
+
export * as mock from './mock';
|
|
11
|
+
export * as httpRequest from './httpRequest';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将数字四舍六入五成双到指定的小数位数。
|
|
3
|
+
*
|
|
4
|
+
* @param {number} number - 要四舍六入五成双的数字。
|
|
5
|
+
* @param {number} [fractionDigits=0] - 要保留的小数位数。默认为0。
|
|
6
|
+
* @returns {number} - 四舍六入五成双后的数字。
|
|
7
|
+
*
|
|
8
|
+
* @example toFixed(12.5, 0)
|
|
9
|
+
* // 输出 12
|
|
10
|
+
*/
|
|
11
|
+
export declare const toFixed: (number: number, fractionDigits?: number) => number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基本单位配置对象,包含单位列表、正转换函数和负转换函数。
|
|
3
|
+
*/
|
|
4
|
+
declare const baseUnitConfig: {
|
|
5
|
+
readonly list: readonly [readonly ["mg/L", 1000, "mg/m3", 1000, "μg/m3", 1000, "ng/m3"], readonly ["ppml", 1000, "ppm", 1000, "ppb", 1000, "ppt"], readonly ["mg/L", 1000, "mg/m³", 1000, "μg/m³", 1000, "ng/m³"], readonly ["kg", 1000, "g", 1000, "mg", 1000, "μg"], readonly ["psi", 6.895, "kpa", 10, "hpa", 100, "pa", 0.0075, "mm hg"], readonly ["km", 1000, "m"], readonly ["km/s", 1000, "m/s"], readonly ["m³/s", 3600, "m³/h", 24, "m³/d"], readonly ["kg/s", 3600, "kg/h", 24, "kg/d"], readonly ["m/s", 3.6, "km/h"]];
|
|
6
|
+
readonly positive: (n: number) => (value: number) => number;
|
|
7
|
+
readonly negative: (n: number) => (value: number) => number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 基本单位配置类型,与 `baseUnitConfig` 类型相同。
|
|
11
|
+
*/
|
|
12
|
+
type BaseUnitConfig = typeof baseUnitConfig;
|
|
13
|
+
/**
|
|
14
|
+
* 基本单位配置列表中值的类型,排除数字类型。
|
|
15
|
+
*/
|
|
16
|
+
type BaseUnitConfigListValue = BaseUnitConfig['list'][number][number];
|
|
17
|
+
/**
|
|
18
|
+
* 单位键类型,从基本单位配置列表中提取的单位字符串。
|
|
19
|
+
*/
|
|
20
|
+
export type UnitKey = Exclude<BaseUnitConfigListValue, number>;
|
|
21
|
+
/**
|
|
22
|
+
* 单位转换函数,根据输入单位和输出单位进行数值转换。
|
|
23
|
+
*
|
|
24
|
+
* @param value - 要转换的数值。
|
|
25
|
+
* @param inputUnit - 输入单位。
|
|
26
|
+
* @param outputUnit - 输出单位。
|
|
27
|
+
* @param otherParams - 其他参数,如重量和摩尔。
|
|
28
|
+
* @returns 转换后的数值。
|
|
29
|
+
*
|
|
30
|
+
* @example unitConvertor(9, 'μg/m³', 'ppb', 64)
|
|
31
|
+
* @returns 3.4382812499999997
|
|
32
|
+
*/
|
|
33
|
+
export declare const unitConvertor: (value: number, inputUnit?: UnitKey | null, outputUnit?: UnitKey | null, ...otherParams: any[]) => any;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 定义 HttpResponseDataKey 类型,它是一个以 "data" 开头的字符串
|
|
3
|
+
*/
|
|
4
|
+
type HttpResponseDataKey = `data${string}`;
|
|
5
|
+
/**
|
|
6
|
+
* HttpResponse 类,用于模拟 HTTP 响应
|
|
7
|
+
* @template T - 响应数据的类型
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpResponse<T> {
|
|
10
|
+
/**
|
|
11
|
+
* HTTP 响应的状态码
|
|
12
|
+
*/
|
|
13
|
+
code: number | string;
|
|
14
|
+
/**
|
|
15
|
+
* HTTP 响应的消息
|
|
16
|
+
*/
|
|
17
|
+
msg: string;
|
|
18
|
+
/**
|
|
19
|
+
* 响应数据,使用 HttpResponseDataKey 作为键
|
|
20
|
+
*/
|
|
21
|
+
[dataProp: HttpResponseDataKey]: T;
|
|
22
|
+
/**
|
|
23
|
+
* 构造函数,用于创建 HttpResponse 实例
|
|
24
|
+
* @param {HttpResponseDataKey} dataProp - 响应数据的键
|
|
25
|
+
* @param {T} data - 响应数据的值
|
|
26
|
+
* @param {boolean} [randomCode=false] - 是否随机生成状态码
|
|
27
|
+
*/
|
|
28
|
+
constructor(dataProp: HttpResponseDataKey, data: T, randomCode?: boolean);
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ZDateUnit } from '../Date/ZDate';
|
|
2
|
+
/**
|
|
3
|
+
* 根据日期范围和间隔生成日期时间数组
|
|
4
|
+
* @param dateRange - 日期范围,包含开始日期和结束日期
|
|
5
|
+
* @param interval - 时间间隔
|
|
6
|
+
* @param dateUnit - 时间单位
|
|
7
|
+
* @param repeat - 重复次数,默认为1
|
|
8
|
+
* @returns 生成的日期时间数组
|
|
9
|
+
*/
|
|
10
|
+
export declare const createDataTimesByRange: (dateRange: [string | Date, string | Date], interval: number, dateUnit: ZDateUnit, repeat?: number) => string[];
|
|
11
|
+
/**
|
|
12
|
+
* 根据开始时间、长度和间隔生成日期时间数组
|
|
13
|
+
* @param beginTime - 开始时间
|
|
14
|
+
* @param length - 时间长度
|
|
15
|
+
* @param interval - 时间间隔
|
|
16
|
+
* @param dateUnit - 时间单位
|
|
17
|
+
* @param repeat - 重复次数,默认为1
|
|
18
|
+
* @returns 生成的日期时间数组
|
|
19
|
+
*/
|
|
20
|
+
export declare const createDataTimesByLength: (beginTime: string, length: number, interval: number, dateUnit: ZDateUnit, repeat?: number) => string[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { WeekParams, ZDateUnit } from '../Date/ZDate';
|
|
2
|
+
import { KeyMatch } from '../DeclareType';
|
|
3
|
+
/**
|
|
4
|
+
* 根据日期范围和时间间隔补全数据列表。
|
|
5
|
+
*
|
|
6
|
+
* @template T - 数据类型。
|
|
7
|
+
* @template U - 日期单位类型。
|
|
8
|
+
* @param {T[]} list - 原始数据列表。
|
|
9
|
+
* @param {KeyMatch<T, string>} dataTimeProp - 数据中日期时间属性的键名。
|
|
10
|
+
* @param {[string, string]} dateRange - 日期范围,包含开始日期和结束日期的字符串数组。
|
|
11
|
+
* @param {Object} completeConfig - 补全配置对象。
|
|
12
|
+
* @param {number} completeConfig.interval - 时间间隔。
|
|
13
|
+
* @param {U} completeConfig.unit - 日期单位。
|
|
14
|
+
* @param {string} completeConfig.format - 日期格式化字符串。
|
|
15
|
+
* @param {boolean} [completeConfig.isUTC] - 是否使用UTC时间,默认为false。
|
|
16
|
+
* @param {U extends 'Week' ? WeekParams : never} [completeConfig.unitParams] - 当单位为周时的额外参数。
|
|
17
|
+
* @param {(data: T) => T} [missDataFormatter] - 缺失数据格式化函数,默认为恒等函数。
|
|
18
|
+
* @returns {T[]} - 补全后的列表。
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
completeByDate(
|
|
22
|
+
[
|
|
23
|
+
{ dataTime: '2024/01/01 00:00:00' },
|
|
24
|
+
{ dataTime: '2024/01/01 03:00:00' },
|
|
25
|
+
],
|
|
26
|
+
'dataTime', // 数据中的时间属性名
|
|
27
|
+
['2024/01/01 00:00:00', '2024/01/01 05:00:00'], // 补齐时间的范围
|
|
28
|
+
{
|
|
29
|
+
interval: 1, // 间隔1
|
|
30
|
+
unit: 'Hours', // 补齐单位为小时
|
|
31
|
+
format: 'YYYY/MM/DD HH:mm:ss', // 此处格式必须和数据中的时间格式一致
|
|
32
|
+
weekParams: [1, 1] // 当unit为Week时, 此参数生效
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
* // 输出
|
|
36
|
+
[
|
|
37
|
+
{ dataTime: '2024/01/01 00:00:00' },
|
|
38
|
+
{ dataTime: '2024/01/01 01:00:00' },
|
|
39
|
+
{ dataTime: '2024/01/01 02:00:00' },
|
|
40
|
+
{ dataTime: '2024/01/01 03:00:00' },
|
|
41
|
+
{ dataTime: '2024/01/01 04:00:00' },
|
|
42
|
+
{ dataTime: '2024/01/01 05:00:00' }
|
|
43
|
+
]
|
|
44
|
+
*/
|
|
45
|
+
export declare const completeByDate: <T, U extends ZDateUnit>(list: T[], dataTimeProp: KeyMatch<T, string>, dateRange: [string, string], completeConfig: {
|
|
46
|
+
interval: number;
|
|
47
|
+
unit: U;
|
|
48
|
+
format: string;
|
|
49
|
+
isUTC?: boolean;
|
|
50
|
+
unitParams?: U extends "Week" ? WeekParams : never;
|
|
51
|
+
}, missDataFormatter?: (data: T) => T) => T[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './completeByDate';
|
|
2
|
+
export * from './mappingBuilder';
|
|
3
|
+
export * from './ratio';
|
|
4
|
+
export * from './sumByGroup';
|
|
5
|
+
export * from './toGroup';
|
|
6
|
+
export * from './valueConvertor';
|
|
7
|
+
export * from './verticalToHorizontal';
|
|
8
|
+
export * from './sort';
|
|
9
|
+
export * as tree from './tree';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { KeyMatch } from '../DeclareType';
|
|
2
|
+
/**
|
|
3
|
+
* 将对象数组转换为键值对形式的对象。
|
|
4
|
+
*
|
|
5
|
+
* @template T - 对象类型。
|
|
6
|
+
* @param {T[]} dataList - 对象数组。
|
|
7
|
+
* @param {KeyMatch<T, PropertyKey>} mapKeyProp - 用于生成键的属性名。
|
|
8
|
+
* @returns {Record<PropertyKey, T>} - 转换后的键值对对象。
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
toKeyValue(
|
|
12
|
+
[
|
|
13
|
+
{ id: 'id1', name: 'name1' },
|
|
14
|
+
{ id: 'id2', name: 'name2' }
|
|
15
|
+
],
|
|
16
|
+
'id'
|
|
17
|
+
)
|
|
18
|
+
* // 输出
|
|
19
|
+
{
|
|
20
|
+
id1: { id: 'id1', name: 'name1' },
|
|
21
|
+
id2: { id: 'id2', name: 'name2' }
|
|
22
|
+
}
|
|
23
|
+
*/
|
|
24
|
+
export declare const toKeyValue: <T>(dataList: T[], mapKeyProp: KeyMatch<T, PropertyKey>) => Record<PropertyKey, T>;
|
|
25
|
+
/**
|
|
26
|
+
* 将对象数组转换为键值对形式的对象,其中值为数组。
|
|
27
|
+
*
|
|
28
|
+
* @template T - 对象类型。
|
|
29
|
+
* @param {T[]} dataList - 对象数组。
|
|
30
|
+
* @param {KeyMatch<T, PropertyKey>} mapKeyProp - 用于生成键的属性名。
|
|
31
|
+
* @returns {Record<PropertyKey, T[]>} - 转换后的键值对对象。
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
toKeyValues(
|
|
35
|
+
[
|
|
36
|
+
{ id: 'id1', name: 'name1' },
|
|
37
|
+
{ id: 'id1', name: 'name2' },
|
|
38
|
+
{ id: 'id2', name: 'name3' }
|
|
39
|
+
],
|
|
40
|
+
'id'
|
|
41
|
+
)
|
|
42
|
+
* // 输出
|
|
43
|
+
{
|
|
44
|
+
id1: [
|
|
45
|
+
{ id: 'id1', name: 'name1' },
|
|
46
|
+
{ id: 'id1', name: 'name2' }
|
|
47
|
+
],
|
|
48
|
+
id2: [
|
|
49
|
+
{ id: 'id2', name: 'name3' }
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
*/
|
|
53
|
+
export declare const toKeyValues: <T>(dataList: T[], mapKeyProp: KeyMatch<T, PropertyKey>) => Record<PropertyKey, T[]>;
|
|
54
|
+
/**
|
|
55
|
+
* 将属性键数组转换为键值对形式的对象,其中值为 `true`。
|
|
56
|
+
*
|
|
57
|
+
* @param {PropertyKey[]} list - 属性键数组。
|
|
58
|
+
* @returns {Record<PropertyKey, true>} - 转换后的键值对对象。
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
toTrue(['1001', '1002', '1003'])
|
|
62
|
+
* // 输出
|
|
63
|
+
{
|
|
64
|
+
'1001': true,
|
|
65
|
+
'1002': true,
|
|
66
|
+
'1003': true
|
|
67
|
+
}
|
|
68
|
+
*/
|
|
69
|
+
export declare const toTrue: (list: PropertyKey[]) => Record<PropertyKey, true>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { KeyMatch, KeyValType } from '../DeclareType';
|
|
2
|
+
/**
|
|
3
|
+
* 定义一个类型别名 `NumberValueProp<T>`,它表示一个联合类型,包含 `KeyMatch<T, number | undefined | null>` 和 `KeyValType`。
|
|
4
|
+
* 这个类型别名通常用于表示键值对中的键或值的类型,其中值可以是数字、undefined 或 null。
|
|
5
|
+
*/
|
|
6
|
+
type NumberValueProp<T> = KeyMatch<T, number | undefined | null> & KeyValType;
|
|
7
|
+
/**
|
|
8
|
+
* 定义一个类型别名 `RatioValue<MD>`,它表示一个对象类型,其中键是 `MD` 数组中每个元素的索引,值是由分子键和分母键组成的字符串,格式为 `${分子键}/${分母键}`。
|
|
9
|
+
* 这个类型别名通常用于表示比例值的类型。
|
|
10
|
+
*/
|
|
11
|
+
type RatioValue<MD extends [KeyValType, KeyValType][]> = {
|
|
12
|
+
[K in keyof MD]: `${MD[K][0]}/${MD[K][1]}`;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 定义一个类型别名 `ResponseData<T, MD>`,它表示一个对象类型,其中包含 `T` 类型的所有属性,以及 `RatioValue<MD>` 类型中每个键对应的值,值的类型是可选的数字。
|
|
16
|
+
* 这个类型别名通常用于表示响应数据的类型,其中包含原始数据和计算得到的比例值。
|
|
17
|
+
*/
|
|
18
|
+
type ResponseData<T, MD extends [KeyValType, KeyValType][]> = T & {
|
|
19
|
+
[K in RatioValue<MD>[number]]?: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 定义一个函数 `ratioByHorizontal`,它接受五个参数:`list`、`props`、`n`、`fractionDigits` 和 `enableFourRoundSix`。
|
|
23
|
+
* 这个函数通常用于计算水平方向上的比例值,并返回一个包含原始数据和计算得到的比例值的数组。
|
|
24
|
+
*
|
|
25
|
+
* @param list - 原始数据数组,类型为 `T[]`。
|
|
26
|
+
* @param props - 比例值的键值对数组,类型为 `MD`,其中 `MD` 是一个二维数组,每个元素是一个包含分子键和分母键的数组。
|
|
27
|
+
* @param n - 比例值的乘数,类型为 `number`,默认值为 1。
|
|
28
|
+
* @param fractionDigits - 保留的小数位数,类型为 `number`,默认值为 2。
|
|
29
|
+
* @param enableFourRoundSix - 是否启用四舍六入五成双规则,类型为 `boolean`,默认值为 true。
|
|
30
|
+
* @returns 一个包含原始数据和计算得到的比例值的数组,类型为 `ResponseData<T, MD>[]`。
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
ratioByHorizontal(
|
|
34
|
+
[
|
|
35
|
+
{ a: 1, b: 2, c: 4, d: 2 },
|
|
36
|
+
{ a: 4, b: 2, c: 1, d: 2 }
|
|
37
|
+
],
|
|
38
|
+
[['a', 'b'], ['c', 'd']] as const,
|
|
39
|
+
100,
|
|
40
|
+
5
|
|
41
|
+
)
|
|
42
|
+
* // 输出
|
|
43
|
+
[
|
|
44
|
+
{ a: 1, b: 2, c: 4, d: 2, 'a/b': 0.5, 'c/d': 2 },
|
|
45
|
+
{ a: 4, b: 2, c: 1, d: 2, 'a/b': 2, 'c/d': 0.5 },
|
|
46
|
+
]
|
|
47
|
+
*/
|
|
48
|
+
export declare const ratioByHorizontal: <T, MD extends [NumberValueProp<T>, NumberValueProp<T>][]>(list: T[], props: MD, n?: number, fractionDigits?: number, enableFourRoundSix?: boolean) => ResponseData<T, MD>[];
|
|
49
|
+
/**
|
|
50
|
+
* 定义一个函数 `ratioByVertical`,它接受一个包含以下属性的对象作为参数:
|
|
51
|
+
* - `list`: 原始数据数组,类型为 `T[]`。
|
|
52
|
+
* - `props`: 比例值的键值对数组,类型为 `BD`,其中 `BD` 是一个包含三个元素的数组,分别表示基准键、过滤键和值键。
|
|
53
|
+
* - `propValues`: 比例值的键值对数组,类型为 `MD`,其中 `MD` 是一个二维数组,每个元素是一个包含分子键和分母键的数组。
|
|
54
|
+
* - `n`: 比例值的乘数,类型为 `number`,默认值为 1。
|
|
55
|
+
* - `fractionDigits`: 保留的小数位数,类型为 `number`,默认值为 2。
|
|
56
|
+
* - `enableFourRoundSix`: 是否启用四舍六入五成双规则,类型为 `boolean`,默认值为 true。
|
|
57
|
+
* - `formatter`: 格式化函数,类型为 `(ratioData: T, calcItems: [T, T]) => void`,默认值为一个空函数。
|
|
58
|
+
* 这个函数通常用于计算垂直方向上的比例值,并返回一个包含原始数据和计算得到的比例值的数组。
|
|
59
|
+
*
|
|
60
|
+
* @param option - 包含计算比例值所需的所有参数的对象。
|
|
61
|
+
* @returns 一个包含原始数据和计算得到的比例值的数组,类型为 `T[]`。
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
ratioByVertical(
|
|
65
|
+
{
|
|
66
|
+
list: [
|
|
67
|
+
{ dataTime: '2024/01/01 00:00:00', factorId: '1001', value: 1 },
|
|
68
|
+
{ dataTime: '2024/01/01 00:00:00', factorId: '1002', value: 2 }
|
|
69
|
+
],
|
|
70
|
+
props: ['dataTime', 'factorId', 'value'],
|
|
71
|
+
propValues: ['1001', '1002'],
|
|
72
|
+
n: 1,
|
|
73
|
+
fractionDigits: 5,
|
|
74
|
+
enableFourRoundSix: true,
|
|
75
|
+
formatter: (ratioData, calcItems) => {
|
|
76
|
+
ratioData.dataTime = '2024/01/01:23:59:59'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
* // 输出
|
|
81
|
+
[{
|
|
82
|
+
dataTime: '2024/01/01 00:00:00',
|
|
83
|
+
factorId: '1001',
|
|
84
|
+
value: 1
|
|
85
|
+
}, {
|
|
86
|
+
dataTime: '2024/01/01 00:00:00',
|
|
87
|
+
factorId: '1002',
|
|
88
|
+
value: 2
|
|
89
|
+
}, {
|
|
90
|
+
dataTime: '2024/01/01:23:59:59',
|
|
91
|
+
factorId: '1001/1002',
|
|
92
|
+
value: 0.5
|
|
93
|
+
}]
|
|
94
|
+
*/
|
|
95
|
+
export declare const ratioByVertical: <T, BD extends [KeyMatch<T, KeyValType>, KeyMatch<T, KeyValType>, KeyMatch<T, number>], MD extends [T[BD[1]], T[BD[1]]][]>(option: {
|
|
96
|
+
list: T[];
|
|
97
|
+
props: BD;
|
|
98
|
+
propValues: MD;
|
|
99
|
+
n?: number;
|
|
100
|
+
fractionDigits?: number;
|
|
101
|
+
enableFourRoundSix?: boolean;
|
|
102
|
+
formatter?: (ratioData: T, calcItems: [T, T]) => void;
|
|
103
|
+
}) => T[];
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { KeyMatch } from '../DeclareType';
|
|
2
|
+
/**
|
|
3
|
+
* 对列表进行排序的函数。
|
|
4
|
+
*
|
|
5
|
+
* 该函数接受一个列表和一个排序键作为参数,根据排序键对列表进行排序。
|
|
6
|
+
* 排序键可以是一个字符串或一个函数,用于指定排序的依据。
|
|
7
|
+
*
|
|
8
|
+
* @param {T[]} list - 需要排序的列表。
|
|
9
|
+
* @param {KeyMatch<T, undefined | number>} sortKey - 排序键,可以是一个字符串或一个函数。
|
|
10
|
+
* @returns {T[]} 返回排序后的列表。
|
|
11
|
+
*/
|
|
12
|
+
export declare const sort: <T>(list: T[], sortKey: KeyMatch<T, undefined | number>) => T[];
|