jinbi-utils 1.0.26 → 1.0.28
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/dist/chunk-optimizer.cjs +89 -33
- package/dist/index.esm.js +2081 -244
- package/dist/index.esm.min.js +2 -2
- package/dist/index.umd.js +5020 -3146
- package/dist/index.umd.min.js +1 -16
- package/package.json +10 -3
- package/types/chinaArea.d.ts +22 -0
- package/types/fieldCatalogParser.d.ts +121 -0
- package/types/index.d.ts +10 -0
- package/types/input.d.ts +51 -0
- package/types/middleware/requestLoggerUnified.d.ts +12 -0
- package/types/mitt.d.ts +31 -0
- package/types/money/constants.d.ts +38 -0
- package/types/money/helpers.d.ts +134 -0
- package/types/money/helpers.test.d.ts +1 -0
- package/types/money/index.d.ts +260 -0
- package/types/money/index.test.d.ts +1 -0
- package/types/money/types.d.ts +22 -0
- package/types/sm3.d.ts +30 -0
- package/types/tree/index.d.ts +55 -0
- package/types/uploadSpeed.d.ts +85 -0
- package/types/uploadValidation.d.ts +53 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Money } from "./index";
|
|
2
|
+
/**
|
|
3
|
+
* 快捷创建 Money 实例的工厂函数
|
|
4
|
+
* @param amount - 金额
|
|
5
|
+
* @returns Money 实例
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const price = money('19.99');
|
|
10
|
+
* const total = money(100);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function money(amount: string | number): Money;
|
|
14
|
+
/**
|
|
15
|
+
* 求和多个金额
|
|
16
|
+
* @param amounts - 金额数组
|
|
17
|
+
* @returns Money - 总和
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const total = sum([
|
|
22
|
+
* new Money('10.5'),
|
|
23
|
+
* new Money('20.3'),
|
|
24
|
+
* new Money('30.2')
|
|
25
|
+
* ]); // 61.00
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function sum(amounts: Money[]): Money;
|
|
29
|
+
/**
|
|
30
|
+
* 获取多个金额中的最大值
|
|
31
|
+
* @param amounts - 金额数组
|
|
32
|
+
* @returns Money - 最大值
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const maxAmount = max([
|
|
37
|
+
* new Money('10.5'),
|
|
38
|
+
* new Money('20.3'),
|
|
39
|
+
* new Money('30.2')
|
|
40
|
+
* ]); // 30.2
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function max(amounts: Money[]): Money;
|
|
44
|
+
/**
|
|
45
|
+
* 获取多个金额中的最小值
|
|
46
|
+
* @param amounts - 金额数组
|
|
47
|
+
* @returns Money - 最小值
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const minAmount = min([
|
|
52
|
+
* new Money('10.5'),
|
|
53
|
+
* new Money('20.3'),
|
|
54
|
+
* new Money('30.2')
|
|
55
|
+
* ]); // 10.5
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function min(amounts: Money[]): Money;
|
|
59
|
+
/**
|
|
60
|
+
* 计算平均值
|
|
61
|
+
* @param amounts - 金额数组
|
|
62
|
+
* @param decimalPlaces - 结果保留的小数位数,默认 2
|
|
63
|
+
* @returns Money - 平均值
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const avgAmount = average([
|
|
68
|
+
* new Money('10.5'),
|
|
69
|
+
* new Money('20.3'),
|
|
70
|
+
* new Money('30.2')
|
|
71
|
+
* ]); // 20.33
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function average(amounts: Money[], decimalPlaces?: number): Money;
|
|
75
|
+
/**
|
|
76
|
+
* 判断金额是否在指定范围内(包含边界)
|
|
77
|
+
* @param amount - 要判断的金额
|
|
78
|
+
* @param minAmount - 最小值
|
|
79
|
+
* @param maxAmount - 最大值
|
|
80
|
+
* @returns boolean
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const price = new Money('50');
|
|
85
|
+
* isInRange(price, new Money('10'), new Money('100')); // true
|
|
86
|
+
* isInRange(price, new Money('60'), new Money('100')); // false
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function isInRange(amount: Money, minAmount: Money, maxAmount: Money): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* 将金额限制在指定范围内
|
|
92
|
+
* @param amount - 要限制的金额
|
|
93
|
+
* @param minAmount - 最小值
|
|
94
|
+
* @param maxAmount - 最大值
|
|
95
|
+
* @returns Money - 限制后的金额
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* clamp(new Money('150'), new Money('0'), new Money('100')); // 100
|
|
100
|
+
* clamp(new Money('-10'), new Money('0'), new Money('100')); // 0
|
|
101
|
+
* clamp(new Money('50'), new Money('0'), new Money('100')); // 50
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function clamp(amount: Money, minAmount: Money, maxAmount: Money): Money;
|
|
105
|
+
/**
|
|
106
|
+
* 按权重分配金额(加权分配)
|
|
107
|
+
* @param amount - 总金额
|
|
108
|
+
* @param weights - 权重数组
|
|
109
|
+
* @returns Money[] - 分配后的金额数组
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* // 100 元按权重 [3, 2, 1] 分配
|
|
114
|
+
* const shares = distributeByWeight(new Money('100'), [3, 2, 1]);
|
|
115
|
+
* // shares: [50.00, 33.33, 16.67]
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function distributeByWeight(amount: Money, weights: number[]): Money[];
|
|
119
|
+
/**
|
|
120
|
+
* 计算多个金额的加权平均值
|
|
121
|
+
* @param amounts - 金额数组
|
|
122
|
+
* @param weights - 权重数组
|
|
123
|
+
* @param decimalPlaces - 结果保留的小数位数,默认 2
|
|
124
|
+
* @returns Money - 加权平均值
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const avg = weightedAverage(
|
|
129
|
+
* [new Money('100'), new Money('200'), new Money('300')],
|
|
130
|
+
* [1, 2, 3]
|
|
131
|
+
* ); // 233.33
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function weightedAverage(amounts: Money[], weights: number[], decimalPlaces?: number): Money;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import type { MoneyInput, MoneyFormatOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* 可比较的金额类型
|
|
5
|
+
*/
|
|
6
|
+
export declare type ComparableAmount = string | number | Money;
|
|
7
|
+
/**
|
|
8
|
+
* 金额计算工具类
|
|
9
|
+
* 基于 decimal.js 实现精确的货币计算,避免 JavaScript 浮点数精度问题
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const price = new Money('19.99');
|
|
14
|
+
* const total = price.multiply(3); // 59.97
|
|
15
|
+
* const tax = total.multiply('0.13'); // 7.7961
|
|
16
|
+
* const finalPrice = total.add(tax).round(2); // 67.77
|
|
17
|
+
* console.log(finalPrice.format()); // "¥67.77"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class Money {
|
|
21
|
+
private readonly value;
|
|
22
|
+
/**
|
|
23
|
+
* 创建 Money 实例
|
|
24
|
+
* @param amount - 金额,支持 string | number | Decimal
|
|
25
|
+
*/
|
|
26
|
+
constructor(amount: MoneyInput);
|
|
27
|
+
/**
|
|
28
|
+
* 加法运算
|
|
29
|
+
* @param amount - 要相加的金额
|
|
30
|
+
* @returns 新的 Money 实例
|
|
31
|
+
*/
|
|
32
|
+
add(amount: ComparableAmount): Money;
|
|
33
|
+
/**
|
|
34
|
+
* 减法运算
|
|
35
|
+
* @param amount - 要相减的金额
|
|
36
|
+
* @returns 新的 Money 实例
|
|
37
|
+
*/
|
|
38
|
+
subtract(amount: ComparableAmount): Money;
|
|
39
|
+
/**
|
|
40
|
+
* 乘法运算
|
|
41
|
+
* @param multiplier - 乘数
|
|
42
|
+
* @returns 新的 Money 实例
|
|
43
|
+
*/
|
|
44
|
+
multiply(multiplier: MoneyInput): Money;
|
|
45
|
+
/**
|
|
46
|
+
* 除法运算
|
|
47
|
+
* @param divisor - 除数
|
|
48
|
+
* @returns 新的 Money 实例
|
|
49
|
+
*/
|
|
50
|
+
divide(divisor: MoneyInput): Money;
|
|
51
|
+
/**
|
|
52
|
+
* 求余运算
|
|
53
|
+
* @param divisor - 除数
|
|
54
|
+
* @returns 新的 Money 实例
|
|
55
|
+
*/
|
|
56
|
+
mod(divisor: MoneyInput): Money;
|
|
57
|
+
/**
|
|
58
|
+
* 绝对值
|
|
59
|
+
* @returns 新的 Money 实例
|
|
60
|
+
*/
|
|
61
|
+
abs(): Money;
|
|
62
|
+
/**
|
|
63
|
+
* 取反
|
|
64
|
+
* @returns 新的 Money 实例
|
|
65
|
+
*/
|
|
66
|
+
negate(): Money;
|
|
67
|
+
/**
|
|
68
|
+
* 四舍五入到指定小数位
|
|
69
|
+
* @param decimalPlaces - 小数位数,默认 2
|
|
70
|
+
* @param roundingMode - 舍入模式,默认 ROUND_HALF_UP(四舍五入)
|
|
71
|
+
* @returns 新的 Money 实例
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* new Money('1.125').round(2); // 1.13 (四舍五入)
|
|
76
|
+
* new Money('1.124').round(2); // 1.12
|
|
77
|
+
* new Money('1.125').round(2, Decimal.ROUND_DOWN); // 1.12 (向下舍入)
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
round(decimalPlaces?: number, roundingMode?: Decimal.Rounding): Money;
|
|
81
|
+
/**
|
|
82
|
+
* 向上取整到指定小数位
|
|
83
|
+
* @param decimalPlaces - 小数位数,默认 2
|
|
84
|
+
* @returns 新的 Money 实例
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* new Money('1.121').ceil(2); // 1.13
|
|
89
|
+
* new Money('1.129').ceil(2); // 1.13
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
ceil(decimalPlaces?: number): Money;
|
|
93
|
+
/**
|
|
94
|
+
* 向下取整到指定小数位
|
|
95
|
+
* @param decimalPlaces - 小数位数,默认 2
|
|
96
|
+
* @returns 新的 Money 实例
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* new Money('1.128').floor(2); // 1.12
|
|
101
|
+
* new Money('1.121').floor(2); // 1.12
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
floor(decimalPlaces?: number): Money;
|
|
105
|
+
/**
|
|
106
|
+
* 截断到指定小数位(直接切割,不进行舍入)
|
|
107
|
+
* @param decimalPlaces - 小数位数,默认 2
|
|
108
|
+
* @returns 新的 Money 实例
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* new Money('1.12999').truncate(2); // 1.12
|
|
113
|
+
* new Money('1.12111').truncate(2); // 1.12
|
|
114
|
+
* new Money('1.19999').truncate(2); // 1.19
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
truncate(decimalPlaces?: number): Money;
|
|
118
|
+
/**
|
|
119
|
+
* 比较:是否大于
|
|
120
|
+
* @param amount - 要比较的金额
|
|
121
|
+
* @returns boolean
|
|
122
|
+
*/
|
|
123
|
+
isGreaterThan(amount: ComparableAmount): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* 比较:是否大于等于
|
|
126
|
+
* @param amount - 要比较的金额
|
|
127
|
+
* @returns boolean
|
|
128
|
+
*/
|
|
129
|
+
isGreaterThanOrEqualTo(amount: ComparableAmount): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* 比较:是否小于
|
|
132
|
+
* @param amount - 要比较的金额
|
|
133
|
+
* @returns boolean
|
|
134
|
+
*/
|
|
135
|
+
isLessThan(amount: ComparableAmount): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* 比较:是否小于等于
|
|
138
|
+
* @param amount - 要比较的金额
|
|
139
|
+
* @returns boolean
|
|
140
|
+
*/
|
|
141
|
+
isLessThanOrEqualTo(amount: ComparableAmount): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* 比较:是否相等
|
|
144
|
+
* @param amount - 要比较的金额
|
|
145
|
+
* @returns boolean
|
|
146
|
+
*/
|
|
147
|
+
equals(amount: ComparableAmount): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* 是否为零
|
|
150
|
+
* @returns boolean
|
|
151
|
+
*/
|
|
152
|
+
isZero(): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* 是否为正数
|
|
155
|
+
* @returns boolean
|
|
156
|
+
*/
|
|
157
|
+
isPositive(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* 是否为负数
|
|
160
|
+
* @returns boolean
|
|
161
|
+
*/
|
|
162
|
+
isNegative(): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* 转换为字符串(完整精度)
|
|
165
|
+
* @returns string
|
|
166
|
+
*/
|
|
167
|
+
toString(): string;
|
|
168
|
+
/**
|
|
169
|
+
* 转换为指定精度的字符串(使用精确切割,不是 toFixed)
|
|
170
|
+
* @param decimalPlaces - 小数位数,默认 2
|
|
171
|
+
* @param roundingMode - 舍入模式,默认 ROUND_HALF_UP
|
|
172
|
+
* @returns string
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* new Money('1.12999').toFixedString(2); // "1.13"
|
|
177
|
+
* new Money('1.12999').toFixedString(4); // "1.1300"
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
toFixedString(decimalPlaces?: number, roundingMode?: Decimal.Rounding): string;
|
|
181
|
+
/**
|
|
182
|
+
* 转换为数字(警告:可能丢失精度,仅用于显示)
|
|
183
|
+
* @returns number
|
|
184
|
+
*/
|
|
185
|
+
toNumber(): number;
|
|
186
|
+
/**
|
|
187
|
+
* 转换为 Decimal 对象
|
|
188
|
+
* @returns Decimal
|
|
189
|
+
*/
|
|
190
|
+
toDecimal(): Decimal;
|
|
191
|
+
/**
|
|
192
|
+
* 格式化为货币字符串
|
|
193
|
+
* @param options - 格式化选项
|
|
194
|
+
* @returns string
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* new Money('1234.56').format(); // "¥1,234.56"
|
|
199
|
+
* new Money('1234.56').format({ symbol: '$' }); // "$1,234.56"
|
|
200
|
+
* new Money('1234.56').format({ symbol: '¥', decimalPlaces: 0 }); // "¥1,235"
|
|
201
|
+
* new Money('1234.56').format({ thousandsSeparator: '' }); // "¥1234.56"
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
format(options?: MoneyFormatOptions): string;
|
|
205
|
+
/**
|
|
206
|
+
* 按比例分配金额(解决分账/分摊场景的精度问题)
|
|
207
|
+
* @param ratios - 分配比例数组
|
|
208
|
+
* @returns Money[] - 分配后的金额数组
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* // 100 元按 1:2:3 比例分配
|
|
213
|
+
* const [a, b, c] = new Money('100').allocate([1, 2, 3]);
|
|
214
|
+
* // a: 16.67, b: 33.33, c: 50.00 (总和仍为 100.00)
|
|
215
|
+
*
|
|
216
|
+
* // 订单 99.99 元,3人平摊
|
|
217
|
+
* const shares = new Money('99.99').allocate([1, 1, 1]);
|
|
218
|
+
* // shares: [33.33, 33.33, 33.33] (总和 99.99)
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
allocate(ratios: number[]): Money[];
|
|
222
|
+
/**
|
|
223
|
+
* 计算百分比
|
|
224
|
+
* @param percentage - 百分比值(如:15 表示 15%)
|
|
225
|
+
* @param decimalPlaces - 结果保留的小数位数,默认 2
|
|
226
|
+
* @returns Money - 计算结果
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* new Money('100').percentage(15); // 15.00 (100 的 15%)
|
|
231
|
+
* new Money('99.99').percentage(8.5); // 8.50 (99.99 的 8.5%)
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
percentage(percentage: MoneyInput, decimalPlaces?: number): Money;
|
|
235
|
+
/**
|
|
236
|
+
* 计算折扣后的价格
|
|
237
|
+
* @param discount - 折扣率(如:0.8 表示 8折,20 表示 8折)
|
|
238
|
+
* @param isPercentage - discount 是否为百分比形式,默认 false
|
|
239
|
+
* @param decimalPlaces - 结果保留的小数位数,默认 2
|
|
240
|
+
* @returns Money - 折扣后的价格
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* // 方式1:直接传折扣率
|
|
245
|
+
* new Money('100').applyDiscount(0.8); // 80.00 (8折后)
|
|
246
|
+
*
|
|
247
|
+
* // 方式2:传百分比
|
|
248
|
+
* new Money('100').applyDiscount(20, true); // 80.00 (打8折,折扣20%)
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
applyDiscount(discount: MoneyInput, isPercentage?: boolean, decimalPlaces?: number): Money;
|
|
252
|
+
/**
|
|
253
|
+
* 内部辅助方法:将 ComparableAmount 转换为 Decimal
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
private toDecimalValue;
|
|
257
|
+
}
|
|
258
|
+
export type { MoneyInput, MoneyFormatOptions } from "./types";
|
|
259
|
+
export { RoundingMode } from "./constants";
|
|
260
|
+
export { Decimal };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type Decimal from "decimal.js";
|
|
2
|
+
/**
|
|
3
|
+
* 金额格式化选项
|
|
4
|
+
*/
|
|
5
|
+
export interface MoneyFormatOptions {
|
|
6
|
+
/** 货币符号,默认 "¥" */
|
|
7
|
+
symbol?: string;
|
|
8
|
+
/** 小数位数,默认 2 */
|
|
9
|
+
decimalPlaces?: number;
|
|
10
|
+
/** 千分位分隔符,默认 "," */
|
|
11
|
+
thousandsSeparator?: string;
|
|
12
|
+
/** 小数点分隔符,默认 "." */
|
|
13
|
+
decimalSeparator?: string;
|
|
14
|
+
/** 符号位置,默认 "prefix" */
|
|
15
|
+
symbolPosition?: "prefix" | "suffix";
|
|
16
|
+
/** 舍入模式,默认 ROUND_HALF_UP */
|
|
17
|
+
roundingMode?: Decimal.Rounding;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Money 类接受的输入类型
|
|
21
|
+
*/
|
|
22
|
+
export declare type MoneyInput = string | number | Decimal;
|
package/types/sm3.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SM3 国密哈希算法工具
|
|
3
|
+
* @description 使用 sm-crypto 库对敏感数据(如密码)进行 SM3 加密
|
|
4
|
+
*
|
|
5
|
+
* SM3 是中国国家密码管理局发布的密码杂凑算法标准
|
|
6
|
+
* 输出 256 位(32 字节)的哈希值
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* SM3 哈希计算
|
|
10
|
+
* @param message 待哈希的字符串
|
|
11
|
+
* @returns 64 位十六进制字符串
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const hash = sm3('hello world');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function sm3(message: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* 对密码进行 SM3 加密
|
|
21
|
+
* @param password 原始密码
|
|
22
|
+
* @returns SM3 加密后的密码(64 位十六进制字符串)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const encryptedPassword = encryptPassword('admin123');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function encryptPassword(password: string): string;
|
|
30
|
+
export default sm3;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 树节点类型定义
|
|
3
|
+
*/
|
|
4
|
+
export declare type TreeNode = {
|
|
5
|
+
id?: number | string;
|
|
6
|
+
parentId?: number | string | null;
|
|
7
|
+
pathList?: Array<number | string>;
|
|
8
|
+
uniqueId?: number | string;
|
|
9
|
+
children?: TreeNode[];
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @description 提取菜单树中的每一项uniqueId
|
|
14
|
+
* @param tree 树
|
|
15
|
+
* @returns 每一项uniqueId组成的数组
|
|
16
|
+
*/
|
|
17
|
+
export declare const extractPathList: (tree: TreeNode[]) => Array<number | string>;
|
|
18
|
+
/**
|
|
19
|
+
* @description 如果父级下children的length为1,删除children并自动组建唯一uniqueId
|
|
20
|
+
* @param tree 树
|
|
21
|
+
* @param pathList 每一项的id组成的数组
|
|
22
|
+
* @returns 组件唯一uniqueId后的树
|
|
23
|
+
*/
|
|
24
|
+
export declare const deleteChildren: (tree: TreeNode[], pathList?: Array<number | string>) => TreeNode[];
|
|
25
|
+
/**
|
|
26
|
+
* @description 创建层级关系
|
|
27
|
+
* @param tree 树
|
|
28
|
+
* @param pathList 每一项的id组成的数组
|
|
29
|
+
* @returns 创建层级关系后的树
|
|
30
|
+
*/
|
|
31
|
+
export declare const buildHierarchyTree: (tree: TreeNode[], pathList?: Array<number | string>) => TreeNode[];
|
|
32
|
+
/**
|
|
33
|
+
* @description 广度优先遍历,根据唯一uniqueId找当前节点信息
|
|
34
|
+
* @param tree 树
|
|
35
|
+
* @param uniqueId 唯一uniqueId
|
|
36
|
+
* @returns 当前节点信息
|
|
37
|
+
*/
|
|
38
|
+
export declare const getNodeByUniqueId: (tree: TreeNode[], uniqueId: number | string) => TreeNode | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* @description 向当前唯一uniqueId节点中追加字段
|
|
41
|
+
* @param tree 树
|
|
42
|
+
* @param uniqueId 唯一uniqueId
|
|
43
|
+
* @param fields 需要追加的字段
|
|
44
|
+
* @returns 追加字段后的树
|
|
45
|
+
*/
|
|
46
|
+
export declare const appendFieldByUniqueId: (tree: TreeNode[], uniqueId: number | string, fields: Record<string, unknown>) => TreeNode[];
|
|
47
|
+
/**
|
|
48
|
+
* @description 构造树型结构数据
|
|
49
|
+
* @param data 数据源
|
|
50
|
+
* @param id id字段 默认id
|
|
51
|
+
* @param parentId 父节点字段,默认parentId
|
|
52
|
+
* @param children 子节点字段,默认children
|
|
53
|
+
* @returns 追加字段后的树
|
|
54
|
+
*/
|
|
55
|
+
export declare const handleTree: (data: TreeNode[], id?: string | undefined, parentId?: string | undefined, children?: string | undefined) => TreeNode[];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上传速度计算和时间预估工具
|
|
3
|
+
* 使用滑动窗口算法计算实时上传速度
|
|
4
|
+
*/
|
|
5
|
+
export declare class UploadSpeedCalculator {
|
|
6
|
+
private speedPoints;
|
|
7
|
+
private readonly windowSize;
|
|
8
|
+
private readonly minPoints;
|
|
9
|
+
private startTime;
|
|
10
|
+
private totalBytes;
|
|
11
|
+
/**
|
|
12
|
+
* @param windowSize 滑动窗口大小(秒),默认 10 秒
|
|
13
|
+
* @param minPoints 最少记录点数,默认 3 个
|
|
14
|
+
*/
|
|
15
|
+
constructor(windowSize?: number, minPoints?: number);
|
|
16
|
+
/**
|
|
17
|
+
* 开始计算
|
|
18
|
+
* @param totalBytes 总字节数
|
|
19
|
+
*/
|
|
20
|
+
start(totalBytes: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* 添加速度记录点
|
|
23
|
+
* @param uploadedBytes 已上传字节数
|
|
24
|
+
*/
|
|
25
|
+
addPoint(uploadedBytes: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* 计算当前上传速度(字节/秒)
|
|
28
|
+
*/
|
|
29
|
+
getCurrentSpeed(): number;
|
|
30
|
+
/**
|
|
31
|
+
* 计算平均上传速度(字节/秒)
|
|
32
|
+
*/
|
|
33
|
+
getAverageSpeed(): number;
|
|
34
|
+
/**
|
|
35
|
+
* 计算剩余时间(秒)
|
|
36
|
+
* @param uploadedBytes 已上传字节数
|
|
37
|
+
* @returns 剩余秒数,-1 表示无法计算
|
|
38
|
+
*/
|
|
39
|
+
getRemainingTime(uploadedBytes: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* 格式化速度(自动选择单位)
|
|
42
|
+
* @param bytesPerSecond 速度(字节/秒)
|
|
43
|
+
*/
|
|
44
|
+
static formatSpeed(bytesPerSecond: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* 格式化剩余时间(友好显示)
|
|
47
|
+
* @param seconds 剩余秒数
|
|
48
|
+
*/
|
|
49
|
+
static formatRemainingTime(seconds: number): string;
|
|
50
|
+
/**
|
|
51
|
+
* 获取上传进度百分比
|
|
52
|
+
* @param uploadedBytes 已上传字节数
|
|
53
|
+
*/
|
|
54
|
+
getProgress(uploadedBytes: number): number;
|
|
55
|
+
/**
|
|
56
|
+
* 重置计算器
|
|
57
|
+
*/
|
|
58
|
+
reset(): void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 全局速度计算器管理器
|
|
62
|
+
* 为每个文件维护独立的速度计算器
|
|
63
|
+
*/
|
|
64
|
+
export declare class SpeedCalculatorManager {
|
|
65
|
+
private calculators;
|
|
66
|
+
/**
|
|
67
|
+
* 获取或创建文件的速度计算器
|
|
68
|
+
* @param fileId 文件 ID
|
|
69
|
+
*/
|
|
70
|
+
getCalculator(fileId: string): UploadSpeedCalculator;
|
|
71
|
+
/**
|
|
72
|
+
* 移除文件的速度计算器
|
|
73
|
+
* @param fileId 文件 ID
|
|
74
|
+
*/
|
|
75
|
+
removeCalculator(fileId: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* 清空所有计算器
|
|
78
|
+
*/
|
|
79
|
+
clear(): void;
|
|
80
|
+
/**
|
|
81
|
+
* 获取所有文件的总速度
|
|
82
|
+
*/
|
|
83
|
+
getTotalSpeed(): number;
|
|
84
|
+
}
|
|
85
|
+
export declare const speedCalculatorManager: SpeedCalculatorManager;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件上传前验证工具
|
|
3
|
+
* 包含文件大小、类型、配额、网络等验证
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidationResult {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
error?: string;
|
|
8
|
+
code?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ValidationConfig {
|
|
11
|
+
maxFileSize?: number;
|
|
12
|
+
maxTotalSize?: number;
|
|
13
|
+
allowedTypes?: string[];
|
|
14
|
+
maxFilesCount?: number;
|
|
15
|
+
checkNetwork?: boolean;
|
|
16
|
+
checkQuota?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 文件大小验证器
|
|
20
|
+
*/
|
|
21
|
+
export declare function validateFileSize(file: File, maxSize?: number): ValidationResult;
|
|
22
|
+
/**
|
|
23
|
+
* 总文件大小验证器
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateTotalSize(files: File[], maxTotalSize?: number): ValidationResult;
|
|
26
|
+
/**
|
|
27
|
+
* 文件类型验证器
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateFileType(file: File, allowedTypes?: string[]): ValidationResult;
|
|
30
|
+
/**
|
|
31
|
+
* 文件数量验证器
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateFilesCount(currentCount: number, newFilesCount: number, maxCount?: number): ValidationResult;
|
|
34
|
+
/**
|
|
35
|
+
* 网络状态检测器
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkNetworkStatus(): ValidationResult;
|
|
38
|
+
/**
|
|
39
|
+
* 配额检查器(模拟,实际需要调用后端 API)
|
|
40
|
+
*/
|
|
41
|
+
export declare function checkStorageQuota(filesTotalSize: number): Promise<ValidationResult>;
|
|
42
|
+
/**
|
|
43
|
+
* 综合验证器 - 执行所有验证
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateFilesBeforeUpload(files: File[], currentFiles?: File[], config?: ValidationConfig): Promise<ValidationResult[]>;
|
|
46
|
+
/**
|
|
47
|
+
* 格式化文件大小
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatFileSize(bytes: number): string;
|
|
50
|
+
/**
|
|
51
|
+
* 获取友好的错误提示
|
|
52
|
+
*/
|
|
53
|
+
export declare function getValidationErrorMessage(results: ValidationResult[]): string;
|