@yh-kit/utils 1.9.0 → 1.10.0
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 +336 -303
- package/dist/utils.umd.cjs +1 -1
- package/package.json +5 -3
- package/types/utils/lib/echarts/index.d.ts +12 -0
- package/types/utils/lib/index.d.ts +1 -0
package/dist/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const y = (
|
|
2
|
-
if (!
|
|
1
|
+
const y = (e) => {
|
|
2
|
+
if (!e || !e.length) return {};
|
|
3
3
|
const n = {};
|
|
4
|
-
return
|
|
5
|
-
const
|
|
6
|
-
n[
|
|
4
|
+
return e.forEach((t) => {
|
|
5
|
+
const o = Object.assign({ label: t.label, text: t.label }, t);
|
|
6
|
+
n[t?.value] = o;
|
|
7
7
|
}), n;
|
|
8
8
|
}, m = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
9
9
|
__proto__: null,
|
|
@@ -15,8 +15,8 @@ const y = (t) => {
|
|
|
15
15
|
* @param arr 数组
|
|
16
16
|
* @returns 去重后的数组
|
|
17
17
|
*/
|
|
18
|
-
unique(
|
|
19
|
-
return
|
|
18
|
+
unique(e) {
|
|
19
|
+
return e ? Array.from(new Set(e)) : [];
|
|
20
20
|
},
|
|
21
21
|
/**
|
|
22
22
|
* 判断某元素是否在数组中
|
|
@@ -24,8 +24,8 @@ const y = (t) => {
|
|
|
24
24
|
* @param element 查询元素
|
|
25
25
|
* @returns 是否存在。true 存在;false 不存在
|
|
26
26
|
*/
|
|
27
|
-
isExist(
|
|
28
|
-
return !
|
|
27
|
+
isExist(e, n) {
|
|
28
|
+
return !e || !n ? !1 : e.indexOf(n) !== -1;
|
|
29
29
|
},
|
|
30
30
|
/**
|
|
31
31
|
* 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
|
|
@@ -33,11 +33,11 @@ const y = (t) => {
|
|
|
33
33
|
* @param target 目标元素
|
|
34
34
|
* @returns 出现次数
|
|
35
35
|
*/
|
|
36
|
-
countOfAppear(
|
|
37
|
-
let
|
|
38
|
-
for (const
|
|
39
|
-
|
|
40
|
-
return
|
|
36
|
+
countOfAppear(e, n) {
|
|
37
|
+
let t = 0;
|
|
38
|
+
for (const o of e)
|
|
39
|
+
o === n && t++;
|
|
40
|
+
return t;
|
|
41
41
|
},
|
|
42
42
|
/**
|
|
43
43
|
* 查找某个元素在数组中重复出现的位置
|
|
@@ -45,13 +45,13 @@ const y = (t) => {
|
|
|
45
45
|
* @param element 元素
|
|
46
46
|
* @returns 位置数组
|
|
47
47
|
*/
|
|
48
|
-
indexsOfAppear(
|
|
49
|
-
let
|
|
50
|
-
const
|
|
48
|
+
indexsOfAppear(e, n) {
|
|
49
|
+
let t = -1;
|
|
50
|
+
const o = [];
|
|
51
51
|
do
|
|
52
|
-
|
|
53
|
-
while (
|
|
54
|
-
return
|
|
52
|
+
t = e.indexOf(n, t + 1), t !== -1 && o.push(t);
|
|
53
|
+
while (t !== -1);
|
|
54
|
+
return o;
|
|
55
55
|
},
|
|
56
56
|
/**
|
|
57
57
|
* 数组排序-默认升序
|
|
@@ -59,8 +59,8 @@ const y = (t) => {
|
|
|
59
59
|
* @param order 排序方式:asc 升序;desc 降序
|
|
60
60
|
* @returns 排序后的数组
|
|
61
61
|
*/
|
|
62
|
-
sort(
|
|
63
|
-
return
|
|
62
|
+
sort(e, n = "asc") {
|
|
63
|
+
return e ? e.sort((t, o) => n === "asc" ? t > o ? 1 : -1 : t < o ? 1 : -1) : [];
|
|
64
64
|
},
|
|
65
65
|
/**
|
|
66
66
|
* 数组乱序(洗牌算法)
|
|
@@ -73,47 +73,47 @@ const y = (t) => {
|
|
|
73
73
|
* @param arr 数组
|
|
74
74
|
* @returns
|
|
75
75
|
*/
|
|
76
|
-
shuffle(
|
|
77
|
-
if (!
|
|
76
|
+
shuffle(e) {
|
|
77
|
+
if (!e)
|
|
78
78
|
return [];
|
|
79
|
-
for (let n =
|
|
80
|
-
const
|
|
81
|
-
[
|
|
79
|
+
for (let n = e.length - 1; n > 0; n--) {
|
|
80
|
+
const t = Math.floor(Math.random() * (n + 1));
|
|
81
|
+
[e[n], e[t]] = [e[t], e[n]];
|
|
82
82
|
}
|
|
83
|
-
return
|
|
83
|
+
return e;
|
|
84
84
|
},
|
|
85
85
|
/**
|
|
86
86
|
* 获取数组中的最大值
|
|
87
87
|
* @param arr 数组
|
|
88
88
|
* @returns 最大值
|
|
89
89
|
*/
|
|
90
|
-
getMaxValue(
|
|
91
|
-
return
|
|
90
|
+
getMaxValue(e) {
|
|
91
|
+
return e ? Math.max(...e) : 0;
|
|
92
92
|
},
|
|
93
93
|
/**
|
|
94
94
|
* 获取数组中的最小值
|
|
95
95
|
* @param arr 数组
|
|
96
96
|
* @returns 最小值
|
|
97
97
|
*/
|
|
98
|
-
getMinValue(
|
|
99
|
-
return
|
|
98
|
+
getMinValue(e) {
|
|
99
|
+
return e ? Math.min(...e) : 0;
|
|
100
100
|
},
|
|
101
101
|
/**
|
|
102
102
|
* 获取数组中的最小值和索引
|
|
103
103
|
* @param array 数组
|
|
104
104
|
* @returns 最小值和索引
|
|
105
105
|
*/
|
|
106
|
-
getMinValueAndIndex(
|
|
107
|
-
if (
|
|
106
|
+
getMinValueAndIndex(e) {
|
|
107
|
+
if (e.length === 0) return { value: 0, index: 0 };
|
|
108
108
|
const n = {
|
|
109
109
|
/** 最小值 */
|
|
110
|
-
value:
|
|
110
|
+
value: e[0],
|
|
111
111
|
/** 最小值索引 */
|
|
112
112
|
index: 0
|
|
113
113
|
};
|
|
114
|
-
for (let
|
|
115
|
-
const
|
|
116
|
-
n.value >
|
|
114
|
+
for (let t = 1, o = e.length; t < o; t++) {
|
|
115
|
+
const r = e[t];
|
|
116
|
+
n.value > r && (n.value = r, n.index = t);
|
|
117
117
|
}
|
|
118
118
|
return n;
|
|
119
119
|
},
|
|
@@ -122,10 +122,10 @@ const y = (t) => {
|
|
|
122
122
|
* @param arr 数组
|
|
123
123
|
* @returns 最大值和索引
|
|
124
124
|
*/
|
|
125
|
-
getMaxValueAndIndex(
|
|
126
|
-
return
|
|
127
|
-
(n,
|
|
128
|
-
{ value:
|
|
125
|
+
getMaxValueAndIndex(e) {
|
|
126
|
+
return e.length === 0 ? { value: 0, index: 0 } : e.reduce(
|
|
127
|
+
(n, t, o) => t < n.value ? { value: t, index: o } : n,
|
|
128
|
+
{ value: e[0], index: 0 }
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
},
|
|
@@ -145,18 +145,18 @@ class _ {
|
|
|
145
145
|
* @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
|
|
146
146
|
* @returns 返回转换后的Blob对象,如果转换失败,则返回null。
|
|
147
147
|
*/
|
|
148
|
-
static toBlob(n,
|
|
148
|
+
static toBlob(n, t = "", o = 512) {
|
|
149
149
|
const s = (n.split(",")[1] || n).replace(/-/g, "+").replace(/_/g, "/"), c = "=".repeat((4 - s.length % 4) % 4), l = s + c;
|
|
150
150
|
try {
|
|
151
151
|
const i = atob(l), d = [];
|
|
152
|
-
for (let a = 0; a < i.length; a +=
|
|
153
|
-
const u = i.slice(a, a +
|
|
152
|
+
for (let a = 0; a < i.length; a += o) {
|
|
153
|
+
const u = i.slice(a, a + o), h = new Array(u.length);
|
|
154
154
|
for (let f = 0; f < u.length; f++)
|
|
155
155
|
h[f] = u.charCodeAt(f);
|
|
156
156
|
const g = new Uint8Array(h);
|
|
157
157
|
d.push(g);
|
|
158
158
|
}
|
|
159
|
-
return new Blob(d, { type:
|
|
159
|
+
return new Blob(d, { type: t });
|
|
160
160
|
} catch (i) {
|
|
161
161
|
return console.error("Failed to convert base64 to blob:", i), null;
|
|
162
162
|
}
|
|
@@ -171,7 +171,7 @@ class _ {
|
|
|
171
171
|
* @param mimeType MIME类型,默认为"text/plain"。
|
|
172
172
|
* @returns 返回一个File对象,包含解码后的数据。
|
|
173
173
|
*/
|
|
174
|
-
static toFile(n,
|
|
174
|
+
static toFile(n, t = "file.txt", o = "text/plain") {
|
|
175
175
|
const s = n.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), c = "=".repeat((4 - s.length % 4) % 4), l = s + c, i = atob(l), d = [];
|
|
176
176
|
for (let u = 0; u < i.length; u += 512) {
|
|
177
177
|
const h = i.slice(u, u + 512), g = new Array(h.length);
|
|
@@ -179,8 +179,8 @@ class _ {
|
|
|
179
179
|
g[f] = h.charCodeAt(f);
|
|
180
180
|
d.push(new Uint8Array(g));
|
|
181
181
|
}
|
|
182
|
-
const a = new Blob(d, { type:
|
|
183
|
-
return new File([a],
|
|
182
|
+
const a = new Blob(d, { type: o });
|
|
183
|
+
return new File([a], t, { type: o });
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* base64加密 -- 普通字符串转 Base64 编码
|
|
@@ -189,8 +189,8 @@ class _ {
|
|
|
189
189
|
*/
|
|
190
190
|
static encode(n) {
|
|
191
191
|
if (!n) return "";
|
|
192
|
-
const
|
|
193
|
-
return this._bytesToBase64(
|
|
192
|
+
const t = this._stringToUtf8Bytes(n);
|
|
193
|
+
return this._bytesToBase64(t);
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
196
|
* base64解密 -- Base64 编码转普通字符串
|
|
@@ -200,79 +200,79 @@ class _ {
|
|
|
200
200
|
static decode(n) {
|
|
201
201
|
if (!n) return "";
|
|
202
202
|
n = n.replace(/\s/g, "");
|
|
203
|
-
const
|
|
204
|
-
return this._utf8BytesToString(
|
|
203
|
+
const t = this._base64ToBytes(n);
|
|
204
|
+
return this._utf8BytesToString(t);
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
207
|
* 字符串转 UTF-8 字节数组
|
|
208
208
|
*/
|
|
209
209
|
static _stringToUtf8Bytes(n) {
|
|
210
|
-
const
|
|
211
|
-
for (let
|
|
212
|
-
let
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
else if (
|
|
216
|
-
|
|
217
|
-
else if (
|
|
218
|
-
|
|
210
|
+
const t = [];
|
|
211
|
+
for (let o = 0; o < n.length; o++) {
|
|
212
|
+
let r = n.charCodeAt(o);
|
|
213
|
+
if (r < 128)
|
|
214
|
+
t.push(r);
|
|
215
|
+
else if (r < 2048)
|
|
216
|
+
t.push(192 | r >> 6), t.push(128 | r & 63);
|
|
217
|
+
else if (r < 55296 || r >= 57344)
|
|
218
|
+
t.push(224 | r >> 12), t.push(128 | r >> 6 & 63), t.push(128 | r & 63);
|
|
219
219
|
else {
|
|
220
|
-
|
|
221
|
-
const s =
|
|
220
|
+
o++;
|
|
221
|
+
const s = r, c = n.charCodeAt(o);
|
|
222
222
|
if (isNaN(c))
|
|
223
223
|
throw new Error("代理对不完整");
|
|
224
|
-
|
|
224
|
+
r = 65536 + ((s & 1023) << 10) + (c & 1023), t.push(240 | r >> 18), t.push(128 | r >> 12 & 63), t.push(128 | r >> 6 & 63), t.push(128 | r & 63);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
return
|
|
227
|
+
return t;
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
230
|
* UTF-8 字节数组转字符串
|
|
231
231
|
*/
|
|
232
232
|
static _utf8BytesToString(n) {
|
|
233
|
-
let
|
|
234
|
-
for (;
|
|
235
|
-
const
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
else if (
|
|
239
|
-
const s = n[
|
|
240
|
-
|
|
241
|
-
} else if (
|
|
242
|
-
const s = n[
|
|
243
|
-
|
|
244
|
-
} else if (
|
|
245
|
-
const s = n[
|
|
246
|
-
|
|
233
|
+
let t = "", o = 0;
|
|
234
|
+
for (; o < n.length; ) {
|
|
235
|
+
const r = n[o++];
|
|
236
|
+
if (r < 128)
|
|
237
|
+
t += String.fromCharCode(r);
|
|
238
|
+
else if (r >= 192 && r < 224) {
|
|
239
|
+
const s = n[o++] & 63;
|
|
240
|
+
t += String.fromCharCode((r & 31) << 6 | s);
|
|
241
|
+
} else if (r >= 224 && r < 240) {
|
|
242
|
+
const s = n[o++] & 63, c = n[o++] & 63;
|
|
243
|
+
t += String.fromCharCode((r & 15) << 12 | s << 6 | c);
|
|
244
|
+
} else if (r >= 240 && r < 248) {
|
|
245
|
+
const s = n[o++] & 63, c = n[o++] & 63, l = n[o++] & 63, i = (r & 7) << 18 | s << 12 | c << 6 | l, d = Math.floor((i - 65536) / 1024) + 55296, a = (i - 65536) % 1024 + 56320;
|
|
246
|
+
t += String.fromCharCode(d, a);
|
|
247
247
|
} else
|
|
248
|
-
|
|
248
|
+
t += "�";
|
|
249
249
|
}
|
|
250
|
-
return
|
|
250
|
+
return t;
|
|
251
251
|
}
|
|
252
252
|
/**
|
|
253
253
|
* 字节数组转 Base64 编码
|
|
254
254
|
*/
|
|
255
255
|
static _bytesToBase64(n) {
|
|
256
|
-
let
|
|
257
|
-
for (;
|
|
258
|
-
const
|
|
259
|
-
s ? l ?
|
|
256
|
+
let t = "", o = 0;
|
|
257
|
+
for (; o < n.length; ) {
|
|
258
|
+
const r = n[o++], s = o < n.length, c = s ? n[o++] : 0, l = o < n.length, i = l ? n[o++] : 0, d = r >> 2, a = (r & 3) << 4 | c >> 4, u = (c & 15) << 2 | i >> 6, h = i & 63;
|
|
259
|
+
s ? l ? t += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(a) + this.BASE64_CHARS.charAt(u) + this.BASE64_CHARS.charAt(h) : 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) + "==";
|
|
260
260
|
}
|
|
261
|
-
return
|
|
261
|
+
return t;
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
264
|
* Base64 编码转字节数组
|
|
265
265
|
*/
|
|
266
266
|
static _base64ToBytes(n) {
|
|
267
|
-
const
|
|
268
|
-
let
|
|
269
|
-
|
|
270
|
-
const
|
|
267
|
+
const t = n.length;
|
|
268
|
+
let o = 0;
|
|
269
|
+
t >= 2 && (n[t - 1] === "=" && o++, n[t - 2] === "=" && o++);
|
|
270
|
+
const r = Math.floor(t * 3 / 4) - o, s = new Array(r), c = new Array(256).fill(-1);
|
|
271
271
|
for (let d = 0; d < this.BASE64_CHARS.length; d++)
|
|
272
272
|
c[this.BASE64_CHARS.charCodeAt(d)] = d;
|
|
273
273
|
let l = 0, i = 0;
|
|
274
|
-
for (; i <
|
|
275
|
-
const d = c[n.charCodeAt(i++)], a = c[n.charCodeAt(i++)], u = i <
|
|
274
|
+
for (; i < t; ) {
|
|
275
|
+
const d = c[n.charCodeAt(i++)], a = c[n.charCodeAt(i++)], u = i < t ? c[n.charCodeAt(i++)] : -1, h = i < t ? c[n.charCodeAt(i++)] : -1;
|
|
276
276
|
if (d === -1 || a === -1)
|
|
277
277
|
throw new Error("无效的 Base64 字符");
|
|
278
278
|
const g = d << 2 | a >> 4;
|
|
@@ -287,62 +287,62 @@ class _ {
|
|
|
287
287
|
return s;
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
const
|
|
290
|
+
const A = {
|
|
291
291
|
/**
|
|
292
292
|
* 检查是否为空字符串
|
|
293
293
|
* @param str 要检查的字符串
|
|
294
294
|
* @returns 如果字符串为空,则返回 true,否则返回 false
|
|
295
295
|
*/
|
|
296
|
-
isEmptyString(
|
|
297
|
-
return typeof
|
|
296
|
+
isEmptyString(e) {
|
|
297
|
+
return typeof e == "string" && e.trim() === "";
|
|
298
298
|
},
|
|
299
299
|
/**
|
|
300
300
|
* 判断是否为数字
|
|
301
301
|
* @param val 要检查的值
|
|
302
302
|
* @returns 如果值是数字,则返回 true,否则返回 false
|
|
303
303
|
*/
|
|
304
|
-
isNumber(
|
|
305
|
-
return typeof
|
|
304
|
+
isNumber(e) {
|
|
305
|
+
return typeof e == "number" && !isNaN(e);
|
|
306
306
|
},
|
|
307
307
|
/**
|
|
308
308
|
* 判断是否为对象
|
|
309
309
|
* @param val 要检查的值
|
|
310
310
|
* @returns 如果值是对象,则返回 true,否则返回 false
|
|
311
311
|
*/
|
|
312
|
-
isObject(
|
|
313
|
-
return
|
|
312
|
+
isObject(e) {
|
|
313
|
+
return e !== null && typeof e == "object" && !Array.isArray(e);
|
|
314
314
|
},
|
|
315
315
|
/**
|
|
316
316
|
* 判断对象是否为空
|
|
317
317
|
* @param obj 要检查的对象
|
|
318
318
|
* @returns 如果对象为空,则返回 true,否则返回 false
|
|
319
319
|
*/
|
|
320
|
-
isEmptyObject(
|
|
321
|
-
return
|
|
320
|
+
isEmptyObject(e) {
|
|
321
|
+
return e ? Object.keys(e).length === 0 && e.constructor === Object : !0;
|
|
322
322
|
},
|
|
323
323
|
/**
|
|
324
324
|
* 判断是否为布尔值
|
|
325
325
|
* @param val 要检查的值
|
|
326
326
|
* @returns 如果值是布尔值,则返回 true,否则返回 false
|
|
327
327
|
*/
|
|
328
|
-
isBoolean(
|
|
329
|
-
return typeof
|
|
328
|
+
isBoolean(e) {
|
|
329
|
+
return typeof e == "boolean";
|
|
330
330
|
},
|
|
331
331
|
/**
|
|
332
332
|
* 判断是否为数组
|
|
333
333
|
* @param val 要检查的值
|
|
334
334
|
* @returns 如果值是数组,则返回 true,否则返回 false
|
|
335
335
|
*/
|
|
336
|
-
isArray(
|
|
337
|
-
return Array.isArray(
|
|
336
|
+
isArray(e) {
|
|
337
|
+
return Array.isArray(e);
|
|
338
338
|
},
|
|
339
339
|
/**
|
|
340
340
|
* 判断是否为函数
|
|
341
341
|
* @param val 要检查的值
|
|
342
342
|
* @returns
|
|
343
343
|
*/
|
|
344
|
-
isFunction(
|
|
345
|
-
return typeof
|
|
344
|
+
isFunction(e) {
|
|
345
|
+
return typeof e == "function";
|
|
346
346
|
},
|
|
347
347
|
/**
|
|
348
348
|
* 判断是否为 Promise 对象
|
|
@@ -350,41 +350,41 @@ const b = {
|
|
|
350
350
|
* @returns 如果对象是 Promise 对象,则返回 true,否则返回 false
|
|
351
351
|
*/
|
|
352
352
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
353
|
-
isPromise(
|
|
354
|
-
return !!
|
|
353
|
+
isPromise(e) {
|
|
354
|
+
return !!e && (typeof e == "object" || typeof e == "function") && typeof e.then == "function";
|
|
355
355
|
},
|
|
356
356
|
/**
|
|
357
357
|
* 判断是否为 DOM 元素
|
|
358
358
|
* @param obj 要检查的对象
|
|
359
359
|
* @returns 如果对象是 DOM 元素,则返回 true,否则返回 false
|
|
360
360
|
*/
|
|
361
|
-
isElement(
|
|
362
|
-
return
|
|
361
|
+
isElement(e) {
|
|
362
|
+
return e instanceof Element;
|
|
363
363
|
},
|
|
364
364
|
/**
|
|
365
365
|
* 判断手机号格式(中国)
|
|
366
366
|
* @param str 手机号字符串
|
|
367
367
|
* @returns true 表示手机号格式正确,false 表示手机号格式错误
|
|
368
368
|
*/
|
|
369
|
-
isPhone(
|
|
370
|
-
return /^1[3-9]\d{9}$/.test(
|
|
369
|
+
isPhone(e) {
|
|
370
|
+
return /^1[3-9]\d{9}$/.test(e);
|
|
371
371
|
},
|
|
372
372
|
/**
|
|
373
373
|
* 判断邮箱格式
|
|
374
374
|
* @param str 邮箱字符串
|
|
375
375
|
* @returns true 表示邮箱格式正确,false 表示邮箱格式错误
|
|
376
376
|
*/
|
|
377
|
-
isEmail(
|
|
378
|
-
return /^[\w.-]+@[\w.-]+\.\w+$/.test(
|
|
377
|
+
isEmail(e) {
|
|
378
|
+
return /^[\w.-]+@[\w.-]+\.\w+$/.test(e);
|
|
379
379
|
},
|
|
380
380
|
/**
|
|
381
381
|
* 判断字符串是否为 JSON
|
|
382
382
|
* @param str 字符串
|
|
383
383
|
* @returns true 表示是 JSON,false 表示不是 JSON
|
|
384
384
|
*/
|
|
385
|
-
isJSON(
|
|
385
|
+
isJSON(e) {
|
|
386
386
|
try {
|
|
387
|
-
return JSON.parse(
|
|
387
|
+
return JSON.parse(e), !0;
|
|
388
388
|
} catch {
|
|
389
389
|
return !1;
|
|
390
390
|
}
|
|
@@ -397,16 +397,16 @@ const b = {
|
|
|
397
397
|
* const img = new Image();
|
|
398
398
|
* img.src = "URL_ADDRESS * img.src = "https://example.com/image.jpg";
|
|
399
399
|
*/
|
|
400
|
-
isImageLoaded(
|
|
401
|
-
return
|
|
400
|
+
isImageLoaded(e) {
|
|
401
|
+
return e.complete && e.naturalWidth !== 0;
|
|
402
402
|
},
|
|
403
403
|
/**
|
|
404
404
|
* 判断元素是否在可视区域内
|
|
405
405
|
* @param el 元素对象
|
|
406
406
|
* @returns true 表示元素在可视区域内,false 表示元素不在可视区域内
|
|
407
407
|
*/
|
|
408
|
-
isInViewport(
|
|
409
|
-
const n =
|
|
408
|
+
isInViewport(e) {
|
|
409
|
+
const n = e.getBoundingClientRect();
|
|
410
410
|
return n.top >= 0 && n.left >= 0 && n.bottom <= window.innerHeight && n.right <= window.innerWidth;
|
|
411
411
|
},
|
|
412
412
|
/**
|
|
@@ -421,8 +421,8 @@ const b = {
|
|
|
421
421
|
* isLeapYear(2025); // false
|
|
422
422
|
* isLeapYear(2024); // true
|
|
423
423
|
*/
|
|
424
|
-
isLeapYear(
|
|
425
|
-
return
|
|
424
|
+
isLeapYear(e) {
|
|
425
|
+
return e % 4 === 0 && e % 100 !== 0 || e % 400 === 0;
|
|
426
426
|
},
|
|
427
427
|
/**
|
|
428
428
|
* 判断是否为移动端
|
|
@@ -431,15 +431,15 @@ const b = {
|
|
|
431
431
|
isMobile() {
|
|
432
432
|
return /Mobi|Android|iPhone/i.test(navigator.userAgent);
|
|
433
433
|
}
|
|
434
|
-
},
|
|
434
|
+
}, v = {
|
|
435
435
|
/**
|
|
436
436
|
* 通过传入的name获取cookie的值
|
|
437
437
|
* @param name cookie的name
|
|
438
438
|
* @returns cookie的值
|
|
439
439
|
*/
|
|
440
|
-
getCookie(
|
|
441
|
-
if (!
|
|
442
|
-
const n = document.cookie.match(new RegExp("(^| )" +
|
|
440
|
+
getCookie(e) {
|
|
441
|
+
if (!e) return;
|
|
442
|
+
const n = document.cookie.match(new RegExp("(^| )" + e + "=([^;]+)"));
|
|
443
443
|
return n ? decodeURIComponent(n[2]) : null;
|
|
444
444
|
},
|
|
445
445
|
/**
|
|
@@ -449,27 +449,27 @@ const b = {
|
|
|
449
449
|
* @param days cookie的过期时间,默认7天。如果为0,则表示cookie在会话结束时过期。如果为负数,则表示cookie已过期。
|
|
450
450
|
* @returns void
|
|
451
451
|
*/
|
|
452
|
-
setCookie(
|
|
453
|
-
const
|
|
454
|
-
|
|
452
|
+
setCookie(e, n, t = 7) {
|
|
453
|
+
const o = /* @__PURE__ */ new Date();
|
|
454
|
+
o.setTime(o.getTime() + t * 24 * 60 * 60 * 1e3), document.cookie = `${e}=${encodeURIComponent(n)};expires=${o.toUTCString()};path=/`;
|
|
455
455
|
},
|
|
456
456
|
/**
|
|
457
457
|
* 删除cookie
|
|
458
458
|
* @param name cookie的name
|
|
459
459
|
* @returns void
|
|
460
460
|
*/
|
|
461
|
-
deleteCookie(
|
|
462
|
-
this.setCookie(
|
|
461
|
+
deleteCookie(e) {
|
|
462
|
+
this.setCookie(e, "", -1);
|
|
463
463
|
}
|
|
464
|
-
},
|
|
464
|
+
}, O = {
|
|
465
465
|
/**
|
|
466
466
|
* 获取当前时间字符串
|
|
467
467
|
* @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
|
|
468
468
|
* @param hour12 是否使用12小时制。默认false,使用24小时制。
|
|
469
469
|
* @returns 当前时间的字符串。如:'2025/5/27 16:54:45'
|
|
470
470
|
*/
|
|
471
|
-
getTimeString(
|
|
472
|
-
return n ? (/* @__PURE__ */ new Date()).toLocaleString(
|
|
471
|
+
getTimeString(e, n = !1) {
|
|
472
|
+
return n ? (/* @__PURE__ */ new Date()).toLocaleString(e, { hour12: !0 }) : (/* @__PURE__ */ new Date()).toLocaleString("chinese", { hour12: !1 });
|
|
473
473
|
},
|
|
474
474
|
/**
|
|
475
475
|
* 计算两个日期相差天数
|
|
@@ -477,9 +477,9 @@ const b = {
|
|
|
477
477
|
* @param date2 日期2
|
|
478
478
|
* @returns 相差天数
|
|
479
479
|
*/
|
|
480
|
-
diffDays(
|
|
481
|
-
const
|
|
482
|
-
return
|
|
480
|
+
diffDays(e, n) {
|
|
481
|
+
const t = new Date(e).getTime(), o = new Date(n).getTime();
|
|
482
|
+
return t > o ? Math.abs(Math.floor((t - o) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((o - t) / (24 * 3600 * 1e3)));
|
|
483
483
|
},
|
|
484
484
|
/**
|
|
485
485
|
* 生成唯一ID(时间戳+随机数)
|
|
@@ -495,10 +495,10 @@ const b = {
|
|
|
495
495
|
* @param day 日期
|
|
496
496
|
* @returns 当年的第几天
|
|
497
497
|
*/
|
|
498
|
-
getWhichDays(
|
|
499
|
-
let
|
|
500
|
-
for (let
|
|
501
|
-
switch (
|
|
498
|
+
getWhichDays(e, n, t) {
|
|
499
|
+
let o = t;
|
|
500
|
+
for (let r = 1; r < n; r++)
|
|
501
|
+
switch (r) {
|
|
502
502
|
case 1:
|
|
503
503
|
case 3:
|
|
504
504
|
case 5:
|
|
@@ -506,34 +506,34 @@ const b = {
|
|
|
506
506
|
case 8:
|
|
507
507
|
case 10:
|
|
508
508
|
case 12:
|
|
509
|
-
|
|
509
|
+
o += 31;
|
|
510
510
|
break;
|
|
511
511
|
case 2:
|
|
512
|
-
|
|
512
|
+
A.isLeapYear(e) ? o += 29 : o += 28;
|
|
513
513
|
break;
|
|
514
514
|
default:
|
|
515
|
-
|
|
515
|
+
o += 30;
|
|
516
516
|
break;
|
|
517
517
|
}
|
|
518
|
-
return
|
|
518
|
+
return o;
|
|
519
519
|
}
|
|
520
|
-
},
|
|
520
|
+
}, R = {
|
|
521
521
|
/**
|
|
522
522
|
* 获取元素相对于文档顶部的偏移量(距离)
|
|
523
523
|
* 处理了SVG元素的特殊情况。
|
|
524
524
|
* @param el 元素
|
|
525
525
|
* @returns 偏移量(距离值)
|
|
526
526
|
*/
|
|
527
|
-
getOffsetTop(
|
|
528
|
-
if (!
|
|
527
|
+
getOffsetTop(e) {
|
|
528
|
+
if (!e)
|
|
529
529
|
throw new Error("Element is not provided");
|
|
530
|
-
if (
|
|
531
|
-
const
|
|
532
|
-
return
|
|
530
|
+
if (e instanceof SVGElement) {
|
|
531
|
+
const t = e.getBoundingClientRect(), o = window.pageYOffset || document.documentElement.scrollTop;
|
|
532
|
+
return t.top + o;
|
|
533
533
|
}
|
|
534
534
|
let n = 0;
|
|
535
|
-
for (;
|
|
536
|
-
n +=
|
|
535
|
+
for (; e; )
|
|
536
|
+
n += e.offsetTop, e = e.offsetParent;
|
|
537
537
|
return n;
|
|
538
538
|
},
|
|
539
539
|
/**
|
|
@@ -541,11 +541,11 @@ const b = {
|
|
|
541
541
|
* @returns 包含滚动值的对象 { scrollLeft: 水平滚动值, scrollTop: 垂直滚动值 }
|
|
542
542
|
*/
|
|
543
543
|
getScrollValue() {
|
|
544
|
-
const
|
|
544
|
+
const e = {
|
|
545
545
|
scrollLeft: 0,
|
|
546
546
|
scrollTop: 0
|
|
547
547
|
};
|
|
548
|
-
return
|
|
548
|
+
return e.scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft, e.scrollTop = document.body.scrollTop || document.documentElement.scrollTop, e;
|
|
549
549
|
},
|
|
550
550
|
/**
|
|
551
551
|
* 获取鼠标事件的页面坐标
|
|
@@ -555,12 +555,12 @@ const b = {
|
|
|
555
555
|
* @param e 鼠标事件
|
|
556
556
|
* @returns 包含页面坐标的对象 { pageX: 水平页面坐标, pageY: 垂直页面坐标 }
|
|
557
557
|
*/
|
|
558
|
-
getPageValue(
|
|
559
|
-
|
|
560
|
-
const n =
|
|
558
|
+
getPageValue(e) {
|
|
559
|
+
e = e || window.event;
|
|
560
|
+
const n = e.pageX || e.clientX + this.getScrollValue().scrollLeft, t = e.pageY || e.clientY + this.getScrollValue().scrollTop;
|
|
561
561
|
return {
|
|
562
562
|
pageX: n,
|
|
563
|
-
pageY:
|
|
563
|
+
pageY: t
|
|
564
564
|
};
|
|
565
565
|
},
|
|
566
566
|
/**
|
|
@@ -571,8 +571,8 @@ const b = {
|
|
|
571
571
|
* @param fn 事件处理函数
|
|
572
572
|
*/
|
|
573
573
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
574
|
-
addEventListener(
|
|
575
|
-
|
|
574
|
+
addEventListener(e, n, t) {
|
|
575
|
+
e.addEventListener ? e.addEventListener(n, t) : e.attachEvent ? e.attachEvent("on" + n, t) : e["on" + n] = t;
|
|
576
576
|
},
|
|
577
577
|
/**
|
|
578
578
|
* 获取视口宽度
|
|
@@ -594,20 +594,52 @@ const b = {
|
|
|
594
594
|
* @param blob blob对象
|
|
595
595
|
* @param filename 文件名
|
|
596
596
|
*/
|
|
597
|
-
saveAsBlob(
|
|
598
|
-
const
|
|
599
|
-
|
|
597
|
+
saveAsBlob(e, n) {
|
|
598
|
+
const t = document.createElement("a"), o = window.URL.createObjectURL(e);
|
|
599
|
+
t.href = o, t.download = n, document.body.appendChild(t), t.click(), URL.revokeObjectURL(o), document.body.removeChild(t);
|
|
600
600
|
}
|
|
601
601
|
}, L = {
|
|
602
|
+
/**
|
|
603
|
+
* echarts动画函数
|
|
604
|
+
* @param option echarts配置
|
|
605
|
+
* @param myChart echarts实例
|
|
606
|
+
*/
|
|
607
|
+
animate(e, n) {
|
|
608
|
+
let t = -1;
|
|
609
|
+
const o = e.series[0].data.length;
|
|
610
|
+
let r;
|
|
611
|
+
r = setInterval(() => {
|
|
612
|
+
n.dispatchAction({
|
|
613
|
+
type: "downplay",
|
|
614
|
+
seriesIndex: 0,
|
|
615
|
+
dataIndex: t
|
|
616
|
+
}), t = (t + 1) % o, n.dispatchAction({
|
|
617
|
+
type: "highlight",
|
|
618
|
+
seriesIndex: 0,
|
|
619
|
+
dataIndex: t
|
|
620
|
+
}), n.dispatchAction({
|
|
621
|
+
type: "showTip",
|
|
622
|
+
seriesIndex: 0,
|
|
623
|
+
dataIndex: t
|
|
624
|
+
}), t > o && (t = 0);
|
|
625
|
+
}, 2e3), n.on("mouseover", () => {
|
|
626
|
+
clearInterval(r), n.dispatchAction({
|
|
627
|
+
type: "downplay",
|
|
628
|
+
seriesIndex: 0,
|
|
629
|
+
dataIndex: t
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}, I = {
|
|
602
634
|
/**
|
|
603
635
|
* 将选中的字母数组从A-Z排序:用于试题选择答案的排序实例
|
|
604
636
|
* @param arr 字母数组
|
|
605
637
|
* @returns
|
|
606
638
|
*/
|
|
607
|
-
sortFromA2Z(
|
|
608
|
-
return
|
|
609
|
-
const
|
|
610
|
-
return
|
|
639
|
+
sortFromA2Z(e) {
|
|
640
|
+
return e?.length ? e.sort((t, o) => {
|
|
641
|
+
const r = t.toUpperCase(), s = o.toUpperCase();
|
|
642
|
+
return r < s ? -1 : r > s ? 1 : 0;
|
|
611
643
|
}) : void 0;
|
|
612
644
|
}
|
|
613
645
|
}, T = {
|
|
@@ -619,8 +651,8 @@ const b = {
|
|
|
619
651
|
* @param degrees 度数。单位:°
|
|
620
652
|
* @returns 弧度值
|
|
621
653
|
*/
|
|
622
|
-
degrees2Radians(
|
|
623
|
-
return
|
|
654
|
+
degrees2Radians(e) {
|
|
655
|
+
return e * Math.PI / 180;
|
|
624
656
|
},
|
|
625
657
|
/**
|
|
626
658
|
* 根据经纬度计算距离【弃用】
|
|
@@ -630,11 +662,11 @@ const b = {
|
|
|
630
662
|
* @param targetLng 目标经度
|
|
631
663
|
* @returns 距离值 单位:km
|
|
632
664
|
*/
|
|
633
|
-
getDistance(
|
|
634
|
-
const
|
|
665
|
+
getDistance(e, n, t, o) {
|
|
666
|
+
const r = this.degrees2Radians(e), s = this.degrees2Radians(t), c = r - s, l = this.degrees2Radians(n) - this.degrees2Radians(o);
|
|
635
667
|
let i = 2 * Math.asin(
|
|
636
668
|
Math.sqrt(
|
|
637
|
-
Math.pow(Math.sin(c / 2), 2) + Math.cos(
|
|
669
|
+
Math.pow(Math.sin(c / 2), 2) + Math.cos(r) * Math.cos(s) * Math.pow(Math.sin(l / 2), 2)
|
|
638
670
|
)
|
|
639
671
|
);
|
|
640
672
|
return i = i * 6378.137, i = Math.round(i * 1e4) / 1e4, i = +i.toFixed(2), console.log("经纬度计算的距离为:" + i), i;
|
|
@@ -654,12 +686,12 @@ const b = {
|
|
|
654
686
|
* @param unit 距离单位,默认单位为千米。可选值:km(千米)、m(米)、mi(英里)、nmi(海里)
|
|
655
687
|
* @returns 距离值
|
|
656
688
|
*/
|
|
657
|
-
calculateDistanceByHaversine(
|
|
658
|
-
const
|
|
659
|
-
if (
|
|
689
|
+
calculateDistanceByHaversine(e, n, t = "km") {
|
|
690
|
+
const o = this, r = e.longitude ?? e.lng, s = e.latitude ?? e.lat, c = n.longitude ?? n.lng, l = n.latitude ?? n.lat;
|
|
691
|
+
if (r === void 0 || s === void 0 || c === void 0 || l === void 0)
|
|
660
692
|
throw new Error("无效的坐标格式,缺少经纬度信息");
|
|
661
|
-
const i = 6371, d =
|
|
662
|
-
switch (
|
|
693
|
+
const i = 6371, d = o.degrees2Radians(s), a = o.degrees2Radians(l), u = o.degrees2Radians(l - s), h = o.degrees2Radians(c - r), g = Math.sin(u / 2) * Math.sin(u / 2) + Math.cos(d) * Math.cos(a) * Math.sin(h / 2) * Math.sin(h / 2), f = 2 * Math.atan2(Math.sqrt(g), Math.sqrt(1 - g)), p = i * f;
|
|
694
|
+
switch (t) {
|
|
663
695
|
case "m":
|
|
664
696
|
return p * 1e3;
|
|
665
697
|
// 米
|
|
@@ -680,20 +712,20 @@ const b = {
|
|
|
680
712
|
* @param closed 是否闭合路径,默认不闭合
|
|
681
713
|
* @returns 距离结果对象。包含每个距离段的数组(segments)和总距离(total)。
|
|
682
714
|
*/
|
|
683
|
-
calculateDistancesByHaversine(
|
|
684
|
-
if (
|
|
715
|
+
calculateDistancesByHaversine(e, n = "km", t = !1) {
|
|
716
|
+
if (e.length < 2)
|
|
685
717
|
return { segments: [], total: 0 };
|
|
686
|
-
const
|
|
687
|
-
let
|
|
688
|
-
for (let s = 0; s <
|
|
689
|
-
const c = this.calculateDistanceByHaversine(
|
|
690
|
-
|
|
718
|
+
const o = [];
|
|
719
|
+
let r = 0;
|
|
720
|
+
for (let s = 0; s < e.length - 1; s++) {
|
|
721
|
+
const c = this.calculateDistanceByHaversine(e[s], e[s + 1], n);
|
|
722
|
+
o.push(c), r += c;
|
|
691
723
|
}
|
|
692
|
-
if (
|
|
693
|
-
const s = this.calculateDistanceByHaversine(
|
|
694
|
-
|
|
724
|
+
if (t && e.length > 2) {
|
|
725
|
+
const s = this.calculateDistanceByHaversine(e[e.length - 1], e[0], n);
|
|
726
|
+
o.push(s), r += s;
|
|
695
727
|
}
|
|
696
|
-
return { segments:
|
|
728
|
+
return { segments: o, total: r };
|
|
697
729
|
}
|
|
698
730
|
};
|
|
699
731
|
class j {
|
|
@@ -704,14 +736,14 @@ class j {
|
|
|
704
736
|
*/
|
|
705
737
|
static toStandardFormat(n) {
|
|
706
738
|
try {
|
|
707
|
-
const
|
|
708
|
-
if (isNaN(
|
|
739
|
+
const t = typeof n == "string" ? parseFloat(n) : n;
|
|
740
|
+
if (isNaN(t))
|
|
709
741
|
throw new Error("输入不是有效的数字");
|
|
710
|
-
if (!isFinite(
|
|
742
|
+
if (!isFinite(t))
|
|
711
743
|
throw new Error("输入是无穷大");
|
|
712
|
-
return
|
|
713
|
-
} catch (
|
|
714
|
-
return console.error("格式化失败:",
|
|
744
|
+
return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
745
|
+
} catch (t) {
|
|
746
|
+
return console.error("格式化失败:", t), "格式错误";
|
|
715
747
|
}
|
|
716
748
|
}
|
|
717
749
|
/**
|
|
@@ -721,12 +753,12 @@ class j {
|
|
|
721
753
|
*/
|
|
722
754
|
static toChineseFormat(n) {
|
|
723
755
|
try {
|
|
724
|
-
const
|
|
725
|
-
if (isNaN(
|
|
756
|
+
const t = typeof n == "string" ? parseFloat(n) : n;
|
|
757
|
+
if (isNaN(t))
|
|
726
758
|
throw new Error("输入不是有效的数字");
|
|
727
|
-
if (
|
|
759
|
+
if (t > 9999999999999e-2 || t < -9999999999999e-2)
|
|
728
760
|
throw new Error("输入数字超出范围");
|
|
729
|
-
const
|
|
761
|
+
const o = t < 0, r = Math.abs(t), s = Math.floor(r), c = Math.round((r - s) * 100), l = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], i = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], d = ["角", "分"];
|
|
730
762
|
let a = "", u = s;
|
|
731
763
|
if (u === 0)
|
|
732
764
|
a = l[0];
|
|
@@ -744,29 +776,29 @@ class j {
|
|
|
744
776
|
f > 0 && (h += l[f] + d[0]), p > 0 && (h += l[p] + d[1]);
|
|
745
777
|
} else
|
|
746
778
|
h = "整";
|
|
747
|
-
let g = (
|
|
779
|
+
let g = (o ? "负" : "") + a + "圆" + h;
|
|
748
780
|
return g === "零圆整" && (g = "零圆"), g;
|
|
749
|
-
} catch (
|
|
750
|
-
return console.error("转换失败:",
|
|
781
|
+
} catch (t) {
|
|
782
|
+
return console.error("转换失败:", t), "格式错误";
|
|
751
783
|
}
|
|
752
784
|
}
|
|
753
785
|
}
|
|
754
|
-
const
|
|
786
|
+
const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
755
787
|
__proto__: null,
|
|
756
|
-
toLetter:
|
|
757
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
788
|
+
toLetter: b
|
|
789
|
+
}, Symbol.toStringTag, { value: "Module" })), x = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), M = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
758
790
|
__proto__: null,
|
|
759
|
-
toMoney:
|
|
791
|
+
toMoney: x
|
|
760
792
|
}, Symbol.toStringTag, { value: "Module" })), H = {
|
|
761
793
|
...S,
|
|
762
|
-
...
|
|
794
|
+
...M,
|
|
763
795
|
/**
|
|
764
796
|
* 判断是否为数字
|
|
765
797
|
* @param val 待判断的值
|
|
766
798
|
* @returns 是否为数字。true 是;false 否
|
|
767
799
|
*/
|
|
768
|
-
isNumber(
|
|
769
|
-
return typeof
|
|
800
|
+
isNumber(e) {
|
|
801
|
+
return typeof e == "number" && !isNaN(e);
|
|
770
802
|
}
|
|
771
803
|
}, k = {
|
|
772
804
|
/**
|
|
@@ -774,8 +806,8 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
774
806
|
* @param obj 对象
|
|
775
807
|
* @returns 是否为空。true 为空;false 不为空
|
|
776
808
|
*/
|
|
777
|
-
isEmptyObject(
|
|
778
|
-
return
|
|
809
|
+
isEmptyObject(e) {
|
|
810
|
+
return e ? Object.keys(e).length === 0 && e.constructor === Object : !0;
|
|
779
811
|
},
|
|
780
812
|
/**
|
|
781
813
|
* 复制对象【对象的浅拷贝 把obj1的成员,复制给obj2】
|
|
@@ -783,9 +815,9 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
783
815
|
* @param obj2 目标对象
|
|
784
816
|
*/
|
|
785
817
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
786
|
-
copy(
|
|
787
|
-
for (const
|
|
788
|
-
n[
|
|
818
|
+
copy(e, n) {
|
|
819
|
+
for (const t in e)
|
|
820
|
+
n[t] = e[t];
|
|
789
821
|
},
|
|
790
822
|
/**
|
|
791
823
|
* 对象的深拷贝 把o1 的成员,复制给o2
|
|
@@ -793,22 +825,22 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
793
825
|
* @param o2
|
|
794
826
|
*/
|
|
795
827
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
796
|
-
deepCopy(
|
|
797
|
-
for (const
|
|
798
|
-
const
|
|
799
|
-
|
|
828
|
+
deepCopy(e, n) {
|
|
829
|
+
for (const t in e) {
|
|
830
|
+
const o = e[t];
|
|
831
|
+
o instanceof Object ? (n[t] = {}, this.deepCopy(o, n[t])) : o instanceof Array ? (n[t] = [], this.deepCopy(o, n[t])) : n[t] = e[t];
|
|
800
832
|
}
|
|
801
833
|
}
|
|
802
|
-
},
|
|
834
|
+
}, N = {
|
|
803
835
|
/**
|
|
804
836
|
* 脱敏
|
|
805
837
|
* @param phone 电话号码/手机号码
|
|
806
838
|
* @returns 脱敏后的电话号码/手机号码
|
|
807
839
|
*/
|
|
808
|
-
desensitize(
|
|
809
|
-
return
|
|
840
|
+
desensitize(e) {
|
|
841
|
+
return e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : "";
|
|
810
842
|
}
|
|
811
|
-
},
|
|
843
|
+
}, P = {
|
|
812
844
|
/**
|
|
813
845
|
* 生成随机颜色
|
|
814
846
|
* @returns 随机颜色值
|
|
@@ -822,8 +854,8 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
822
854
|
* @param max 最大值
|
|
823
855
|
* @returns 随机数
|
|
824
856
|
*/
|
|
825
|
-
int(
|
|
826
|
-
return Math.floor(Math.random() * (n -
|
|
857
|
+
int(e, n) {
|
|
858
|
+
return Math.floor(Math.random() * (n - e + 1)) + e;
|
|
827
859
|
},
|
|
828
860
|
/**
|
|
829
861
|
* 生成唯一ID(时间戳+随机数)
|
|
@@ -832,7 +864,7 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
832
864
|
uniqueId() {
|
|
833
865
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
834
866
|
}
|
|
835
|
-
},
|
|
867
|
+
}, $ = {
|
|
836
868
|
/**
|
|
837
869
|
* 验证手机号
|
|
838
870
|
*/
|
|
@@ -869,65 +901,65 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
869
901
|
* 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
|
|
870
902
|
*/
|
|
871
903
|
decimal: /^0\.(0[1-9]|[1-9][0-9]*)$/
|
|
872
|
-
},
|
|
904
|
+
}, D = {
|
|
873
905
|
/**
|
|
874
906
|
* 通过key值获取 localStorage 中存储的某个值
|
|
875
907
|
* @param key 获取的key
|
|
876
908
|
* @returns 获取的值
|
|
877
909
|
*/
|
|
878
|
-
getLocal(
|
|
879
|
-
return localStorage.getItem(
|
|
910
|
+
getLocal(e) {
|
|
911
|
+
return localStorage.getItem(e);
|
|
880
912
|
},
|
|
881
913
|
/**
|
|
882
914
|
* 设置localStorage中的某个值
|
|
883
915
|
* @param key 设置的key
|
|
884
916
|
* @param value 设置的value
|
|
885
917
|
*/
|
|
886
|
-
setLocal(
|
|
887
|
-
localStorage.setItem(
|
|
918
|
+
setLocal(e, n) {
|
|
919
|
+
localStorage.setItem(e, n);
|
|
888
920
|
},
|
|
889
921
|
/**
|
|
890
922
|
* 删除localStorage中的某个值
|
|
891
923
|
* @param key 删除的key
|
|
892
924
|
*/
|
|
893
|
-
removeLocal(
|
|
894
|
-
localStorage.removeItem(
|
|
925
|
+
removeLocal(e) {
|
|
926
|
+
localStorage.removeItem(e);
|
|
895
927
|
},
|
|
896
928
|
/**
|
|
897
929
|
* 通过key值获取 sessionStorage 中存储的某个值
|
|
898
930
|
* @param key 获取的key
|
|
899
931
|
* @returns 获取的值
|
|
900
932
|
*/
|
|
901
|
-
getSession(
|
|
902
|
-
return sessionStorage.getItem(
|
|
933
|
+
getSession(e) {
|
|
934
|
+
return sessionStorage.getItem(e);
|
|
903
935
|
},
|
|
904
936
|
/**
|
|
905
937
|
* 设置sessionStorage中的某个值
|
|
906
938
|
* @param key 设置的key
|
|
907
939
|
* @param value 设置的value
|
|
908
940
|
*/
|
|
909
|
-
setSession(
|
|
910
|
-
sessionStorage.setItem(
|
|
941
|
+
setSession(e, n) {
|
|
942
|
+
sessionStorage.setItem(e, n);
|
|
911
943
|
},
|
|
912
944
|
/**
|
|
913
945
|
* 删除sessionStorage中的某个值
|
|
914
946
|
* @param key 删除的key
|
|
915
947
|
*/
|
|
916
|
-
removeSession(
|
|
917
|
-
sessionStorage.removeItem(
|
|
948
|
+
removeSession(e) {
|
|
949
|
+
sessionStorage.removeItem(e);
|
|
918
950
|
}
|
|
919
|
-
},
|
|
951
|
+
}, F = {
|
|
920
952
|
/**
|
|
921
953
|
* 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
|
|
922
954
|
* @param str 字符串
|
|
923
955
|
* @param element 查询元素
|
|
924
956
|
* @returns 是否存在。true 存在;false 不存在
|
|
925
957
|
*/
|
|
926
|
-
isExist(
|
|
927
|
-
if (!
|
|
958
|
+
isExist(e, n) {
|
|
959
|
+
if (!e || !n)
|
|
928
960
|
return !1;
|
|
929
|
-
const
|
|
930
|
-
return console.log("判断某元素是否在字符串中",
|
|
961
|
+
const t = e.split(",");
|
|
962
|
+
return console.log("判断某元素是否在字符串中", t.indexOf(n) === -1), t.indexOf(n) !== -1;
|
|
931
963
|
},
|
|
932
964
|
/**
|
|
933
965
|
* 判断某元素是否在字符串中-比isExist()方法更高效。
|
|
@@ -935,17 +967,17 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
935
967
|
* @param element 查询元素
|
|
936
968
|
* @returns 是否存在。true 存在;false 不存在
|
|
937
969
|
*/
|
|
938
|
-
includes(
|
|
939
|
-
return !
|
|
970
|
+
includes(e, n) {
|
|
971
|
+
return !e || !n ? !1 : e.includes(n);
|
|
940
972
|
},
|
|
941
973
|
/**
|
|
942
974
|
* 判断字符串是否为 JSON
|
|
943
975
|
* @param str 字符串
|
|
944
976
|
* @returns
|
|
945
977
|
*/
|
|
946
|
-
isJSON(
|
|
978
|
+
isJSON(e) {
|
|
947
979
|
try {
|
|
948
|
-
return JSON.parse(
|
|
980
|
+
return JSON.parse(e), !0;
|
|
949
981
|
} catch {
|
|
950
982
|
return !1;
|
|
951
983
|
}
|
|
@@ -956,46 +988,46 @@ const A = (t) => t > 25 || t < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t], S = /*
|
|
|
956
988
|
* @param element 元素
|
|
957
989
|
* @returns 位置数组
|
|
958
990
|
*/
|
|
959
|
-
indexsOfAppear(
|
|
960
|
-
let
|
|
961
|
-
const
|
|
991
|
+
indexsOfAppear(e, n) {
|
|
992
|
+
let t = -1;
|
|
993
|
+
const o = [];
|
|
962
994
|
do
|
|
963
|
-
|
|
964
|
-
while (
|
|
965
|
-
return
|
|
995
|
+
t = e.indexOf(n, t + 1), t !== -1 && o.push(t);
|
|
996
|
+
while (t !== -1);
|
|
997
|
+
return o;
|
|
966
998
|
},
|
|
967
999
|
/**
|
|
968
1000
|
* 获取字符串中出现次数最多的字符和次数
|
|
969
1001
|
* @param string 字符串
|
|
970
1002
|
* @returns 数组,第一个元素为出现次数,第二个元素为出现次数最多的字符
|
|
971
1003
|
*/
|
|
972
|
-
getMaxTimesAndVal(
|
|
973
|
-
const n = [0, ""],
|
|
974
|
-
for (let s = 0; s <
|
|
975
|
-
const c =
|
|
976
|
-
|
|
1004
|
+
getMaxTimesAndVal(e) {
|
|
1005
|
+
const n = [0, ""], t = {};
|
|
1006
|
+
for (let s = 0; s < e.length; s++) {
|
|
1007
|
+
const c = e.charAt(s);
|
|
1008
|
+
t[c] ? t[c]++ : t[c] = 1;
|
|
977
1009
|
}
|
|
978
|
-
let
|
|
979
|
-
for (const s in
|
|
980
|
-
|
|
981
|
-
const
|
|
982
|
-
for (const s in
|
|
983
|
-
|
|
984
|
-
return n[0] =
|
|
1010
|
+
let o = 1;
|
|
1011
|
+
for (const s in t)
|
|
1012
|
+
o < t[s] && (o = t[s]);
|
|
1013
|
+
const r = [];
|
|
1014
|
+
for (const s in t)
|
|
1015
|
+
o == t[s] && r.push(s);
|
|
1016
|
+
return n[0] = o, n[1] = r.join(), n;
|
|
985
1017
|
}
|
|
986
|
-
}, B = (
|
|
987
|
-
const
|
|
988
|
-
return
|
|
1018
|
+
}, B = (e) => {
|
|
1019
|
+
const t = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
|
|
1020
|
+
return t ? decodeURIComponent(t[1]) : null;
|
|
989
1021
|
};
|
|
990
|
-
function
|
|
991
|
-
return new URLSearchParams(window.location.search).get(
|
|
1022
|
+
function C(e) {
|
|
1023
|
+
return new URLSearchParams(window.location.search).get(e);
|
|
992
1024
|
}
|
|
993
|
-
const
|
|
1025
|
+
const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
994
1026
|
__proto__: null,
|
|
995
1027
|
getQueryInfoByName: B,
|
|
996
|
-
getQueryParam:
|
|
997
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
998
|
-
...
|
|
1028
|
+
getQueryParam: C
|
|
1029
|
+
}, Symbol.toStringTag, { value: "Module" })), V = {
|
|
1030
|
+
...E,
|
|
999
1031
|
/**
|
|
1000
1032
|
* 获取当前域名
|
|
1001
1033
|
* @returns 当前url链接的host信息
|
|
@@ -1010,23 +1042,23 @@ const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1010
1042
|
getPath() {
|
|
1011
1043
|
return window.location.pathname;
|
|
1012
1044
|
}
|
|
1013
|
-
},
|
|
1045
|
+
}, W = {
|
|
1014
1046
|
/**
|
|
1015
1047
|
* 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
|
|
1016
1048
|
* @param list 瀑布流数据-数组
|
|
1017
1049
|
* @param columnsNum 需要展示的列数
|
|
1018
1050
|
* @returns 适合瀑布流布局的数组
|
|
1019
1051
|
*/
|
|
1020
|
-
toList(
|
|
1021
|
-
console.log(
|
|
1022
|
-
const
|
|
1023
|
-
for (let
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1027
|
-
for (const
|
|
1028
|
-
|
|
1029
|
-
return
|
|
1052
|
+
toList(e, n = 2) {
|
|
1053
|
+
console.log(e, n);
|
|
1054
|
+
const t = {};
|
|
1055
|
+
for (let r = 0; r < n; r++)
|
|
1056
|
+
t[r] = [];
|
|
1057
|
+
e.forEach((r, s) => t[s % n].push(r));
|
|
1058
|
+
const o = [];
|
|
1059
|
+
for (const r in t)
|
|
1060
|
+
o.push(...t[r]);
|
|
1061
|
+
return o;
|
|
1030
1062
|
},
|
|
1031
1063
|
/**
|
|
1032
1064
|
* js瀑布流布局
|
|
@@ -1034,15 +1066,15 @@ const x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1034
1066
|
* @param items 瀑布流元素
|
|
1035
1067
|
* @param step 间距
|
|
1036
1068
|
*/
|
|
1037
|
-
jsLayout(
|
|
1038
|
-
const
|
|
1069
|
+
jsLayout(e, n, t) {
|
|
1070
|
+
const o = e.offsetWidth, r = n[0].offsetWidth, s = parseInt((o / r).toString()), c = (o - r * s) / (s - 1), l = [];
|
|
1039
1071
|
for (let i = 0, d = n.length; i < d; i++) {
|
|
1040
1072
|
const a = n[i];
|
|
1041
1073
|
if (i < s)
|
|
1042
|
-
a.style.left = (
|
|
1074
|
+
a.style.left = (r + c) * i + "px", l[i] = a.offsetHeight;
|
|
1043
1075
|
else {
|
|
1044
1076
|
const { index: u, value: h } = w.getMinValueAndIndex(l);
|
|
1045
|
-
a.style.left = (
|
|
1077
|
+
a.style.left = (r + c) * u + "px", a.style.top = h + t + "px", l[u] = a.offsetHeight + t + h;
|
|
1046
1078
|
}
|
|
1047
1079
|
}
|
|
1048
1080
|
}
|
|
@@ -1051,20 +1083,21 @@ export {
|
|
|
1051
1083
|
_ as Base64Utils,
|
|
1052
1084
|
j as MoneyFormatter,
|
|
1053
1085
|
w as arrayUtils,
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1086
|
+
A as booleanUtils,
|
|
1087
|
+
v as cookieUtils,
|
|
1088
|
+
O as dateUtils,
|
|
1089
|
+
R as documentUtils,
|
|
1058
1090
|
U as downloadUtils,
|
|
1059
|
-
L as
|
|
1091
|
+
L as echartsUtils,
|
|
1092
|
+
I as letterUtils,
|
|
1060
1093
|
T as mapUtils,
|
|
1061
1094
|
H as numberUtils,
|
|
1062
1095
|
k as objectUtils,
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1096
|
+
N as phoneUtils,
|
|
1097
|
+
P as randomUtils,
|
|
1098
|
+
$ as regexpUtils,
|
|
1099
|
+
D as storageUtils,
|
|
1100
|
+
F as stringUtils,
|
|
1101
|
+
V as urlUtils,
|
|
1102
|
+
W as waterfallUtils
|
|
1070
1103
|
};
|