@yh-kit/utils 1.15.0 → 1.15.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/dist/utils.js +217 -190
- package/dist/utils.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/array/appear.d.ts +17 -0
- package/types/array/array2obj.d.ts +12 -0
- package/types/array/base.d.ts +2 -0
- package/types/array/exist.d.ts +17 -0
- package/types/array/extreme-value.d.ts +33 -0
- package/types/array/index.d.ts +24 -0
- package/types/array/orderby.d.ts +22 -0
- package/types/array/unique.d.ts +9 -0
- package/types/{utils/lib/url → url}/index.d.ts +5 -4
- package/types/typings/src/enum-obj.d.ts +0 -14
- package/types/typings/src/index.d.ts +0 -2
- package/types/typings/src/option.d.ts +0 -13
- package/types/utils/lib/array/array2obj.d.ts +0 -8
- package/types/utils/lib/array/index.d.ts +0 -83
- /package/types/{utils/lib/base64 → base64}/index.d.ts +0 -0
- /package/types/{utils/lib/boolean → boolean}/index.d.ts +0 -0
- /package/types/{utils/lib/common → common}/index.d.ts +0 -0
- /package/types/{utils/lib/cookie → cookie}/index.d.ts +0 -0
- /package/types/{utils/lib/date → date}/index.d.ts +0 -0
- /package/types/{utils/lib/document → document}/index.d.ts +0 -0
- /package/types/{utils/lib/download → download}/index.d.ts +0 -0
- /package/types/{utils/lib/echarts → echarts}/index.d.ts +0 -0
- /package/types/{utils/lib/index.d.ts → index.d.ts} +0 -0
- /package/types/{utils/lib/letter → letter}/index.d.ts +0 -0
- /package/types/{utils/lib/map → map}/index.d.ts +0 -0
- /package/types/{utils/lib/money → money}/index.d.ts +0 -0
- /package/types/{utils/lib/name → name}/index.d.ts +0 -0
- /package/types/{utils/lib/name → name}/typing.d.ts +0 -0
- /package/types/{utils/lib/number → number}/index.d.ts +0 -0
- /package/types/{utils/lib/number → number}/letter.d.ts +0 -0
- /package/types/{utils/lib/number → number}/money.d.ts +0 -0
- /package/types/{utils/lib/object → object}/index.d.ts +0 -0
- /package/types/{utils/lib/phone → phone}/index.d.ts +0 -0
- /package/types/{utils/lib/random → random}/index.d.ts +0 -0
- /package/types/{utils/lib/regexp → regexp}/index.d.ts +0 -0
- /package/types/{utils/lib/storage → storage}/index.d.ts +0 -0
- /package/types/{utils/lib/string → string}/index.d.ts +0 -0
- /package/types/{utils/lib/url → url}/query.d.ts +0 -0
- /package/types/{utils/lib/waterfall → waterfall}/index.d.ts +0 -0
package/dist/utils.js
CHANGED
|
@@ -1,139 +1,166 @@
|
|
|
1
|
-
const w =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* @returns 最小值
|
|
97
|
-
*/
|
|
98
|
-
getMinValue(e) {
|
|
99
|
-
return e ? Math.min(...e) : 0;
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
* 获取数组中的最小值和索引
|
|
103
|
-
* @param array 数组
|
|
104
|
-
* @returns 最小值和索引
|
|
105
|
-
*/
|
|
106
|
-
getMinValueAndIndex(e) {
|
|
107
|
-
if (e.length === 0) return { value: 0, index: 0 };
|
|
108
|
-
const n = {
|
|
109
|
-
/** 最小值 */
|
|
110
|
-
value: e[0],
|
|
111
|
-
/** 最小值索引 */
|
|
112
|
-
index: 0
|
|
113
|
-
};
|
|
114
|
-
for (let t = 1, r = e.length; t < r; t++) {
|
|
115
|
-
const o = e[t];
|
|
116
|
-
n.value > o && (n.value = o, n.index = t);
|
|
117
|
-
}
|
|
118
|
-
return n;
|
|
119
|
-
},
|
|
120
|
-
/**
|
|
121
|
-
* 获取数组中的最大值和索引
|
|
122
|
-
* @param arr 数组
|
|
123
|
-
* @returns 最大值和索引
|
|
124
|
-
*/
|
|
125
|
-
getMaxValueAndIndex(e) {
|
|
126
|
-
return e.length === 0 ? { value: 0, index: 0 } : e.reduce(
|
|
127
|
-
(n, t, r) => t < n.value ? { value: t, index: r } : n,
|
|
128
|
-
{ value: e[0], index: 0 }
|
|
129
|
-
);
|
|
1
|
+
const w = {
|
|
2
|
+
/**
|
|
3
|
+
* 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
|
|
4
|
+
* @param arr 数组
|
|
5
|
+
* @param target 目标元素
|
|
6
|
+
* @returns 出现次数
|
|
7
|
+
*/
|
|
8
|
+
countOfAppear(e, n) {
|
|
9
|
+
let t = 0;
|
|
10
|
+
for (const r of e)
|
|
11
|
+
r === n && t++;
|
|
12
|
+
return t;
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* 查找某个元素在数组中重复出现的位置
|
|
16
|
+
* @param array 数组
|
|
17
|
+
* @param element 元素
|
|
18
|
+
* @returns 位置数组
|
|
19
|
+
*/
|
|
20
|
+
indexsOfAppear(e, n) {
|
|
21
|
+
let t = -1;
|
|
22
|
+
const r = [];
|
|
23
|
+
do
|
|
24
|
+
t = e.indexOf(n, t + 1), t !== -1 && r.push(t);
|
|
25
|
+
while (t !== -1);
|
|
26
|
+
return r;
|
|
27
|
+
}
|
|
28
|
+
}, b = {
|
|
29
|
+
// toEnumObj: handleArrTansferEnumObj,
|
|
30
|
+
/**
|
|
31
|
+
* 数组转枚举对象
|
|
32
|
+
* @param arr 数组
|
|
33
|
+
* @param valueKey 值键名。不传,默认值为"value"。
|
|
34
|
+
* @returns 枚举对象。键为数组元素的valueKey值,值为数组元素。
|
|
35
|
+
*/
|
|
36
|
+
toEnumObj(e, n = "value") {
|
|
37
|
+
if (!e || !e.length) return {};
|
|
38
|
+
const t = {};
|
|
39
|
+
return e.forEach((r) => {
|
|
40
|
+
const o = Object.assign({ label: r.label, text: r.label }, r);
|
|
41
|
+
t[r[n]] = o;
|
|
42
|
+
}), t;
|
|
43
|
+
}
|
|
44
|
+
}, A = {
|
|
45
|
+
/**
|
|
46
|
+
* 判断某元素是否在存在于数组中(indexOf方法)
|
|
47
|
+
* @param arr 数组
|
|
48
|
+
* @param element 查询元素
|
|
49
|
+
* @returns 是否存在。true 存在;false 不存在
|
|
50
|
+
*/
|
|
51
|
+
isExistByIndexOf(e, n) {
|
|
52
|
+
return !e || !n ? !1 : e.indexOf(n) !== -1;
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* 判断某元素是否在存在于数组中(includes方法)
|
|
56
|
+
* @param arr 数组
|
|
57
|
+
* @param element 查询元素
|
|
58
|
+
* @returns 是否存在。true 存在;false 不存在
|
|
59
|
+
*/
|
|
60
|
+
isExistByIncludes(e, n) {
|
|
61
|
+
return !e || !n ? !1 : e.includes(n);
|
|
62
|
+
}
|
|
63
|
+
}, S = {
|
|
64
|
+
/**
|
|
65
|
+
* 获取数组中的最大值
|
|
66
|
+
* @param arr 数组
|
|
67
|
+
* @returns 最大值
|
|
68
|
+
*/
|
|
69
|
+
getMaxValue(e) {
|
|
70
|
+
return e ? Math.max(...e) : 0;
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* 获取数组中的最小值
|
|
74
|
+
* @param arr 数组
|
|
75
|
+
* @returns 最小值
|
|
76
|
+
*/
|
|
77
|
+
getMinValue(e) {
|
|
78
|
+
return e ? Math.min(...e) : 0;
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* 获取数组中的最小值和索引
|
|
82
|
+
* @param array 数组
|
|
83
|
+
* @returns 最小值和索引
|
|
84
|
+
*/
|
|
85
|
+
getMinValueAndIndex(e) {
|
|
86
|
+
if (e.length === 0) return { value: 0, index: 0 };
|
|
87
|
+
const n = {
|
|
88
|
+
/** 最小值 */
|
|
89
|
+
value: e[0],
|
|
90
|
+
/** 最小值索引 */
|
|
91
|
+
index: 0
|
|
92
|
+
};
|
|
93
|
+
for (let t = 1, r = e.length; t < r; t++) {
|
|
94
|
+
const o = e[t];
|
|
95
|
+
n.value > o && (n.value = o, n.index = t);
|
|
130
96
|
}
|
|
97
|
+
return n;
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* 获取数组中的最大值和索引
|
|
101
|
+
* @param arr 数组
|
|
102
|
+
* @returns 最大值和索引
|
|
103
|
+
*/
|
|
104
|
+
getMaxValueAndIndex(e) {
|
|
105
|
+
return e.length === 0 ? { value: 0, index: 0 } : e.reduce(
|
|
106
|
+
(n, t, r) => t < n.value ? { value: t, index: r } : n,
|
|
107
|
+
{ value: e[0], index: 0 }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}, M = {
|
|
111
|
+
/**
|
|
112
|
+
* 数组排序-默认升序
|
|
113
|
+
* @param arr 数组
|
|
114
|
+
* @param order 排序方式:asc 升序;desc 降序
|
|
115
|
+
* @returns 排序后的数组
|
|
116
|
+
*/
|
|
117
|
+
sort(e, n = "asc") {
|
|
118
|
+
return e ? e.sort((t, r) => n === "asc" ? t > r ? 1 : -1 : t < r ? 1 : -1) : [];
|
|
131
119
|
},
|
|
132
|
-
|
|
133
|
-
|
|
120
|
+
/**
|
|
121
|
+
* 数组乱序(洗牌算法)
|
|
122
|
+
* 1. 从数组的最后一个元素开始,将其与随机位置的元素交换位置。
|
|
123
|
+
* 2. 然后,从倒数第二个元素开始,将其与随机位置的元素交换位置。
|
|
124
|
+
* 3. 以此类推,直到第一个元素。
|
|
125
|
+
* 4. 这样,数组中的元素就会被随机打乱顺序。
|
|
126
|
+
* 5. 注意,这个算法会改变原数组。如果不想改变原数组,可以先复制一份再进行操作。
|
|
127
|
+
* 6. 时间复杂度:O(n)
|
|
128
|
+
* @param arr 数组
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
shuffle(e) {
|
|
132
|
+
if (!e)
|
|
133
|
+
return [];
|
|
134
|
+
for (let n = e.length - 1; n > 0; n--) {
|
|
135
|
+
const t = Math.floor(Math.random() * (n + 1));
|
|
136
|
+
[e[n], e[t]] = [e[t], e[n]];
|
|
137
|
+
}
|
|
138
|
+
return e;
|
|
139
|
+
}
|
|
140
|
+
}, x = {
|
|
141
|
+
/**
|
|
142
|
+
* 数组去重
|
|
143
|
+
* @param arr 数组
|
|
144
|
+
* @returns 去重后的数组
|
|
145
|
+
*/
|
|
146
|
+
uniqueBySet(e) {
|
|
147
|
+
return e ? Array.from(new Set(e)) : [];
|
|
134
148
|
}
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
}, E = {
|
|
150
|
+
// 数组转对象
|
|
151
|
+
...b,
|
|
152
|
+
// 数组去重
|
|
153
|
+
...x,
|
|
154
|
+
// 判断元素是否存在
|
|
155
|
+
...A,
|
|
156
|
+
// 数组排序
|
|
157
|
+
...M,
|
|
158
|
+
// 获取极值
|
|
159
|
+
...S,
|
|
160
|
+
// 统计出现次数
|
|
161
|
+
...w
|
|
162
|
+
};
|
|
163
|
+
class I {
|
|
137
164
|
/** Base64 编码表 */
|
|
138
165
|
static BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
139
166
|
/**
|
|
@@ -287,7 +314,7 @@ class _ {
|
|
|
287
314
|
return s;
|
|
288
315
|
}
|
|
289
316
|
}
|
|
290
|
-
const
|
|
317
|
+
const C = {
|
|
291
318
|
/**
|
|
292
319
|
* 检查是否为空字符串
|
|
293
320
|
* @param str 要检查的字符串
|
|
@@ -431,7 +458,7 @@ const S = {
|
|
|
431
458
|
isMobile() {
|
|
432
459
|
return /Mobi|Android|iPhone/i.test(navigator.userAgent);
|
|
433
460
|
}
|
|
434
|
-
},
|
|
461
|
+
}, k = {
|
|
435
462
|
/**
|
|
436
463
|
* 获取变量的类型
|
|
437
464
|
* @param val 任意变量
|
|
@@ -440,7 +467,7 @@ const S = {
|
|
|
440
467
|
getType(e) {
|
|
441
468
|
return Object.prototype.toString.call(e).replace(/\[object\s(\w+)\]/, "$1");
|
|
442
469
|
}
|
|
443
|
-
},
|
|
470
|
+
}, H = {
|
|
444
471
|
/**
|
|
445
472
|
* 通过传入的name获取cookie的值
|
|
446
473
|
* @param name cookie的name
|
|
@@ -470,7 +497,7 @@ const S = {
|
|
|
470
497
|
deleteCookie(e) {
|
|
471
498
|
this.setCookie(e, "", -1);
|
|
472
499
|
}
|
|
473
|
-
},
|
|
500
|
+
}, $ = {
|
|
474
501
|
/**
|
|
475
502
|
* 获取当前时间字符串
|
|
476
503
|
* @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
|
|
@@ -518,7 +545,7 @@ const S = {
|
|
|
518
545
|
r += 31;
|
|
519
546
|
break;
|
|
520
547
|
case 2:
|
|
521
|
-
|
|
548
|
+
C.isLeapYear(e) ? r += 29 : r += 28;
|
|
522
549
|
break;
|
|
523
550
|
default:
|
|
524
551
|
r += 30;
|
|
@@ -585,7 +612,7 @@ const S = {
|
|
|
585
612
|
new RegExp("(" + r + ")").test(n) && (n = n.replace(RegExp.$1, RegExp.$1.length === 1 ? t[r] : ("00" + t[r]).substr(("" + t[r]).length)));
|
|
586
613
|
return n;
|
|
587
614
|
}
|
|
588
|
-
},
|
|
615
|
+
}, j = {
|
|
589
616
|
/**
|
|
590
617
|
* 获取元素相对于文档顶部的偏移量(距离)
|
|
591
618
|
* 处理了SVG元素的特殊情况。
|
|
@@ -656,7 +683,7 @@ const S = {
|
|
|
656
683
|
getViewportHeight() {
|
|
657
684
|
return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
658
685
|
}
|
|
659
|
-
},
|
|
686
|
+
}, N = {
|
|
660
687
|
/**
|
|
661
688
|
* 将blob对象转化成文件并导出到本地
|
|
662
689
|
* @param blob blob对象
|
|
@@ -675,7 +702,7 @@ const S = {
|
|
|
675
702
|
const t = document.createElement("a");
|
|
676
703
|
t.href = e, t.download = n, document.body.appendChild(t), t.click(), URL.revokeObjectURL(e), document.body.removeChild(t);
|
|
677
704
|
}
|
|
678
|
-
},
|
|
705
|
+
}, P = {
|
|
679
706
|
/**
|
|
680
707
|
* echarts动画函数
|
|
681
708
|
* @param option echarts配置
|
|
@@ -707,7 +734,7 @@ const S = {
|
|
|
707
734
|
});
|
|
708
735
|
});
|
|
709
736
|
}
|
|
710
|
-
},
|
|
737
|
+
}, F = {
|
|
711
738
|
/**
|
|
712
739
|
* 将选中的字母数组从A-Z排序:用于试题选择答案的排序实例
|
|
713
740
|
* @param arr 字母数组
|
|
@@ -719,7 +746,7 @@ const S = {
|
|
|
719
746
|
return o < s ? -1 : o > s ? 1 : 0;
|
|
720
747
|
}) : void 0;
|
|
721
748
|
}
|
|
722
|
-
},
|
|
749
|
+
}, V = {
|
|
723
750
|
/**
|
|
724
751
|
* 角度(度数)转弧度
|
|
725
752
|
* 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
|
|
@@ -805,7 +832,7 @@ const S = {
|
|
|
805
832
|
return { segments: r, total: o };
|
|
806
833
|
}
|
|
807
834
|
};
|
|
808
|
-
class
|
|
835
|
+
class W {
|
|
809
836
|
/**
|
|
810
837
|
* 转换为标准金额格式(带千分位和两位小数)
|
|
811
838
|
* @param num 要转换的数字
|
|
@@ -860,7 +887,7 @@ class N {
|
|
|
860
887
|
}
|
|
861
888
|
}
|
|
862
889
|
}
|
|
863
|
-
const
|
|
890
|
+
const Y = {
|
|
864
891
|
/**
|
|
865
892
|
* 中文姓名脱敏
|
|
866
893
|
* @param name 姓名
|
|
@@ -903,15 +930,15 @@ const P = {
|
|
|
903
930
|
}
|
|
904
931
|
return `${e.slice(0, c)}${"*".repeat(e.length - c)}`;
|
|
905
932
|
}
|
|
906
|
-
},
|
|
933
|
+
}, B = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
907
934
|
__proto__: null,
|
|
908
|
-
toLetter:
|
|
909
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
935
|
+
toLetter: B
|
|
936
|
+
}, Symbol.toStringTag, { value: "Module" })), R = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
910
937
|
__proto__: null,
|
|
911
|
-
toMoney:
|
|
912
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
913
|
-
...
|
|
914
|
-
...
|
|
938
|
+
toMoney: R
|
|
939
|
+
}, Symbol.toStringTag, { value: "Module" })), z = {
|
|
940
|
+
...D,
|
|
941
|
+
...U,
|
|
915
942
|
/**
|
|
916
943
|
* 判断是否为数字
|
|
917
944
|
* @param val 待判断的值
|
|
@@ -920,7 +947,7 @@ const P = {
|
|
|
920
947
|
isNumber(e) {
|
|
921
948
|
return typeof e == "number" && !isNaN(e);
|
|
922
949
|
}
|
|
923
|
-
},
|
|
950
|
+
}, q = {
|
|
924
951
|
/**
|
|
925
952
|
* 判断对象是否为空
|
|
926
953
|
* @param obj 对象
|
|
@@ -951,7 +978,7 @@ const P = {
|
|
|
951
978
|
r instanceof Object ? (n[t] = {}, this.deepCopy(r, n[t])) : r instanceof Array ? (n[t] = [], this.deepCopy(r, n[t])) : n[t] = e[t];
|
|
952
979
|
}
|
|
953
980
|
}
|
|
954
|
-
},
|
|
981
|
+
}, Z = {
|
|
955
982
|
/**
|
|
956
983
|
* 脱敏
|
|
957
984
|
* @param phone 电话号码/手机号码
|
|
@@ -960,7 +987,7 @@ const P = {
|
|
|
960
987
|
desensitize(e) {
|
|
961
988
|
return e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : "";
|
|
962
989
|
}
|
|
963
|
-
},
|
|
990
|
+
}, J = {
|
|
964
991
|
/**
|
|
965
992
|
* 生成随机颜色
|
|
966
993
|
* @returns 随机颜色值
|
|
@@ -984,7 +1011,7 @@ const P = {
|
|
|
984
1011
|
uniqueId() {
|
|
985
1012
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
986
1013
|
}
|
|
987
|
-
},
|
|
1014
|
+
}, X = {
|
|
988
1015
|
/**
|
|
989
1016
|
* 验证手机号
|
|
990
1017
|
*/
|
|
@@ -1021,7 +1048,7 @@ const P = {
|
|
|
1021
1048
|
* 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
|
|
1022
1049
|
*/
|
|
1023
1050
|
decimal: /^0\.(0[1-9]|[1-9][0-9]*)$/
|
|
1024
|
-
},
|
|
1051
|
+
}, G = {
|
|
1025
1052
|
/**
|
|
1026
1053
|
* 通过key值获取 localStorage 中存储的某个值
|
|
1027
1054
|
* @param key 获取的key
|
|
@@ -1068,7 +1095,7 @@ const P = {
|
|
|
1068
1095
|
removeSession(e) {
|
|
1069
1096
|
sessionStorage.removeItem(e);
|
|
1070
1097
|
}
|
|
1071
|
-
},
|
|
1098
|
+
}, Q = {
|
|
1072
1099
|
/**
|
|
1073
1100
|
* 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
|
|
1074
1101
|
* @param str 字符串
|
|
@@ -1151,19 +1178,19 @@ const P = {
|
|
|
1151
1178
|
throw new Error("开始位置小于0或结束位置超出字符串长度或开始位置大于结束位置");
|
|
1152
1179
|
return e.slice(0, n) + "*".repeat(t - n + 1) + e.slice(t);
|
|
1153
1180
|
}
|
|
1154
|
-
},
|
|
1155
|
-
const t = new RegExp("[?&]" + e + "=([^&#]*)", "
|
|
1181
|
+
}, v = (e) => {
|
|
1182
|
+
const t = new RegExp("[?&]" + e + "=([^&#]*)", "gi").exec(window.location.href);
|
|
1156
1183
|
return t ? decodeURIComponent(t[1]) : null;
|
|
1157
1184
|
};
|
|
1158
|
-
function
|
|
1185
|
+
function L(e) {
|
|
1159
1186
|
return new URLSearchParams(window.location.search).get(e);
|
|
1160
1187
|
}
|
|
1161
|
-
const
|
|
1188
|
+
const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1162
1189
|
__proto__: null,
|
|
1163
|
-
getQueryInfoByName:
|
|
1164
|
-
getQueryParam:
|
|
1165
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
1166
|
-
...
|
|
1190
|
+
getQueryInfoByName: v,
|
|
1191
|
+
getQueryParam: L
|
|
1192
|
+
}, Symbol.toStringTag, { value: "Module" })), K = {
|
|
1193
|
+
...O,
|
|
1167
1194
|
/**
|
|
1168
1195
|
* 获取当前域名
|
|
1169
1196
|
* @returns 当前url链接的host信息
|
|
@@ -1178,7 +1205,7 @@ const R = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1178
1205
|
getPath() {
|
|
1179
1206
|
return window.location.pathname;
|
|
1180
1207
|
}
|
|
1181
|
-
},
|
|
1208
|
+
}, ee = {
|
|
1182
1209
|
/**
|
|
1183
1210
|
* 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
|
|
1184
1211
|
* @param list 瀑布流数据-数组
|
|
@@ -1209,33 +1236,33 @@ const R = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1209
1236
|
if (i < s)
|
|
1210
1237
|
a.style.left = (o + c) * i + "px", l[i] = a.offsetHeight;
|
|
1211
1238
|
else {
|
|
1212
|
-
const { index: u, value: d } =
|
|
1239
|
+
const { index: u, value: d } = E.getMinValueAndIndex(l);
|
|
1213
1240
|
a.style.left = (o + c) * u + "px", a.style.top = d + t + "px", l[u] = a.offsetHeight + t + d;
|
|
1214
1241
|
}
|
|
1215
1242
|
}
|
|
1216
1243
|
}
|
|
1217
1244
|
};
|
|
1218
1245
|
export {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1246
|
+
I as Base64Utils,
|
|
1247
|
+
W as MoneyFormatter,
|
|
1248
|
+
E as arrayUtils,
|
|
1249
|
+
C as booleanUtils,
|
|
1250
|
+
k as commonUtils,
|
|
1251
|
+
H as cookieUtils,
|
|
1252
|
+
$ as dateUtils,
|
|
1253
|
+
j as documentUtils,
|
|
1254
|
+
N as downloadUtils,
|
|
1255
|
+
P as echartsUtils,
|
|
1256
|
+
F as letterUtils,
|
|
1257
|
+
V as mapUtils,
|
|
1258
|
+
Y as nameUtils,
|
|
1259
|
+
z as numberUtils,
|
|
1260
|
+
q as objectUtils,
|
|
1261
|
+
Z as phoneUtils,
|
|
1262
|
+
J as randomUtils,
|
|
1263
|
+
X as regexpUtils,
|
|
1264
|
+
G as storageUtils,
|
|
1265
|
+
Q as stringUtils,
|
|
1266
|
+
K as urlUtils,
|
|
1267
|
+
ee as waterfallUtils
|
|
1241
1268
|
};
|
package/dist/utils.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(d=typeof globalThis<"u"?globalThis:d||self,w(d.yhkitUtils={}))})(this,function(d){"use strict";const A=Object.assign({unique(e){return e?Array.from(new Set(e)):[]},isExist(e,n){return!e||!n?!1:e.indexOf(n)!==-1},countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]},shuffle(e){if(!e)return[];for(let n=e.length-1;n>0;n--){const t=Math.floor(Math.random()*(n+1));[e[n],e[t]]=[e[t],e[n]]}return e},getMaxValue(e){return e?Math.max(...e):0},getMinValue(e){return e?Math.min(...e):0},getMinValueAndIndex(e){if(e.length===0)return{value:0,index:0};const n={value:e[0],index:0};for(let t=1,r=e.length;t<r;t++){const o=e[t];n.value>o&&(n.value=o,n.index=t)}return n},getMaxValueAndIndex(e){return e.length===0?{value:0,index:0}:e.reduce((n,t,r)=>t<n.value?{value:t,index:r}:n,{value:e[0],index:0})}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:(e,n="value")=>{if(!e||!e.length)return{};const t={};return e.forEach(r=>{const o=Object.assign({label:r.label,text:r.label},r);t[r[n]]=o}),t}},Symbol.toStringTag,{value:"Module"}))});class M{static BASE64_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";static toBlob(n,t="",r=512){const s=(n.split(",")[1]||n).replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),l=s+c;try{const i=atob(l),h=[];for(let a=0;a<i.length;a+=r){const u=i.slice(a,a+r),f=new Array(u.length);for(let g=0;g<u.length;g++)f[g]=u.charCodeAt(g);const y=new Uint8Array(f);h.push(y)}return new Blob(h,{type:t})}catch(i){return console.error("Failed to convert base64 to blob:",i),null}}static toFile(n,t="file.txt",r="text/plain"){const s=n.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),l=s+c,i=atob(l),h=[];for(let u=0;u<i.length;u+=512){const f=i.slice(u,u+512),y=new Array(f.length);for(let g=0;g<f.length;g++)y[g]=f.charCodeAt(g);h.push(new Uint8Array(y))}const a=new Blob(h,{type:r});return new File([a],t,{type:r})}static encode(n){if(!n)return"";const t=this._stringToUtf8Bytes(n);return this._bytesToBase64(t)}static decode(n){if(!n)return"";n=n.replace(/\s/g,"");const t=this._base64ToBytes(n);return this._utf8BytesToString(t)}static _stringToUtf8Bytes(n){const t=[];for(let r=0;r<n.length;r++){let o=n.charCodeAt(r);if(o<128)t.push(o);else if(o<2048)t.push(192|o>>6),t.push(128|o&63);else if(o<55296||o>=57344)t.push(224|o>>12),t.push(128|o>>6&63),t.push(128|o&63);else{r++;const s=o,c=n.charCodeAt(r);if(isNaN(c))throw new Error("代理对不完整");o=65536+((s&1023)<<10)+(c&1023),t.push(240|o>>18),t.push(128|o>>12&63),t.push(128|o>>6&63),t.push(128|o&63)}}return t}static _utf8BytesToString(n){let t="",r=0;for(;r<n.length;){const o=n[r++];if(o<128)t+=String.fromCharCode(o);else if(o>=192&&o<224){const s=n[r++]&63;t+=String.fromCharCode((o&31)<<6|s)}else if(o>=224&&o<240){const s=n[r++]&63,c=n[r++]&63;t+=String.fromCharCode((o&15)<<12|s<<6|c)}else if(o>=240&&o<248){const s=n[r++]&63,c=n[r++]&63,l=n[r++]&63,i=(o&7)<<18|s<<12|c<<6|l,h=Math.floor((i-65536)/1024)+55296,a=(i-65536)%1024+56320;t+=String.fromCharCode(h,a)}else t+="�"}return t}static _bytesToBase64(n){let t="",r=0;for(;r<n.length;){const o=n[r++],s=r<n.length,c=s?n[r++]:0,l=r<n.length,i=l?n[r++]:0,h=o>>2,a=(o&3)<<4|c>>4,u=(c&15)<<2|i>>6,f=i&63;s?l?t+=this.BASE64_CHARS.charAt(h)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+this.BASE64_CHARS.charAt(f):t+=this.BASE64_CHARS.charAt(h)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+"=":t+=this.BASE64_CHARS.charAt(h)+this.BASE64_CHARS.charAt(a)+"=="}return t}static _base64ToBytes(n){const t=n.length;let r=0;t>=2&&(n[t-1]==="="&&r++,n[t-2]==="="&&r++);const o=Math.floor(t*3/4)-r,s=new Array(o),c=new Array(256).fill(-1);for(let h=0;h<this.BASE64_CHARS.length;h++)c[this.BASE64_CHARS.charCodeAt(h)]=h;let l=0,i=0;for(;i<t;){const h=c[n.charCodeAt(i++)],a=c[n.charCodeAt(i++)],u=i<t?c[n.charCodeAt(i++)]:-1,f=i<t?c[n.charCodeAt(i++)]:-1;if(h===-1||a===-1)throw new Error("无效的 Base64 字符");const y=h<<2|a>>4;if(s[l++]=y,u!==-1){const g=(a&15)<<4|u>>2;if(s[l++]=g,f!==-1){const p=(u&3)<<6|f;s[l++]=p}}}return s}}const S={isEmptyString(e){return typeof e=="string"&&e.trim()===""},isNumber(e){return typeof e=="number"&&!isNaN(e)},isObject(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)},isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},isBoolean(e){return typeof e=="boolean"},isArray(e){return Array.isArray(e)},isFunction(e){return typeof e=="function"},isPromise(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"},isElement(e){return e instanceof Element},isPhone(e){return/^1[3-9]\d{9}$/.test(e)},isEmail(e){return/^[\w.-]+@[\w.-]+\.\w+$/.test(e)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},isImageLoaded(e){return e.complete&&e.naturalWidth!==0},isInViewport(e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(e){return e%4===0&&e%100!==0||e%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},U={getType(e){return Object.prototype.toString.call(e).replace(/\[object\s(\w+)\]/,"$1")}},E={getCookie(e){if(!e)return;const n=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(e,n,t=7){const r=new Date;r.setTime(r.getTime()+t*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},C={getTimeString(e,n=!1){return n?new Date().toLocaleString(e,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(e,n){const t=new Date(e).getTime(),r=new Date(n).getTime();return t>r?Math.abs(Math.floor((t-r)/(24*3600*1e3))):Math.abs(Math.floor((r-t)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(e,n,t){let r=t;for(let o=1;o<n;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:r+=31;break;case 2:S.isLeapYear(e)?r+=29:r+=28;break;default:r+=30;break}return r},getTimeStringAutoShort2(e,n){const t=new Date,r=new Date(e),o=t.getFullYear(),s=t.getMonth()+1,c=t.getDate(),l=r.getFullYear(),i=r.getMonth()+1,h=r.getDate();let a="";const u=n?" "+this.formatDate(r,"hh:mm"):"";if(o===l){const g=t.getTime()-e;if(s===i&&c===h)g<60*1e3?a="刚刚":a=this.formatDate(r,"hh:mm");else{const p=new Date;p.setDate(p.getDate()-1);const b=new Date;if(b.setDate(b.getDate()-2),i===p.getMonth()+1&&h===p.getDate())a="昨天"+u;else if(i===b.getMonth()+1&&h===b.getDate())a="前天"+u;else if(g/36e5<=7*24){const m=new Array(7);m[0]="星期日",m[1]="星期一",m[2]="星期二",m[3]="星期三",m[4]="星期四",m[5]="星期五",m[6]="星期六",a=m[r.getDay()]+u}else a=this.formatDate(r,"yyyy/M/d")+u}}else a=this.formatDate(r,"yyyy/M/d")+u;return a},formatDate(e,n){const t={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(n)&&(n=n.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(const r in t)new RegExp("("+r+")").test(n)&&(n=n.replace(RegExp.$1,RegExp.$1.length===1?t[r]:("00"+t[r]).substr((""+t[r]).length)));return n}},B={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const t=e.getBoundingClientRect(),r=window.pageYOffset||document.documentElement.scrollTop;return t.top+r}let n=0;for(;e;)n+=e.offsetTop,e=e.offsetParent;return n},getScrollValue(){const e={scrollLeft:0,scrollTop:0};return e.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,e.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,e},getPageValue(e){e=e||window.event;const n=e.pageX||e.clientX+this.getScrollValue().scrollLeft,t=e.pageY||e.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:t}},addEventListener(e,n,t){e.addEventListener?e.addEventListener(n,t):e.attachEvent?e.attachEvent("on"+n,t):e["on"+n]=t},getViewportWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},getViewportHeight(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}},D={saveAsBlob(e,n){const t=document.createElement("a"),r=window.URL.createObjectURL(e);t.href=r,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(r),document.body.removeChild(t)},saveAsUrl(e,n){const t=document.createElement("a");t.href=e,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(e),document.body.removeChild(t)}},R={animate(e,n){let t=-1;const r=e.series[0].data.length;let o;o=setInterval(()=>{n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:t}),t=(t+1)%r,n.dispatchAction({type:"highlight",seriesIndex:0,dataIndex:t}),n.dispatchAction({type:"showTip",seriesIndex:0,dataIndex:t}),t>r&&(t=0)},2e3),n.on("mouseover",()=>{clearInterval(o),n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:t})})}},v={sortFromA2Z(e){return e?.length?e.sort((t,r)=>{const o=t.toUpperCase(),s=r.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},x={degrees2Radians(e){return e*Math.PI/180},getDistance(e,n,t,r){const o=this.degrees2Radians(e),s=this.degrees2Radians(t),c=o-s,l=this.degrees2Radians(n)-this.degrees2Radians(r);let i=2*Math.asin(Math.sqrt(Math.pow(Math.sin(c/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(l/2),2)));return i=i*6378.137,i=Math.round(i*1e4)/1e4,i=+i.toFixed(2),console.log("经纬度计算的距离为:"+i),i},calculateDistanceByHaversine(e,n,t="km"){const r=this,o=e.longitude??e.lng,s=e.latitude??e.lat,c=n.longitude??n.lng,l=n.latitude??n.lat;if(o===void 0||s===void 0||c===void 0||l===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const i=6371,h=r.degrees2Radians(s),a=r.degrees2Radians(l),u=r.degrees2Radians(l-s),f=r.degrees2Radians(c-o),y=Math.sin(u/2)*Math.sin(u/2)+Math.cos(h)*Math.cos(a)*Math.sin(f/2)*Math.sin(f/2),g=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),p=i*g;switch(t){case"m":return p*1e3;case"mi":return p*.621371;case"nmi":return p*.539957;default:return p}},calculateDistancesByHaversine(e,n="km",t=!1){if(e.length<2)return{segments:[],total:0};const r=[];let o=0;for(let s=0;s<e.length-1;s++){const c=this.calculateDistanceByHaversine(e[s],e[s+1],n);r.push(c),o+=c}if(t&&e.length>2){const s=this.calculateDistanceByHaversine(e[e.length-1],e[0],n);r.push(s),o+=s}return{segments:r,total:o}}};class O{static toStandardFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(!isFinite(t))throw new Error("输入是无穷大");return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(t){return console.error("格式化失败:",t),"格式错误"}}static toChineseFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(t>9999999999999e-2||t<-9999999999999e-2)throw new Error("输入数字超出范围");const r=t<0,o=Math.abs(t),s=Math.floor(o),c=Math.round((o-s)*100),l=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],i=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],h=["角","分"];let a="",u=s;if(u===0)a=l[0];else{let g=0;for(;u>0;){const p=u%10;p!==0?a=l[p]+i[g]+a:a.charAt(0)!==l[0]&&(a=l[p]+a),u=Math.floor(u/10),g++}a=a.replace(/零+/g,"零"),a=a.replace(/零+$/,"")}let f="";if(c>0){const g=Math.floor(c/10),p=c%10;g>0&&(f+=l[g]+h[0]),p>0&&(f+=l[p]+h[1])}else f="整";let y=(r?"负":"")+a+"圆"+f;return y==="零圆整"&&(y="零圆"),y}catch(t){return console.error("转换失败:",t),"格式错误"}}}const T={desensitizeChineseName(e,n={}){const{keepLength:t=1,keepLast:r=!1}=n;if(!e||e.length===0||e.trim().length===0)throw new Error("姓名不能为空");if(typeof e!="string")throw new Error("姓名必须是字符串");if(e.length<=1)return e;const o=["欧阳","司马","上官","东方","独孤","南宫","闻人","夏侯","诸葛","尉迟","公孙","长孙","宇文","司徒","慕容"];n.compoundSurname&&n.compoundSurname.trim().length>0&&!o.includes(n.compoundSurname)&&o.push(n.compoundSurname);let s="";o.some(l=>e.startsWith(l))?s=o.find(l=>e.startsWith(l))||"":s=e[0]||"";const c=Math.max(t,s.length);if(c>=e.length)return e;if(r&&e.length>2){const l=e.slice(0,c),i=e.slice(-1),h=e.length-c-1;return`${l}${"*".repeat(h)}${i}`}return`${e.slice(0,c)}${"*".repeat(e.length-c)}`}},_={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"})),isNumber(e){return typeof e=="number"&&!isNaN(e)}},L={isEmptyObject(e){return!e||JSON.stringify(e)==="{}"?!0:Object.keys(e).length===0&&e.constructor===Object},copy(e,n){for(const t in e)n[t]=e[t]},deepCopy(e,n){for(const t in e){const r=e[t];r instanceof Object?(n[t]={},this.deepCopy(r,n[t])):r instanceof Array?(n[t]=[],this.deepCopy(r,n[t])):n[t]=e[t]}}},j={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},k={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(e,n){return Math.floor(Math.random()*(n-e+1))+e},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},I={mobile:/^1[3-9]\d{9}$/,email:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,chinese:/^[\u4e00-\u9fa5]+$/,english:/^[a-zA-Z]+$/,chineseStart:/^[\u4e00-\u9fa5]+\w*$/,integer:/^\d+$/,integerAndzero:/^(0|[1-9]+[0-9]*)$/,strongPassword:/^(?!.*[\s\p{C}])(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[\d\W])|(?=.*\d)(?=.*[^\w\s])).{8,}$/u,decimal:/^0\.(0[1-9]|[1-9][0-9]*)$/},H={getLocal(e){return localStorage.getItem(e)},setLocal(e,n){localStorage.setItem(e,n)},removeLocal(e){localStorage.removeItem(e)},getSession(e){return sessionStorage.getItem(e)},setSession(e,n){sessionStorage.setItem(e,n)},removeSession(e){sessionStorage.removeItem(e)}},$={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1},includes(e,n){return!e||!n?!1:e.includes(n)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},getMaxTimesAndVal(e){const n=[0,""],t={};for(let s=0;s<e.length;s++){const c=e.charAt(s);t[c]?t[c]++:t[c]=1}let r=1;for(const s in t)r<t[s]&&(r=t[s]);const o=[];for(const s in t)r==t[s]&&o.push(s);return n[0]=r,n[1]=o.join(),n},mask(e,n,t){if(!e)throw new Error("字符串为空");if(typeof n!="number"||typeof t!="number")throw new Error("开始位置或结束位置为空");if(n<0||t>e.length||n>t)throw new Error("开始位置小于0或结束位置超出字符串长度或开始位置大于结束位置");return e.slice(0,n)+"*".repeat(t-n+1)+e.slice(t)}},N=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function P(e){return new URLSearchParams(window.location.search).get(e)}const F={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:N,getQueryParam:P},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},V={toList(e,n=2){console.log(e,n);const t={};for(let o=0;o<n;o++)t[o]=[];e.forEach((o,s)=>t[s%n].push(o));const r=[];for(const o in t)r.push(...t[o]);return r},jsLayout(e,n,t){const r=e.offsetWidth,o=n[0].offsetWidth,s=parseInt((r/o).toString()),c=(r-o*s)/(s-1),l=[];for(let i=0,h=n.length;i<h;i++){const a=n[i];if(i<s)a.style.left=(o+c)*i+"px",l[i]=a.offsetHeight;else{const{index:u,value:f}=A.getMinValueAndIndex(l);a.style.left=(o+c)*u+"px",a.style.top=f+t+"px",l[u]=a.offsetHeight+t+f}}}};d.Base64Utils=M,d.MoneyFormatter=O,d.arrayUtils=A,d.booleanUtils=S,d.commonUtils=U,d.cookieUtils=E,d.dateUtils=C,d.documentUtils=B,d.downloadUtils=D,d.echartsUtils=R,d.letterUtils=v,d.mapUtils=x,d.nameUtils=T,d.numberUtils=_,d.objectUtils=L,d.phoneUtils=j,d.randomUtils=k,d.regexpUtils=I,d.storageUtils=H,d.stringUtils=$,d.urlUtils=F,d.waterfallUtils=V,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(h=typeof globalThis<"u"?globalThis:h||self,w(h.yhkitUtils={}))})(this,function(h){"use strict";const A={...{toEnumObj(e,n="value"){if(!e||!e.length)return{};const t={};return e.forEach(r=>{const o=Object.assign({label:r.label,text:r.label},r);t[r[n]]=o}),t}},...{uniqueBySet(e){return e?Array.from(new Set(e)):[]}},...{isExistByIndexOf(e,n){return!e||!n?!1:e.indexOf(n)!==-1},isExistByIncludes(e,n){return!e||!n?!1:e.includes(n)}},...{sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]},shuffle(e){if(!e)return[];for(let n=e.length-1;n>0;n--){const t=Math.floor(Math.random()*(n+1));[e[n],e[t]]=[e[t],e[n]]}return e}},...{getMaxValue(e){return e?Math.max(...e):0},getMinValue(e){return e?Math.min(...e):0},getMinValueAndIndex(e){if(e.length===0)return{value:0,index:0};const n={value:e[0],index:0};for(let t=1,r=e.length;t<r;t++){const o=e[t];n.value>o&&(n.value=o,n.index=t)}return n},getMaxValueAndIndex(e){return e.length===0?{value:0,index:0}:e.reduce((n,t,r)=>t<n.value?{value:t,index:r}:n,{value:e[0],index:0})}},...{countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r}}};class M{static BASE64_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";static toBlob(n,t="",r=512){const s=(n.split(",")[1]||n).replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),l=s+c;try{const i=atob(l),d=[];for(let a=0;a<i.length;a+=r){const u=i.slice(a,a+r),f=new Array(u.length);for(let g=0;g<u.length;g++)f[g]=u.charCodeAt(g);const p=new Uint8Array(f);d.push(p)}return new Blob(d,{type:t})}catch(i){return console.error("Failed to convert base64 to blob:",i),null}}static toFile(n,t="file.txt",r="text/plain"){const s=n.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),l=s+c,i=atob(l),d=[];for(let u=0;u<i.length;u+=512){const f=i.slice(u,u+512),p=new Array(f.length);for(let g=0;g<f.length;g++)p[g]=f.charCodeAt(g);d.push(new Uint8Array(p))}const a=new Blob(d,{type:r});return new File([a],t,{type:r})}static encode(n){if(!n)return"";const t=this._stringToUtf8Bytes(n);return this._bytesToBase64(t)}static decode(n){if(!n)return"";n=n.replace(/\s/g,"");const t=this._base64ToBytes(n);return this._utf8BytesToString(t)}static _stringToUtf8Bytes(n){const t=[];for(let r=0;r<n.length;r++){let o=n.charCodeAt(r);if(o<128)t.push(o);else if(o<2048)t.push(192|o>>6),t.push(128|o&63);else if(o<55296||o>=57344)t.push(224|o>>12),t.push(128|o>>6&63),t.push(128|o&63);else{r++;const s=o,c=n.charCodeAt(r);if(isNaN(c))throw new Error("代理对不完整");o=65536+((s&1023)<<10)+(c&1023),t.push(240|o>>18),t.push(128|o>>12&63),t.push(128|o>>6&63),t.push(128|o&63)}}return t}static _utf8BytesToString(n){let t="",r=0;for(;r<n.length;){const o=n[r++];if(o<128)t+=String.fromCharCode(o);else if(o>=192&&o<224){const s=n[r++]&63;t+=String.fromCharCode((o&31)<<6|s)}else if(o>=224&&o<240){const s=n[r++]&63,c=n[r++]&63;t+=String.fromCharCode((o&15)<<12|s<<6|c)}else if(o>=240&&o<248){const s=n[r++]&63,c=n[r++]&63,l=n[r++]&63,i=(o&7)<<18|s<<12|c<<6|l,d=Math.floor((i-65536)/1024)+55296,a=(i-65536)%1024+56320;t+=String.fromCharCode(d,a)}else t+="�"}return t}static _bytesToBase64(n){let t="",r=0;for(;r<n.length;){const o=n[r++],s=r<n.length,c=s?n[r++]:0,l=r<n.length,i=l?n[r++]:0,d=o>>2,a=(o&3)<<4|c>>4,u=(c&15)<<2|i>>6,f=i&63;s?l?t+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+this.BASE64_CHARS.charAt(f):t+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+"=":t+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+"=="}return t}static _base64ToBytes(n){const t=n.length;let r=0;t>=2&&(n[t-1]==="="&&r++,n[t-2]==="="&&r++);const o=Math.floor(t*3/4)-r,s=new Array(o),c=new Array(256).fill(-1);for(let d=0;d<this.BASE64_CHARS.length;d++)c[this.BASE64_CHARS.charCodeAt(d)]=d;let l=0,i=0;for(;i<t;){const d=c[n.charCodeAt(i++)],a=c[n.charCodeAt(i++)],u=i<t?c[n.charCodeAt(i++)]:-1,f=i<t?c[n.charCodeAt(i++)]:-1;if(d===-1||a===-1)throw new Error("无效的 Base64 字符");const p=d<<2|a>>4;if(s[l++]=p,u!==-1){const g=(a&15)<<4|u>>2;if(s[l++]=g,f!==-1){const y=(u&3)<<6|f;s[l++]=y}}}return s}}const S={isEmptyString(e){return typeof e=="string"&&e.trim()===""},isNumber(e){return typeof e=="number"&&!isNaN(e)},isObject(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)},isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},isBoolean(e){return typeof e=="boolean"},isArray(e){return Array.isArray(e)},isFunction(e){return typeof e=="function"},isPromise(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"},isElement(e){return e instanceof Element},isPhone(e){return/^1[3-9]\d{9}$/.test(e)},isEmail(e){return/^[\w.-]+@[\w.-]+\.\w+$/.test(e)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},isImageLoaded(e){return e.complete&&e.naturalWidth!==0},isInViewport(e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(e){return e%4===0&&e%100!==0||e%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},U={getType(e){return Object.prototype.toString.call(e).replace(/\[object\s(\w+)\]/,"$1")}},E={getCookie(e){if(!e)return;const n=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(e,n,t=7){const r=new Date;r.setTime(r.getTime()+t*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},B={getTimeString(e,n=!1){return n?new Date().toLocaleString(e,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(e,n){const t=new Date(e).getTime(),r=new Date(n).getTime();return t>r?Math.abs(Math.floor((t-r)/(24*3600*1e3))):Math.abs(Math.floor((r-t)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(e,n,t){let r=t;for(let o=1;o<n;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:r+=31;break;case 2:S.isLeapYear(e)?r+=29:r+=28;break;default:r+=30;break}return r},getTimeStringAutoShort2(e,n){const t=new Date,r=new Date(e),o=t.getFullYear(),s=t.getMonth()+1,c=t.getDate(),l=r.getFullYear(),i=r.getMonth()+1,d=r.getDate();let a="";const u=n?" "+this.formatDate(r,"hh:mm"):"";if(o===l){const g=t.getTime()-e;if(s===i&&c===d)g<60*1e3?a="刚刚":a=this.formatDate(r,"hh:mm");else{const y=new Date;y.setDate(y.getDate()-1);const b=new Date;if(b.setDate(b.getDate()-2),i===y.getMonth()+1&&d===y.getDate())a="昨天"+u;else if(i===b.getMonth()+1&&d===b.getDate())a="前天"+u;else if(g/36e5<=7*24){const m=new Array(7);m[0]="星期日",m[1]="星期一",m[2]="星期二",m[3]="星期三",m[4]="星期四",m[5]="星期五",m[6]="星期六",a=m[r.getDay()]+u}else a=this.formatDate(r,"yyyy/M/d")+u}}else a=this.formatDate(r,"yyyy/M/d")+u;return a},formatDate(e,n){const t={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(n)&&(n=n.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(const r in t)new RegExp("("+r+")").test(n)&&(n=n.replace(RegExp.$1,RegExp.$1.length===1?t[r]:("00"+t[r]).substr((""+t[r]).length)));return n}},C={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const t=e.getBoundingClientRect(),r=window.pageYOffset||document.documentElement.scrollTop;return t.top+r}let n=0;for(;e;)n+=e.offsetTop,e=e.offsetParent;return n},getScrollValue(){const e={scrollLeft:0,scrollTop:0};return e.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,e.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,e},getPageValue(e){e=e||window.event;const n=e.pageX||e.clientX+this.getScrollValue().scrollLeft,t=e.pageY||e.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:t}},addEventListener(e,n,t){e.addEventListener?e.addEventListener(n,t):e.attachEvent?e.attachEvent("on"+n,t):e["on"+n]=t},getViewportWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},getViewportHeight(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}},x={saveAsBlob(e,n){const t=document.createElement("a"),r=window.URL.createObjectURL(e);t.href=r,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(r),document.body.removeChild(t)},saveAsUrl(e,n){const t=document.createElement("a");t.href=e,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(e),document.body.removeChild(t)}},D={animate(e,n){let t=-1;const r=e.series[0].data.length;let o;o=setInterval(()=>{n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:t}),t=(t+1)%r,n.dispatchAction({type:"highlight",seriesIndex:0,dataIndex:t}),n.dispatchAction({type:"showTip",seriesIndex:0,dataIndex:t}),t>r&&(t=0)},2e3),n.on("mouseover",()=>{clearInterval(o),n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:t})})}},R={sortFromA2Z(e){return e?.length?e.sort((t,r)=>{const o=t.toUpperCase(),s=r.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},v={degrees2Radians(e){return e*Math.PI/180},getDistance(e,n,t,r){const o=this.degrees2Radians(e),s=this.degrees2Radians(t),c=o-s,l=this.degrees2Radians(n)-this.degrees2Radians(r);let i=2*Math.asin(Math.sqrt(Math.pow(Math.sin(c/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(l/2),2)));return i=i*6378.137,i=Math.round(i*1e4)/1e4,i=+i.toFixed(2),console.log("经纬度计算的距离为:"+i),i},calculateDistanceByHaversine(e,n,t="km"){const r=this,o=e.longitude??e.lng,s=e.latitude??e.lat,c=n.longitude??n.lng,l=n.latitude??n.lat;if(o===void 0||s===void 0||c===void 0||l===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const i=6371,d=r.degrees2Radians(s),a=r.degrees2Radians(l),u=r.degrees2Radians(l-s),f=r.degrees2Radians(c-o),p=Math.sin(u/2)*Math.sin(u/2)+Math.cos(d)*Math.cos(a)*Math.sin(f/2)*Math.sin(f/2),g=2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p)),y=i*g;switch(t){case"m":return y*1e3;case"mi":return y*.621371;case"nmi":return y*.539957;default:return y}},calculateDistancesByHaversine(e,n="km",t=!1){if(e.length<2)return{segments:[],total:0};const r=[];let o=0;for(let s=0;s<e.length-1;s++){const c=this.calculateDistanceByHaversine(e[s],e[s+1],n);r.push(c),o+=c}if(t&&e.length>2){const s=this.calculateDistanceByHaversine(e[e.length-1],e[0],n);r.push(s),o+=s}return{segments:r,total:o}}};class T{static toStandardFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(!isFinite(t))throw new Error("输入是无穷大");return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(t){return console.error("格式化失败:",t),"格式错误"}}static toChineseFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(t>9999999999999e-2||t<-9999999999999e-2)throw new Error("输入数字超出范围");const r=t<0,o=Math.abs(t),s=Math.floor(o),c=Math.round((o-s)*100),l=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],i=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],d=["角","分"];let a="",u=s;if(u===0)a=l[0];else{let g=0;for(;u>0;){const y=u%10;y!==0?a=l[y]+i[g]+a:a.charAt(0)!==l[0]&&(a=l[y]+a),u=Math.floor(u/10),g++}a=a.replace(/零+/g,"零"),a=a.replace(/零+$/,"")}let f="";if(c>0){const g=Math.floor(c/10),y=c%10;g>0&&(f+=l[g]+d[0]),y>0&&(f+=l[y]+d[1])}else f="整";let p=(r?"负":"")+a+"圆"+f;return p==="零圆整"&&(p="零圆"),p}catch(t){return console.error("转换失败:",t),"格式错误"}}}const L={desensitizeChineseName(e,n={}){const{keepLength:t=1,keepLast:r=!1}=n;if(!e||e.length===0||e.trim().length===0)throw new Error("姓名不能为空");if(typeof e!="string")throw new Error("姓名必须是字符串");if(e.length<=1)return e;const o=["欧阳","司马","上官","东方","独孤","南宫","闻人","夏侯","诸葛","尉迟","公孙","长孙","宇文","司徒","慕容"];n.compoundSurname&&n.compoundSurname.trim().length>0&&!o.includes(n.compoundSurname)&&o.push(n.compoundSurname);let s="";o.some(l=>e.startsWith(l))?s=o.find(l=>e.startsWith(l))||"":s=e[0]||"";const c=Math.max(t,s.length);if(c>=e.length)return e;if(r&&e.length>2){const l=e.slice(0,c),i=e.slice(-1),d=e.length-c-1;return`${l}${"*".repeat(d)}${i}`}return`${e.slice(0,c)}${"*".repeat(e.length-c)}`}},O={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"})),isNumber(e){return typeof e=="number"&&!isNaN(e)}},_={isEmptyObject(e){return!e||JSON.stringify(e)==="{}"?!0:Object.keys(e).length===0&&e.constructor===Object},copy(e,n){for(const t in e)n[t]=e[t]},deepCopy(e,n){for(const t in e){const r=e[t];r instanceof Object?(n[t]={},this.deepCopy(r,n[t])):r instanceof Array?(n[t]=[],this.deepCopy(r,n[t])):n[t]=e[t]}}},I={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},k={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(e,n){return Math.floor(Math.random()*(n-e+1))+e},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},j={mobile:/^1[3-9]\d{9}$/,email:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,chinese:/^[\u4e00-\u9fa5]+$/,english:/^[a-zA-Z]+$/,chineseStart:/^[\u4e00-\u9fa5]+\w*$/,integer:/^\d+$/,integerAndzero:/^(0|[1-9]+[0-9]*)$/,strongPassword:/^(?!.*[\s\p{C}])(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[\d\W])|(?=.*\d)(?=.*[^\w\s])).{8,}$/u,decimal:/^0\.(0[1-9]|[1-9][0-9]*)$/},H={getLocal(e){return localStorage.getItem(e)},setLocal(e,n){localStorage.setItem(e,n)},removeLocal(e){localStorage.removeItem(e)},getSession(e){return sessionStorage.getItem(e)},setSession(e,n){sessionStorage.setItem(e,n)},removeSession(e){sessionStorage.removeItem(e)}},$={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1},includes(e,n){return!e||!n?!1:e.includes(n)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},getMaxTimesAndVal(e){const n=[0,""],t={};for(let s=0;s<e.length;s++){const c=e.charAt(s);t[c]?t[c]++:t[c]=1}let r=1;for(const s in t)r<t[s]&&(r=t[s]);const o=[];for(const s in t)r==t[s]&&o.push(s);return n[0]=r,n[1]=o.join(),n},mask(e,n,t){if(!e)throw new Error("字符串为空");if(typeof n!="number"||typeof t!="number")throw new Error("开始位置或结束位置为空");if(n<0||t>e.length||n>t)throw new Error("开始位置小于0或结束位置超出字符串长度或开始位置大于结束位置");return e.slice(0,n)+"*".repeat(t-n+1)+e.slice(t)}},N=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","gi").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function P(e){return new URLSearchParams(window.location.search).get(e)}const F={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:N,getQueryParam:P},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},V={toList(e,n=2){console.log(e,n);const t={};for(let o=0;o<n;o++)t[o]=[];e.forEach((o,s)=>t[s%n].push(o));const r=[];for(const o in t)r.push(...t[o]);return r},jsLayout(e,n,t){const r=e.offsetWidth,o=n[0].offsetWidth,s=parseInt((r/o).toString()),c=(r-o*s)/(s-1),l=[];for(let i=0,d=n.length;i<d;i++){const a=n[i];if(i<s)a.style.left=(o+c)*i+"px",l[i]=a.offsetHeight;else{const{index:u,value:f}=A.getMinValueAndIndex(l);a.style.left=(o+c)*u+"px",a.style.top=f+t+"px",l[u]=a.offsetHeight+t+f}}}};h.Base64Utils=M,h.MoneyFormatter=T,h.arrayUtils=A,h.booleanUtils=S,h.commonUtils=U,h.cookieUtils=E,h.dateUtils=B,h.documentUtils=C,h.downloadUtils=x,h.echartsUtils=D,h.letterUtils=R,h.mapUtils=v,h.nameUtils=L,h.numberUtils=O,h.objectUtils=_,h.phoneUtils=I,h.randomUtils=k,h.regexpUtils=j,h.storageUtils=H,h.stringUtils=$,h.urlUtils=F,h.waterfallUtils=V,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
/**
|
|
3
|
+
* 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
|
|
4
|
+
* @param arr 数组
|
|
5
|
+
* @param target 目标元素
|
|
6
|
+
* @returns 出现次数
|
|
7
|
+
*/
|
|
8
|
+
countOfAppear<T>(arr: T[], target: T): number;
|
|
9
|
+
/**
|
|
10
|
+
* 查找某个元素在数组中重复出现的位置
|
|
11
|
+
* @param array 数组
|
|
12
|
+
* @param element 元素
|
|
13
|
+
* @returns 位置数组
|
|
14
|
+
*/
|
|
15
|
+
indexsOfAppear<T>(array: T[], element: T): number[];
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IOptionItem, TValueEnum } from "@yh-kit/types";
|
|
2
|
+
/** 数组转对象 */
|
|
3
|
+
declare const _default: {
|
|
4
|
+
/**
|
|
5
|
+
* 数组转枚举对象
|
|
6
|
+
* @param arr 数组
|
|
7
|
+
* @param valueKey 值键名。不传,默认值为"value"。
|
|
8
|
+
* @returns 枚举对象。键为数组元素的valueKey值,值为数组元素。
|
|
9
|
+
*/
|
|
10
|
+
toEnumObj(arr: IOptionItem[], valueKey?: string): TValueEnum;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
/**
|
|
3
|
+
* 判断某元素是否在存在于数组中(indexOf方法)
|
|
4
|
+
* @param arr 数组
|
|
5
|
+
* @param element 查询元素
|
|
6
|
+
* @returns 是否存在。true 存在;false 不存在
|
|
7
|
+
*/
|
|
8
|
+
isExistByIndexOf<T>(arr: T[], element: T): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 判断某元素是否在存在于数组中(includes方法)
|
|
11
|
+
* @param arr 数组
|
|
12
|
+
* @param element 查询元素
|
|
13
|
+
* @returns 是否存在。true 存在;false 不存在
|
|
14
|
+
*/
|
|
15
|
+
isExistByIncludes<T>(arr: T[], element: T): boolean;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
/**
|
|
3
|
+
* 获取数组中的最大值
|
|
4
|
+
* @param arr 数组
|
|
5
|
+
* @returns 最大值
|
|
6
|
+
*/
|
|
7
|
+
getMaxValue(arr: number[]): number;
|
|
8
|
+
/**
|
|
9
|
+
* 获取数组中的最小值
|
|
10
|
+
* @param arr 数组
|
|
11
|
+
* @returns 最小值
|
|
12
|
+
*/
|
|
13
|
+
getMinValue(arr: number[]): number;
|
|
14
|
+
/**
|
|
15
|
+
* 获取数组中的最小值和索引
|
|
16
|
+
* @param array 数组
|
|
17
|
+
* @returns 最小值和索引
|
|
18
|
+
*/
|
|
19
|
+
getMinValueAndIndex(array: number[]): {
|
|
20
|
+
value: number;
|
|
21
|
+
index: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 获取数组中的最大值和索引
|
|
25
|
+
* @param arr 数组
|
|
26
|
+
* @returns 最大值和索引
|
|
27
|
+
*/
|
|
28
|
+
getMaxValueAndIndex(arr: number[]): {
|
|
29
|
+
value: number;
|
|
30
|
+
index: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数组相关操作工具函数
|
|
3
|
+
* @namespace arrayUtils
|
|
4
|
+
*/
|
|
5
|
+
export declare const arrayUtils: {
|
|
6
|
+
readonly countOfAppear: <T>(arr: T[], target: T) => number;
|
|
7
|
+
readonly indexsOfAppear: <T>(array: T[], element: T) => number[];
|
|
8
|
+
readonly getMaxValue: (arr: number[]) => number;
|
|
9
|
+
readonly getMinValue: (arr: number[]) => number;
|
|
10
|
+
readonly getMinValueAndIndex: (array: number[]) => {
|
|
11
|
+
value: number;
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
readonly getMaxValueAndIndex: (arr: number[]) => {
|
|
15
|
+
value: number;
|
|
16
|
+
index: number;
|
|
17
|
+
};
|
|
18
|
+
readonly sort: <T>(arr: T[], order?: "asc" | "desc") => T[];
|
|
19
|
+
readonly shuffle: <T>(arr: T[]) => T[];
|
|
20
|
+
readonly isExistByIndexOf: <T>(arr: T[], element: T) => boolean;
|
|
21
|
+
readonly isExistByIncludes: <T>(arr: T[], element: T) => boolean;
|
|
22
|
+
readonly uniqueBySet: <T>(arr: T[]) => T[];
|
|
23
|
+
readonly toEnumObj: (arr: import("@yh-kit/types").IOptionItem[], valueKey?: string) => import("@yh-kit/types").TValueEnum;
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
/**
|
|
3
|
+
* 数组排序-默认升序
|
|
4
|
+
* @param arr 数组
|
|
5
|
+
* @param order 排序方式:asc 升序;desc 降序
|
|
6
|
+
* @returns 排序后的数组
|
|
7
|
+
*/
|
|
8
|
+
sort<T>(arr: T[], order?: "asc" | "desc"): T[];
|
|
9
|
+
/**
|
|
10
|
+
* 数组乱序(洗牌算法)
|
|
11
|
+
* 1. 从数组的最后一个元素开始,将其与随机位置的元素交换位置。
|
|
12
|
+
* 2. 然后,从倒数第二个元素开始,将其与随机位置的元素交换位置。
|
|
13
|
+
* 3. 以此类推,直到第一个元素。
|
|
14
|
+
* 4. 这样,数组中的元素就会被随机打乱顺序。
|
|
15
|
+
* 5. 注意,这个算法会改变原数组。如果不想改变原数组,可以先复制一份再进行操作。
|
|
16
|
+
* 6. 时间复杂度:O(n)
|
|
17
|
+
* @param arr 数组
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
shuffle<T>(arr: T[]): T[];
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as query from "./query";
|
|
1
2
|
/**
|
|
2
3
|
* url链接信息相关操作工具函数
|
|
3
4
|
*/
|
|
@@ -6,12 +7,12 @@ export declare const urlUtils: {
|
|
|
6
7
|
* 获取当前域名
|
|
7
8
|
* @returns 当前url链接的host信息
|
|
8
9
|
*/
|
|
9
|
-
getHost()
|
|
10
|
+
readonly getHost: () => string;
|
|
10
11
|
/**
|
|
11
12
|
* 获取当前页面路径
|
|
12
13
|
* @returns 当前url链接的pathname信息
|
|
13
14
|
*/
|
|
14
|
-
getPath()
|
|
15
|
-
getQueryParam
|
|
16
|
-
getQueryInfoByName: (name: string) => string | null;
|
|
15
|
+
readonly getPath: () => string;
|
|
16
|
+
readonly getQueryParam: typeof query.getQueryParam;
|
|
17
|
+
readonly getQueryInfoByName: (name: string) => string | null;
|
|
17
18
|
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 枚举对象类型
|
|
3
|
-
* @example
|
|
4
|
-
* ```ts
|
|
5
|
-
* const enumObj = {
|
|
6
|
-
* 1: { key: 1, label: '男', text: '男' },
|
|
7
|
-
* 2: { key: 1, label: '女',text: '女' },
|
|
8
|
-
* } as TValueEnum;
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export type TValueEnum = Record<string | number | symbol, {
|
|
12
|
-
text: string;
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
}>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IOptionItem, TValueEnum } from "../../../typings/src";
|
|
2
|
-
/**
|
|
3
|
-
* 数组转枚举对象
|
|
4
|
-
* @param arr 数组
|
|
5
|
-
* @param valueKey 值键名。不传,默认值为"value"。
|
|
6
|
-
* @returns 枚举对象。键为数组元素的valueKey值,值为数组元素。
|
|
7
|
-
*/
|
|
8
|
-
export declare const toEnumObj: (arr: IOptionItem[], valueKey?: string) => TValueEnum;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 数组相关操作工具函数
|
|
3
|
-
*/
|
|
4
|
-
export declare const arrayUtils: {
|
|
5
|
-
/**
|
|
6
|
-
* 数组去重
|
|
7
|
-
* @param arr 数组
|
|
8
|
-
* @returns 去重后的数组
|
|
9
|
-
*/
|
|
10
|
-
unique<T>(arr: T[]): T[];
|
|
11
|
-
/**
|
|
12
|
-
* 判断某元素是否在数组中
|
|
13
|
-
* @param arr 数组
|
|
14
|
-
* @param element 查询元素
|
|
15
|
-
* @returns 是否存在。true 存在;false 不存在
|
|
16
|
-
*/
|
|
17
|
-
isExist<T>(arr: T[], element: T): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
|
|
20
|
-
* @param arr 数组
|
|
21
|
-
* @param target 目标元素
|
|
22
|
-
* @returns 出现次数
|
|
23
|
-
*/
|
|
24
|
-
countOfAppear<T>(arr: T[], target: T): number;
|
|
25
|
-
/**
|
|
26
|
-
* 查找某个元素在数组中重复出现的位置
|
|
27
|
-
* @param array 数组
|
|
28
|
-
* @param element 元素
|
|
29
|
-
* @returns 位置数组
|
|
30
|
-
*/
|
|
31
|
-
indexsOfAppear<T>(array: T[], element: T): number[];
|
|
32
|
-
/**
|
|
33
|
-
* 数组排序-默认升序
|
|
34
|
-
* @param arr 数组
|
|
35
|
-
* @param order 排序方式:asc 升序;desc 降序
|
|
36
|
-
* @returns 排序后的数组
|
|
37
|
-
*/
|
|
38
|
-
sort<T>(arr: T[], order?: "asc" | "desc"): T[];
|
|
39
|
-
/**
|
|
40
|
-
* 数组乱序(洗牌算法)
|
|
41
|
-
* 1. 从数组的最后一个元素开始,将其与随机位置的元素交换位置。
|
|
42
|
-
* 2. 然后,从倒数第二个元素开始,将其与随机位置的元素交换位置。
|
|
43
|
-
* 3. 以此类推,直到第一个元素。
|
|
44
|
-
* 4. 这样,数组中的元素就会被随机打乱顺序。
|
|
45
|
-
* 5. 注意,这个算法会改变原数组。如果不想改变原数组,可以先复制一份再进行操作。
|
|
46
|
-
* 6. 时间复杂度:O(n)
|
|
47
|
-
* @param arr 数组
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
shuffle<T>(arr: T[]): T[];
|
|
51
|
-
/**
|
|
52
|
-
* 获取数组中的最大值
|
|
53
|
-
* @param arr 数组
|
|
54
|
-
* @returns 最大值
|
|
55
|
-
*/
|
|
56
|
-
getMaxValue(arr: number[]): number;
|
|
57
|
-
/**
|
|
58
|
-
* 获取数组中的最小值
|
|
59
|
-
* @param arr 数组
|
|
60
|
-
* @returns 最小值
|
|
61
|
-
*/
|
|
62
|
-
getMinValue(arr: number[]): number;
|
|
63
|
-
/**
|
|
64
|
-
* 获取数组中的最小值和索引
|
|
65
|
-
* @param array 数组
|
|
66
|
-
* @returns 最小值和索引
|
|
67
|
-
*/
|
|
68
|
-
getMinValueAndIndex(array: number[]): {
|
|
69
|
-
value: number;
|
|
70
|
-
index: number;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* 获取数组中的最大值和索引
|
|
74
|
-
* @param arr 数组
|
|
75
|
-
* @returns 最大值和索引
|
|
76
|
-
*/
|
|
77
|
-
getMaxValueAndIndex(arr: number[]): {
|
|
78
|
-
value: number;
|
|
79
|
-
index: number;
|
|
80
|
-
};
|
|
81
|
-
} & {
|
|
82
|
-
toEnumObj: (arr: import("@yh-kit/types").IOptionItem[], valueKey?: string) => import("@yh-kit/types").TValueEnum;
|
|
83
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|