@yh-kit/utils 1.10.0 → 1.11.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 +264 -205
- package/dist/utils.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/utils/lib/date/index.d.ts +14 -0
package/dist/utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const w = (e) => {
|
|
2
2
|
if (!e || !e.length) return {};
|
|
3
3
|
const n = {};
|
|
4
4
|
return e.forEach((t) => {
|
|
5
|
-
const
|
|
6
|
-
n[t?.value] =
|
|
5
|
+
const r = Object.assign({ label: t.label, text: t.label }, t);
|
|
6
|
+
n[t?.value] = r;
|
|
7
7
|
}), n;
|
|
8
|
-
},
|
|
8
|
+
}, A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
9
9
|
__proto__: null,
|
|
10
|
-
toEnumObj:
|
|
11
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
10
|
+
toEnumObj: w
|
|
11
|
+
}, Symbol.toStringTag, { value: "Module" })), b = Object.assign(
|
|
12
12
|
{
|
|
13
13
|
/**
|
|
14
14
|
* 数组去重
|
|
@@ -35,8 +35,8 @@ const y = (e) => {
|
|
|
35
35
|
*/
|
|
36
36
|
countOfAppear(e, n) {
|
|
37
37
|
let t = 0;
|
|
38
|
-
for (const
|
|
39
|
-
|
|
38
|
+
for (const r of e)
|
|
39
|
+
r === n && t++;
|
|
40
40
|
return t;
|
|
41
41
|
},
|
|
42
42
|
/**
|
|
@@ -47,11 +47,11 @@ const y = (e) => {
|
|
|
47
47
|
*/
|
|
48
48
|
indexsOfAppear(e, n) {
|
|
49
49
|
let t = -1;
|
|
50
|
-
const
|
|
50
|
+
const r = [];
|
|
51
51
|
do
|
|
52
|
-
t = e.indexOf(n, t + 1), t !== -1 &&
|
|
52
|
+
t = e.indexOf(n, t + 1), t !== -1 && r.push(t);
|
|
53
53
|
while (t !== -1);
|
|
54
|
-
return
|
|
54
|
+
return r;
|
|
55
55
|
},
|
|
56
56
|
/**
|
|
57
57
|
* 数组排序-默认升序
|
|
@@ -60,7 +60,7 @@ const y = (e) => {
|
|
|
60
60
|
* @returns 排序后的数组
|
|
61
61
|
*/
|
|
62
62
|
sort(e, n = "asc") {
|
|
63
|
-
return e ? e.sort((t,
|
|
63
|
+
return e ? e.sort((t, r) => n === "asc" ? t > r ? 1 : -1 : t < r ? 1 : -1) : [];
|
|
64
64
|
},
|
|
65
65
|
/**
|
|
66
66
|
* 数组乱序(洗牌算法)
|
|
@@ -111,9 +111,9 @@ const y = (e) => {
|
|
|
111
111
|
/** 最小值索引 */
|
|
112
112
|
index: 0
|
|
113
113
|
};
|
|
114
|
-
for (let t = 1,
|
|
115
|
-
const
|
|
116
|
-
n.value >
|
|
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
117
|
}
|
|
118
118
|
return n;
|
|
119
119
|
},
|
|
@@ -124,16 +124,16 @@ const y = (e) => {
|
|
|
124
124
|
*/
|
|
125
125
|
getMaxValueAndIndex(e) {
|
|
126
126
|
return e.length === 0 ? { value: 0, index: 0 } : e.reduce(
|
|
127
|
-
(n, t,
|
|
127
|
+
(n, t, r) => t < n.value ? { value: t, index: r } : n,
|
|
128
128
|
{ value: e[0], index: 0 }
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
|
-
...
|
|
133
|
+
...A
|
|
134
134
|
}
|
|
135
135
|
);
|
|
136
|
-
class
|
|
136
|
+
class T {
|
|
137
137
|
/** Base64 编码表 */
|
|
138
138
|
static BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
139
139
|
/**
|
|
@@ -145,16 +145,16 @@ class _ {
|
|
|
145
145
|
* @param sliceSize 可选参数,表示分片大小,默认为512字节。用于控制每次处理的Base64字符串长度,以优化大文件的处理。
|
|
146
146
|
* @returns 返回转换后的Blob对象,如果转换失败,则返回null。
|
|
147
147
|
*/
|
|
148
|
-
static toBlob(n, t = "",
|
|
149
|
-
const s = (n.split(",")[1] || n).replace(/-/g, "+").replace(/_/g, "/"),
|
|
148
|
+
static toBlob(n, t = "", r = 512) {
|
|
149
|
+
const s = (n.split(",")[1] || n).replace(/-/g, "+").replace(/_/g, "/"), a = "=".repeat((4 - s.length % 4) % 4), u = s + a;
|
|
150
150
|
try {
|
|
151
|
-
const i = atob(
|
|
152
|
-
for (let
|
|
153
|
-
const
|
|
154
|
-
for (let f = 0; f <
|
|
155
|
-
h[f] =
|
|
156
|
-
const
|
|
157
|
-
d.push(
|
|
151
|
+
const i = atob(u), d = [];
|
|
152
|
+
for (let c = 0; c < i.length; c += r) {
|
|
153
|
+
const l = i.slice(c, c + r), h = new Array(l.length);
|
|
154
|
+
for (let f = 0; f < l.length; f++)
|
|
155
|
+
h[f] = l.charCodeAt(f);
|
|
156
|
+
const p = new Uint8Array(h);
|
|
157
|
+
d.push(p);
|
|
158
158
|
}
|
|
159
159
|
return new Blob(d, { type: t });
|
|
160
160
|
} catch (i) {
|
|
@@ -171,16 +171,16 @@ class _ {
|
|
|
171
171
|
* @param mimeType MIME类型,默认为"text/plain"。
|
|
172
172
|
* @returns 返回一个File对象,包含解码后的数据。
|
|
173
173
|
*/
|
|
174
|
-
static toFile(n, t = "file.txt",
|
|
175
|
-
const s = n.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"),
|
|
176
|
-
for (let
|
|
177
|
-
const h = i.slice(
|
|
174
|
+
static toFile(n, t = "file.txt", r = "text/plain") {
|
|
175
|
+
const s = n.replace(/^data:.+;base64,/, "").replace(/-/g, "+").replace(/_/g, "/"), a = "=".repeat((4 - s.length % 4) % 4), u = s + a, i = atob(u), d = [];
|
|
176
|
+
for (let l = 0; l < i.length; l += 512) {
|
|
177
|
+
const h = i.slice(l, l + 512), p = new Array(h.length);
|
|
178
178
|
for (let f = 0; f < h.length; f++)
|
|
179
|
-
|
|
180
|
-
d.push(new Uint8Array(
|
|
179
|
+
p[f] = h.charCodeAt(f);
|
|
180
|
+
d.push(new Uint8Array(p));
|
|
181
181
|
}
|
|
182
|
-
const
|
|
183
|
-
return new File([
|
|
182
|
+
const c = new Blob(d, { type: r });
|
|
183
|
+
return new File([c], t, { type: r });
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* base64加密 -- 普通字符串转 Base64 编码
|
|
@@ -208,20 +208,20 @@ class _ {
|
|
|
208
208
|
*/
|
|
209
209
|
static _stringToUtf8Bytes(n) {
|
|
210
210
|
const t = [];
|
|
211
|
-
for (let
|
|
212
|
-
let
|
|
213
|
-
if (
|
|
214
|
-
t.push(
|
|
215
|
-
else if (
|
|
216
|
-
t.push(192 |
|
|
217
|
-
else if (
|
|
218
|
-
t.push(224 |
|
|
211
|
+
for (let r = 0; r < n.length; r++) {
|
|
212
|
+
let o = n.charCodeAt(r);
|
|
213
|
+
if (o < 128)
|
|
214
|
+
t.push(o);
|
|
215
|
+
else if (o < 2048)
|
|
216
|
+
t.push(192 | o >> 6), t.push(128 | o & 63);
|
|
217
|
+
else if (o < 55296 || o >= 57344)
|
|
218
|
+
t.push(224 | o >> 12), t.push(128 | o >> 6 & 63), t.push(128 | o & 63);
|
|
219
219
|
else {
|
|
220
|
-
|
|
221
|
-
const s =
|
|
222
|
-
if (isNaN(
|
|
220
|
+
r++;
|
|
221
|
+
const s = o, a = n.charCodeAt(r);
|
|
222
|
+
if (isNaN(a))
|
|
223
223
|
throw new Error("代理对不完整");
|
|
224
|
-
|
|
224
|
+
o = 65536 + ((s & 1023) << 10) + (a & 1023), t.push(240 | o >> 18), t.push(128 | o >> 12 & 63), t.push(128 | o >> 6 & 63), t.push(128 | o & 63);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
return t;
|
|
@@ -230,20 +230,20 @@ class _ {
|
|
|
230
230
|
* UTF-8 字节数组转字符串
|
|
231
231
|
*/
|
|
232
232
|
static _utf8BytesToString(n) {
|
|
233
|
-
let t = "",
|
|
234
|
-
for (;
|
|
235
|
-
const
|
|
236
|
-
if (
|
|
237
|
-
t += String.fromCharCode(
|
|
238
|
-
else if (
|
|
239
|
-
const s = n[
|
|
240
|
-
t += String.fromCharCode((
|
|
241
|
-
} else if (
|
|
242
|
-
const s = n[
|
|
243
|
-
t += String.fromCharCode((
|
|
244
|
-
} else if (
|
|
245
|
-
const s = n[
|
|
246
|
-
t += String.fromCharCode(d,
|
|
233
|
+
let t = "", r = 0;
|
|
234
|
+
for (; r < n.length; ) {
|
|
235
|
+
const o = n[r++];
|
|
236
|
+
if (o < 128)
|
|
237
|
+
t += String.fromCharCode(o);
|
|
238
|
+
else if (o >= 192 && o < 224) {
|
|
239
|
+
const s = n[r++] & 63;
|
|
240
|
+
t += String.fromCharCode((o & 31) << 6 | s);
|
|
241
|
+
} else if (o >= 224 && o < 240) {
|
|
242
|
+
const s = n[r++] & 63, a = n[r++] & 63;
|
|
243
|
+
t += String.fromCharCode((o & 15) << 12 | s << 6 | a);
|
|
244
|
+
} else if (o >= 240 && o < 248) {
|
|
245
|
+
const s = n[r++] & 63, a = n[r++] & 63, u = n[r++] & 63, i = (o & 7) << 18 | s << 12 | a << 6 | u, d = Math.floor((i - 65536) / 1024) + 55296, c = (i - 65536) % 1024 + 56320;
|
|
246
|
+
t += String.fromCharCode(d, c);
|
|
247
247
|
} else
|
|
248
248
|
t += "�";
|
|
249
249
|
}
|
|
@@ -253,10 +253,10 @@ class _ {
|
|
|
253
253
|
* 字节数组转 Base64 编码
|
|
254
254
|
*/
|
|
255
255
|
static _bytesToBase64(n) {
|
|
256
|
-
let t = "",
|
|
257
|
-
for (;
|
|
258
|
-
const
|
|
259
|
-
s ?
|
|
256
|
+
let t = "", r = 0;
|
|
257
|
+
for (; r < n.length; ) {
|
|
258
|
+
const o = n[r++], s = r < n.length, a = s ? n[r++] : 0, u = r < n.length, i = u ? n[r++] : 0, d = o >> 2, c = (o & 3) << 4 | a >> 4, l = (a & 15) << 2 | i >> 6, h = i & 63;
|
|
259
|
+
s ? u ? t += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(c) + this.BASE64_CHARS.charAt(l) + this.BASE64_CHARS.charAt(h) : t += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(c) + this.BASE64_CHARS.charAt(l) + "=" : t += this.BASE64_CHARS.charAt(d) + this.BASE64_CHARS.charAt(c) + "==";
|
|
260
260
|
}
|
|
261
261
|
return t;
|
|
262
262
|
}
|
|
@@ -265,29 +265,29 @@ class _ {
|
|
|
265
265
|
*/
|
|
266
266
|
static _base64ToBytes(n) {
|
|
267
267
|
const t = n.length;
|
|
268
|
-
let
|
|
269
|
-
t >= 2 && (n[t - 1] === "=" &&
|
|
270
|
-
const
|
|
268
|
+
let r = 0;
|
|
269
|
+
t >= 2 && (n[t - 1] === "=" && r++, n[t - 2] === "=" && r++);
|
|
270
|
+
const o = Math.floor(t * 3 / 4) - r, s = new Array(o), a = new Array(256).fill(-1);
|
|
271
271
|
for (let d = 0; d < this.BASE64_CHARS.length; d++)
|
|
272
|
-
|
|
273
|
-
let
|
|
272
|
+
a[this.BASE64_CHARS.charCodeAt(d)] = d;
|
|
273
|
+
let u = 0, i = 0;
|
|
274
274
|
for (; i < t; ) {
|
|
275
|
-
const d =
|
|
276
|
-
if (d === -1 ||
|
|
275
|
+
const d = a[n.charCodeAt(i++)], c = a[n.charCodeAt(i++)], l = i < t ? a[n.charCodeAt(i++)] : -1, h = i < t ? a[n.charCodeAt(i++)] : -1;
|
|
276
|
+
if (d === -1 || c === -1)
|
|
277
277
|
throw new Error("无效的 Base64 字符");
|
|
278
|
-
const
|
|
279
|
-
if (s[
|
|
280
|
-
const f = (
|
|
281
|
-
if (s[
|
|
282
|
-
const
|
|
283
|
-
s[
|
|
278
|
+
const p = d << 2 | c >> 4;
|
|
279
|
+
if (s[u++] = p, l !== -1) {
|
|
280
|
+
const f = (c & 15) << 4 | l >> 2;
|
|
281
|
+
if (s[u++] = f, h !== -1) {
|
|
282
|
+
const g = (l & 3) << 6 | h;
|
|
283
|
+
s[u++] = g;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
return s;
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
const
|
|
290
|
+
const S = {
|
|
291
291
|
/**
|
|
292
292
|
* 检查是否为空字符串
|
|
293
293
|
* @param str 要检查的字符串
|
|
@@ -431,7 +431,7 @@ const A = {
|
|
|
431
431
|
isMobile() {
|
|
432
432
|
return /Mobi|Android|iPhone/i.test(navigator.userAgent);
|
|
433
433
|
}
|
|
434
|
-
},
|
|
434
|
+
}, O = {
|
|
435
435
|
/**
|
|
436
436
|
* 通过传入的name获取cookie的值
|
|
437
437
|
* @param name cookie的name
|
|
@@ -450,8 +450,8 @@ const A = {
|
|
|
450
450
|
* @returns void
|
|
451
451
|
*/
|
|
452
452
|
setCookie(e, n, t = 7) {
|
|
453
|
-
const
|
|
454
|
-
|
|
453
|
+
const r = /* @__PURE__ */ new Date();
|
|
454
|
+
r.setTime(r.getTime() + t * 24 * 60 * 60 * 1e3), document.cookie = `${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`;
|
|
455
455
|
},
|
|
456
456
|
/**
|
|
457
457
|
* 删除cookie
|
|
@@ -461,7 +461,7 @@ const A = {
|
|
|
461
461
|
deleteCookie(e) {
|
|
462
462
|
this.setCookie(e, "", -1);
|
|
463
463
|
}
|
|
464
|
-
},
|
|
464
|
+
}, U = {
|
|
465
465
|
/**
|
|
466
466
|
* 获取当前时间字符串
|
|
467
467
|
* @param locales 区域设置。如:'zh-CN','en-US',"chinese"。默认'zh-CN'。
|
|
@@ -478,8 +478,8 @@ const A = {
|
|
|
478
478
|
* @returns 相差天数
|
|
479
479
|
*/
|
|
480
480
|
diffDays(e, n) {
|
|
481
|
-
const t = new Date(e).getTime(),
|
|
482
|
-
return t >
|
|
481
|
+
const t = new Date(e).getTime(), r = new Date(n).getTime();
|
|
482
|
+
return t > r ? Math.abs(Math.floor((t - r) / (24 * 3600 * 1e3))) : Math.abs(Math.floor((r - t) / (24 * 3600 * 1e3)));
|
|
483
483
|
},
|
|
484
484
|
/**
|
|
485
485
|
* 生成唯一ID(时间戳+随机数)
|
|
@@ -496,9 +496,9 @@ const A = {
|
|
|
496
496
|
* @returns 当年的第几天
|
|
497
497
|
*/
|
|
498
498
|
getWhichDays(e, n, t) {
|
|
499
|
-
let
|
|
500
|
-
for (let
|
|
501
|
-
switch (
|
|
499
|
+
let r = t;
|
|
500
|
+
for (let o = 1; o < n; o++)
|
|
501
|
+
switch (o) {
|
|
502
502
|
case 1:
|
|
503
503
|
case 3:
|
|
504
504
|
case 5:
|
|
@@ -506,18 +506,77 @@ const A = {
|
|
|
506
506
|
case 8:
|
|
507
507
|
case 10:
|
|
508
508
|
case 12:
|
|
509
|
-
|
|
509
|
+
r += 31;
|
|
510
510
|
break;
|
|
511
511
|
case 2:
|
|
512
|
-
|
|
512
|
+
S.isLeapYear(e) ? r += 29 : r += 28;
|
|
513
513
|
break;
|
|
514
514
|
default:
|
|
515
|
-
|
|
515
|
+
r += 30;
|
|
516
516
|
break;
|
|
517
517
|
}
|
|
518
|
-
return
|
|
518
|
+
return r;
|
|
519
|
+
},
|
|
520
|
+
/**
|
|
521
|
+
* 获取时间字符串(自动短化)
|
|
522
|
+
* @param timestamp 时间戳
|
|
523
|
+
* @param mustIncludeTime 是否必须包含时间
|
|
524
|
+
* @returns 时间字符串
|
|
525
|
+
*/
|
|
526
|
+
getTimeStringAutoShort2(e, n) {
|
|
527
|
+
const t = /* @__PURE__ */ new Date(), r = new Date(e), o = t.getFullYear(), s = t.getMonth() + 1, a = t.getDate(), u = r.getFullYear(), i = r.getMonth() + 1, d = r.getDate();
|
|
528
|
+
let c = "";
|
|
529
|
+
const l = n ? " " + this.formatDate(r, "hh:mm") : "";
|
|
530
|
+
if (o === u) {
|
|
531
|
+
const f = t.getTime() - e;
|
|
532
|
+
if (s === i && a === d)
|
|
533
|
+
f < 60 * 1e3 ? c = "刚刚" : c = this.formatDate(r, "hh:mm");
|
|
534
|
+
else {
|
|
535
|
+
const g = /* @__PURE__ */ new Date();
|
|
536
|
+
g.setDate(g.getDate() - 1);
|
|
537
|
+
const m = /* @__PURE__ */ new Date();
|
|
538
|
+
if (m.setDate(m.getDate() - 2), i === g.getMonth() + 1 && d === g.getDate())
|
|
539
|
+
c = "昨天" + l;
|
|
540
|
+
else if (i === m.getMonth() + 1 && d === m.getDate())
|
|
541
|
+
c = "前天" + l;
|
|
542
|
+
else if (f / 36e5 <= 7 * 24) {
|
|
543
|
+
const y = new Array(7);
|
|
544
|
+
y[0] = "星期日", y[1] = "星期一", y[2] = "星期二", y[3] = "星期三", y[4] = "星期四", y[5] = "星期五", y[6] = "星期六", c = y[r.getDay()] + l;
|
|
545
|
+
} else c = this.formatDate(r, "yyyy/M/d") + l;
|
|
546
|
+
}
|
|
547
|
+
} else
|
|
548
|
+
c = this.formatDate(r, "yyyy/M/d") + l;
|
|
549
|
+
return c;
|
|
550
|
+
},
|
|
551
|
+
/**
|
|
552
|
+
* 格式化日期
|
|
553
|
+
* @param date 日期对象
|
|
554
|
+
* @param fmt 格式化字符串
|
|
555
|
+
* @returns 格式化后的日期字符串
|
|
556
|
+
*/
|
|
557
|
+
formatDate(e, n) {
|
|
558
|
+
const t = {
|
|
559
|
+
"M+": e.getMonth() + 1,
|
|
560
|
+
//月份
|
|
561
|
+
"d+": e.getDate(),
|
|
562
|
+
//日
|
|
563
|
+
"h+": e.getHours(),
|
|
564
|
+
//小时
|
|
565
|
+
"m+": e.getMinutes(),
|
|
566
|
+
//分
|
|
567
|
+
"s+": e.getSeconds(),
|
|
568
|
+
//秒
|
|
569
|
+
"q+": Math.floor((e.getMonth() + 3) / 3),
|
|
570
|
+
//季度
|
|
571
|
+
S: e.getMilliseconds()
|
|
572
|
+
//毫秒
|
|
573
|
+
};
|
|
574
|
+
/(y+)/.test(n) && (n = n.replace(RegExp.$1, (e.getFullYear() + "").substr(4 - RegExp.$1.length)));
|
|
575
|
+
for (const r in t)
|
|
576
|
+
new RegExp("(" + r + ")").test(n) && (n = n.replace(RegExp.$1, RegExp.$1.length === 1 ? t[r] : ("00" + t[r]).substr(("" + t[r]).length)));
|
|
577
|
+
return n;
|
|
519
578
|
}
|
|
520
|
-
},
|
|
579
|
+
}, L = {
|
|
521
580
|
/**
|
|
522
581
|
* 获取元素相对于文档顶部的偏移量(距离)
|
|
523
582
|
* 处理了SVG元素的特殊情况。
|
|
@@ -528,8 +587,8 @@ const A = {
|
|
|
528
587
|
if (!e)
|
|
529
588
|
throw new Error("Element is not provided");
|
|
530
589
|
if (e instanceof SVGElement) {
|
|
531
|
-
const t = e.getBoundingClientRect(),
|
|
532
|
-
return t.top +
|
|
590
|
+
const t = e.getBoundingClientRect(), r = window.pageYOffset || document.documentElement.scrollTop;
|
|
591
|
+
return t.top + r;
|
|
533
592
|
}
|
|
534
593
|
let n = 0;
|
|
535
594
|
for (; e; )
|
|
@@ -588,17 +647,17 @@ const A = {
|
|
|
588
647
|
getViewportHeight() {
|
|
589
648
|
return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
590
649
|
}
|
|
591
|
-
},
|
|
650
|
+
}, I = {
|
|
592
651
|
/**
|
|
593
652
|
* 将blob对象转化成文件并导出到本地
|
|
594
653
|
* @param blob blob对象
|
|
595
654
|
* @param filename 文件名
|
|
596
655
|
*/
|
|
597
656
|
saveAsBlob(e, n) {
|
|
598
|
-
const t = document.createElement("a"),
|
|
599
|
-
t.href =
|
|
657
|
+
const t = document.createElement("a"), r = window.URL.createObjectURL(e);
|
|
658
|
+
t.href = r, t.download = n, document.body.appendChild(t), t.click(), URL.revokeObjectURL(r), document.body.removeChild(t);
|
|
600
659
|
}
|
|
601
|
-
},
|
|
660
|
+
}, H = {
|
|
602
661
|
/**
|
|
603
662
|
* echarts动画函数
|
|
604
663
|
* @param option echarts配置
|
|
@@ -606,14 +665,14 @@ const A = {
|
|
|
606
665
|
*/
|
|
607
666
|
animate(e, n) {
|
|
608
667
|
let t = -1;
|
|
609
|
-
const
|
|
610
|
-
let
|
|
611
|
-
|
|
668
|
+
const r = e.series[0].data.length;
|
|
669
|
+
let o;
|
|
670
|
+
o = setInterval(() => {
|
|
612
671
|
n.dispatchAction({
|
|
613
672
|
type: "downplay",
|
|
614
673
|
seriesIndex: 0,
|
|
615
674
|
dataIndex: t
|
|
616
|
-
}), t = (t + 1) %
|
|
675
|
+
}), t = (t + 1) % r, n.dispatchAction({
|
|
617
676
|
type: "highlight",
|
|
618
677
|
seriesIndex: 0,
|
|
619
678
|
dataIndex: t
|
|
@@ -621,28 +680,28 @@ const A = {
|
|
|
621
680
|
type: "showTip",
|
|
622
681
|
seriesIndex: 0,
|
|
623
682
|
dataIndex: t
|
|
624
|
-
}), t >
|
|
683
|
+
}), t > r && (t = 0);
|
|
625
684
|
}, 2e3), n.on("mouseover", () => {
|
|
626
|
-
clearInterval(
|
|
685
|
+
clearInterval(o), n.dispatchAction({
|
|
627
686
|
type: "downplay",
|
|
628
687
|
seriesIndex: 0,
|
|
629
688
|
dataIndex: t
|
|
630
689
|
});
|
|
631
690
|
});
|
|
632
691
|
}
|
|
633
|
-
},
|
|
692
|
+
}, j = {
|
|
634
693
|
/**
|
|
635
694
|
* 将选中的字母数组从A-Z排序:用于试题选择答案的排序实例
|
|
636
695
|
* @param arr 字母数组
|
|
637
696
|
* @returns
|
|
638
697
|
*/
|
|
639
698
|
sortFromA2Z(e) {
|
|
640
|
-
return e?.length ? e.sort((t,
|
|
641
|
-
const
|
|
642
|
-
return
|
|
699
|
+
return e?.length ? e.sort((t, r) => {
|
|
700
|
+
const o = t.toUpperCase(), s = r.toUpperCase();
|
|
701
|
+
return o < s ? -1 : o > s ? 1 : 0;
|
|
643
702
|
}) : void 0;
|
|
644
703
|
}
|
|
645
|
-
},
|
|
704
|
+
}, k = {
|
|
646
705
|
/**
|
|
647
706
|
* 角度(度数)转弧度
|
|
648
707
|
* 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
|
|
@@ -662,11 +721,11 @@ const A = {
|
|
|
662
721
|
* @param targetLng 目标经度
|
|
663
722
|
* @returns 距离值 单位:km
|
|
664
723
|
*/
|
|
665
|
-
getDistance(e, n, t,
|
|
666
|
-
const
|
|
724
|
+
getDistance(e, n, t, r) {
|
|
725
|
+
const o = this.degrees2Radians(e), s = this.degrees2Radians(t), a = o - s, u = this.degrees2Radians(n) - this.degrees2Radians(r);
|
|
667
726
|
let i = 2 * Math.asin(
|
|
668
727
|
Math.sqrt(
|
|
669
|
-
Math.pow(Math.sin(
|
|
728
|
+
Math.pow(Math.sin(a / 2), 2) + Math.cos(o) * Math.cos(s) * Math.pow(Math.sin(u / 2), 2)
|
|
670
729
|
)
|
|
671
730
|
);
|
|
672
731
|
return i = i * 6378.137, i = Math.round(i * 1e4) / 1e4, i = +i.toFixed(2), console.log("经纬度计算的距离为:" + i), i;
|
|
@@ -687,22 +746,22 @@ const A = {
|
|
|
687
746
|
* @returns 距离值
|
|
688
747
|
*/
|
|
689
748
|
calculateDistanceByHaversine(e, n, t = "km") {
|
|
690
|
-
const
|
|
691
|
-
if (
|
|
749
|
+
const r = this, o = e.longitude ?? e.lng, s = e.latitude ?? e.lat, a = n.longitude ?? n.lng, u = n.latitude ?? n.lat;
|
|
750
|
+
if (o === void 0 || s === void 0 || a === void 0 || u === void 0)
|
|
692
751
|
throw new Error("无效的坐标格式,缺少经纬度信息");
|
|
693
|
-
const i = 6371, d =
|
|
752
|
+
const i = 6371, d = r.degrees2Radians(s), c = r.degrees2Radians(u), l = r.degrees2Radians(u - s), h = r.degrees2Radians(a - o), p = Math.sin(l / 2) * Math.sin(l / 2) + Math.cos(d) * Math.cos(c) * Math.sin(h / 2) * Math.sin(h / 2), f = 2 * Math.atan2(Math.sqrt(p), Math.sqrt(1 - p)), g = i * f;
|
|
694
753
|
switch (t) {
|
|
695
754
|
case "m":
|
|
696
|
-
return
|
|
755
|
+
return g * 1e3;
|
|
697
756
|
// 米
|
|
698
757
|
case "mi":
|
|
699
|
-
return
|
|
758
|
+
return g * 0.621371;
|
|
700
759
|
// 英里
|
|
701
760
|
case "nmi":
|
|
702
|
-
return
|
|
761
|
+
return g * 0.539957;
|
|
703
762
|
// 海里
|
|
704
763
|
default:
|
|
705
|
-
return
|
|
764
|
+
return g;
|
|
706
765
|
}
|
|
707
766
|
},
|
|
708
767
|
/**
|
|
@@ -715,20 +774,20 @@ const A = {
|
|
|
715
774
|
calculateDistancesByHaversine(e, n = "km", t = !1) {
|
|
716
775
|
if (e.length < 2)
|
|
717
776
|
return { segments: [], total: 0 };
|
|
718
|
-
const
|
|
719
|
-
let
|
|
777
|
+
const r = [];
|
|
778
|
+
let o = 0;
|
|
720
779
|
for (let s = 0; s < e.length - 1; s++) {
|
|
721
|
-
const
|
|
722
|
-
|
|
780
|
+
const a = this.calculateDistanceByHaversine(e[s], e[s + 1], n);
|
|
781
|
+
r.push(a), o += a;
|
|
723
782
|
}
|
|
724
783
|
if (t && e.length > 2) {
|
|
725
784
|
const s = this.calculateDistanceByHaversine(e[e.length - 1], e[0], n);
|
|
726
|
-
|
|
785
|
+
r.push(s), o += s;
|
|
727
786
|
}
|
|
728
|
-
return { segments:
|
|
787
|
+
return { segments: r, total: o };
|
|
729
788
|
}
|
|
730
789
|
};
|
|
731
|
-
class
|
|
790
|
+
class $ {
|
|
732
791
|
/**
|
|
733
792
|
* 转换为标准金额格式(带千分位和两位小数)
|
|
734
793
|
* @param num 要转换的数字
|
|
@@ -758,40 +817,40 @@ class j {
|
|
|
758
817
|
throw new Error("输入不是有效的数字");
|
|
759
818
|
if (t > 9999999999999e-2 || t < -9999999999999e-2)
|
|
760
819
|
throw new Error("输入数字超出范围");
|
|
761
|
-
const
|
|
762
|
-
let
|
|
763
|
-
if (
|
|
764
|
-
|
|
820
|
+
const r = t < 0, o = Math.abs(t), s = Math.floor(o), a = Math.round((o - s) * 100), u = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"], i = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"], d = ["角", "分"];
|
|
821
|
+
let c = "", l = s;
|
|
822
|
+
if (l === 0)
|
|
823
|
+
c = u[0];
|
|
765
824
|
else {
|
|
766
825
|
let f = 0;
|
|
767
|
-
for (;
|
|
768
|
-
const
|
|
769
|
-
|
|
826
|
+
for (; l > 0; ) {
|
|
827
|
+
const g = l % 10;
|
|
828
|
+
g !== 0 ? c = u[g] + i[f] + c : c.charAt(0) !== u[0] && (c = u[g] + c), l = Math.floor(l / 10), f++;
|
|
770
829
|
}
|
|
771
|
-
|
|
830
|
+
c = c.replace(/零+/g, "零"), c = c.replace(/零+$/, "");
|
|
772
831
|
}
|
|
773
832
|
let h = "";
|
|
774
|
-
if (
|
|
775
|
-
const f = Math.floor(
|
|
776
|
-
f > 0 && (h +=
|
|
833
|
+
if (a > 0) {
|
|
834
|
+
const f = Math.floor(a / 10), g = a % 10;
|
|
835
|
+
f > 0 && (h += u[f] + d[0]), g > 0 && (h += u[g] + d[1]);
|
|
777
836
|
} else
|
|
778
837
|
h = "整";
|
|
779
|
-
let
|
|
780
|
-
return
|
|
838
|
+
let p = (r ? "负" : "") + c + "圆" + h;
|
|
839
|
+
return p === "零圆整" && (p = "零圆"), p;
|
|
781
840
|
} catch (t) {
|
|
782
841
|
return console.error("转换失败:", t), "格式错误";
|
|
783
842
|
}
|
|
784
843
|
}
|
|
785
844
|
}
|
|
786
|
-
const
|
|
845
|
+
const M = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
787
846
|
__proto__: null,
|
|
788
|
-
toLetter:
|
|
789
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
847
|
+
toLetter: M
|
|
848
|
+
}, Symbol.toStringTag, { value: "Module" })), E = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
790
849
|
__proto__: null,
|
|
791
|
-
toMoney:
|
|
792
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
793
|
-
...
|
|
794
|
-
...
|
|
850
|
+
toMoney: E
|
|
851
|
+
}, Symbol.toStringTag, { value: "Module" })), N = {
|
|
852
|
+
...x,
|
|
853
|
+
...B,
|
|
795
854
|
/**
|
|
796
855
|
* 判断是否为数字
|
|
797
856
|
* @param val 待判断的值
|
|
@@ -800,7 +859,7 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
800
859
|
isNumber(e) {
|
|
801
860
|
return typeof e == "number" && !isNaN(e);
|
|
802
861
|
}
|
|
803
|
-
},
|
|
862
|
+
}, P = {
|
|
804
863
|
/**
|
|
805
864
|
* 判断对象是否为空
|
|
806
865
|
* @param obj 对象
|
|
@@ -827,11 +886,11 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
827
886
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
828
887
|
deepCopy(e, n) {
|
|
829
888
|
for (const t in e) {
|
|
830
|
-
const
|
|
831
|
-
|
|
889
|
+
const r = e[t];
|
|
890
|
+
r instanceof Object ? (n[t] = {}, this.deepCopy(r, n[t])) : r instanceof Array ? (n[t] = [], this.deepCopy(r, n[t])) : n[t] = e[t];
|
|
832
891
|
}
|
|
833
892
|
}
|
|
834
|
-
},
|
|
893
|
+
}, F = {
|
|
835
894
|
/**
|
|
836
895
|
* 脱敏
|
|
837
896
|
* @param phone 电话号码/手机号码
|
|
@@ -840,7 +899,7 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
840
899
|
desensitize(e) {
|
|
841
900
|
return e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : "";
|
|
842
901
|
}
|
|
843
|
-
},
|
|
902
|
+
}, V = {
|
|
844
903
|
/**
|
|
845
904
|
* 生成随机颜色
|
|
846
905
|
* @returns 随机颜色值
|
|
@@ -864,7 +923,7 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
864
923
|
uniqueId() {
|
|
865
924
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
866
925
|
}
|
|
867
|
-
},
|
|
926
|
+
}, W = {
|
|
868
927
|
/**
|
|
869
928
|
* 验证手机号
|
|
870
929
|
*/
|
|
@@ -901,7 +960,7 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
901
960
|
* 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
|
|
902
961
|
*/
|
|
903
962
|
decimal: /^0\.(0[1-9]|[1-9][0-9]*)$/
|
|
904
|
-
},
|
|
963
|
+
}, Y = {
|
|
905
964
|
/**
|
|
906
965
|
* 通过key值获取 localStorage 中存储的某个值
|
|
907
966
|
* @param key 获取的key
|
|
@@ -948,7 +1007,7 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
948
1007
|
removeSession(e) {
|
|
949
1008
|
sessionStorage.removeItem(e);
|
|
950
1009
|
}
|
|
951
|
-
},
|
|
1010
|
+
}, z = {
|
|
952
1011
|
/**
|
|
953
1012
|
* 判断某元素是否在字符串中-比includes()方法更兼容,includes为ES6新增方法,IE不支持。小程序也不支持
|
|
954
1013
|
* @param str 字符串
|
|
@@ -990,11 +1049,11 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
990
1049
|
*/
|
|
991
1050
|
indexsOfAppear(e, n) {
|
|
992
1051
|
let t = -1;
|
|
993
|
-
const
|
|
1052
|
+
const r = [];
|
|
994
1053
|
do
|
|
995
|
-
t = e.indexOf(n, t + 1), t !== -1 &&
|
|
1054
|
+
t = e.indexOf(n, t + 1), t !== -1 && r.push(t);
|
|
996
1055
|
while (t !== -1);
|
|
997
|
-
return
|
|
1056
|
+
return r;
|
|
998
1057
|
},
|
|
999
1058
|
/**
|
|
1000
1059
|
* 获取字符串中出现次数最多的字符和次数
|
|
@@ -1004,30 +1063,30 @@ const b = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], S = /*
|
|
|
1004
1063
|
getMaxTimesAndVal(e) {
|
|
1005
1064
|
const n = [0, ""], t = {};
|
|
1006
1065
|
for (let s = 0; s < e.length; s++) {
|
|
1007
|
-
const
|
|
1008
|
-
t[
|
|
1066
|
+
const a = e.charAt(s);
|
|
1067
|
+
t[a] ? t[a]++ : t[a] = 1;
|
|
1009
1068
|
}
|
|
1010
|
-
let
|
|
1069
|
+
let r = 1;
|
|
1011
1070
|
for (const s in t)
|
|
1012
|
-
|
|
1013
|
-
const
|
|
1071
|
+
r < t[s] && (r = t[s]);
|
|
1072
|
+
const o = [];
|
|
1014
1073
|
for (const s in t)
|
|
1015
|
-
|
|
1016
|
-
return n[0] =
|
|
1074
|
+
r == t[s] && o.push(s);
|
|
1075
|
+
return n[0] = r, n[1] = o.join(), n;
|
|
1017
1076
|
}
|
|
1018
|
-
},
|
|
1077
|
+
}, C = (e) => {
|
|
1019
1078
|
const t = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
|
|
1020
1079
|
return t ? decodeURIComponent(t[1]) : null;
|
|
1021
1080
|
};
|
|
1022
|
-
function
|
|
1081
|
+
function D(e) {
|
|
1023
1082
|
return new URLSearchParams(window.location.search).get(e);
|
|
1024
1083
|
}
|
|
1025
|
-
const
|
|
1084
|
+
const R = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1026
1085
|
__proto__: null,
|
|
1027
|
-
getQueryInfoByName:
|
|
1028
|
-
getQueryParam:
|
|
1029
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
1030
|
-
...
|
|
1086
|
+
getQueryInfoByName: C,
|
|
1087
|
+
getQueryParam: D
|
|
1088
|
+
}, Symbol.toStringTag, { value: "Module" })), q = {
|
|
1089
|
+
...R,
|
|
1031
1090
|
/**
|
|
1032
1091
|
* 获取当前域名
|
|
1033
1092
|
* @returns 当前url链接的host信息
|
|
@@ -1042,7 +1101,7 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1042
1101
|
getPath() {
|
|
1043
1102
|
return window.location.pathname;
|
|
1044
1103
|
}
|
|
1045
|
-
},
|
|
1104
|
+
}, Z = {
|
|
1046
1105
|
/**
|
|
1047
1106
|
* 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
|
|
1048
1107
|
* @param list 瀑布流数据-数组
|
|
@@ -1052,13 +1111,13 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1052
1111
|
toList(e, n = 2) {
|
|
1053
1112
|
console.log(e, n);
|
|
1054
1113
|
const t = {};
|
|
1055
|
-
for (let
|
|
1056
|
-
t[
|
|
1057
|
-
e.forEach((
|
|
1058
|
-
const
|
|
1059
|
-
for (const
|
|
1060
|
-
|
|
1061
|
-
return
|
|
1114
|
+
for (let o = 0; o < n; o++)
|
|
1115
|
+
t[o] = [];
|
|
1116
|
+
e.forEach((o, s) => t[s % n].push(o));
|
|
1117
|
+
const r = [];
|
|
1118
|
+
for (const o in t)
|
|
1119
|
+
r.push(...t[o]);
|
|
1120
|
+
return r;
|
|
1062
1121
|
},
|
|
1063
1122
|
/**
|
|
1064
1123
|
* js瀑布流布局
|
|
@@ -1067,37 +1126,37 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1067
1126
|
* @param step 间距
|
|
1068
1127
|
*/
|
|
1069
1128
|
jsLayout(e, n, t) {
|
|
1070
|
-
const
|
|
1129
|
+
const r = e.offsetWidth, o = n[0].offsetWidth, s = parseInt((r / o).toString()), a = (r - o * s) / (s - 1), u = [];
|
|
1071
1130
|
for (let i = 0, d = n.length; i < d; i++) {
|
|
1072
|
-
const
|
|
1131
|
+
const c = n[i];
|
|
1073
1132
|
if (i < s)
|
|
1074
|
-
|
|
1133
|
+
c.style.left = (o + a) * i + "px", u[i] = c.offsetHeight;
|
|
1075
1134
|
else {
|
|
1076
|
-
const { index:
|
|
1077
|
-
|
|
1135
|
+
const { index: l, value: h } = b.getMinValueAndIndex(u);
|
|
1136
|
+
c.style.left = (o + a) * l + "px", c.style.top = h + t + "px", u[l] = c.offsetHeight + t + h;
|
|
1078
1137
|
}
|
|
1079
1138
|
}
|
|
1080
1139
|
}
|
|
1081
1140
|
};
|
|
1082
1141
|
export {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1142
|
+
T as Base64Utils,
|
|
1143
|
+
$ as MoneyFormatter,
|
|
1144
|
+
b as arrayUtils,
|
|
1145
|
+
S as booleanUtils,
|
|
1146
|
+
O as cookieUtils,
|
|
1147
|
+
U as dateUtils,
|
|
1148
|
+
L as documentUtils,
|
|
1149
|
+
I as downloadUtils,
|
|
1150
|
+
H as echartsUtils,
|
|
1151
|
+
j as letterUtils,
|
|
1152
|
+
k as mapUtils,
|
|
1153
|
+
N as numberUtils,
|
|
1154
|
+
P as objectUtils,
|
|
1155
|
+
F as phoneUtils,
|
|
1156
|
+
V as randomUtils,
|
|
1157
|
+
W as regexpUtils,
|
|
1158
|
+
Y as storageUtils,
|
|
1159
|
+
z as stringUtils,
|
|
1160
|
+
q as urlUtils,
|
|
1161
|
+
Z as waterfallUtils
|
|
1103
1162
|
};
|
package/dist/utils.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.yhkitUtils={}))})(this,function(h){"use strict";const b=Object.assign({unique(t){return t?Array.from(new Set(t)):[]},isExist(t,n){return!t||!n?!1:t.indexOf(n)!==-1},countOfAppear(t,n){let e=0;for(const o of t)o===n&&e++;return e},indexsOfAppear(t,n){let e=-1;const o=[];do e=t.indexOf(n,e+1),e!==-1&&o.push(e);while(e!==-1);return o},sort(t,n="asc"){return t?t.sort((e,o)=>n==="asc"?e>o?1:-1:e<o?1:-1):[]},shuffle(t){if(!t)return[];for(let n=t.length-1;n>0;n--){const e=Math.floor(Math.random()*(n+1));[t[n],t[e]]=[t[e],t[n]]}return t},getMaxValue(t){return t?Math.max(...t):0},getMinValue(t){return t?Math.min(...t):0},getMinValueAndIndex(t){if(t.length===0)return{value:0,index:0};const n={value:t[0],index:0};for(let e=1,o=t.length;e<o;e++){const r=t[e];n.value>r&&(n.value=r,n.index=e)}return n},getMaxValueAndIndex(t){return t.length===0?{value:0,index:0}:t.reduce((n,e,o)=>e<n.value?{value:e,index:o}:n,{value:t[0],index:0})}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const n={};return t.forEach(e=>{const o=Object.assign({label:e.label,text:e.label},e);n[e?.value]=o}),n}},Symbol.toStringTag,{value:"Module"}))});class A{static BASE64_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";static toBlob(n,e="",o=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+=o){const u=i.slice(a,a+o),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:e})}catch(i){return console.error("Failed to convert base64 to blob:",i),null}}static toFile(n,e="file.txt",o="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:o});return new File([a],e,{type:o})}static encode(n){if(!n)return"";const e=this._stringToUtf8Bytes(n);return this._bytesToBase64(e)}static decode(n){if(!n)return"";n=n.replace(/\s/g,"");const e=this._base64ToBytes(n);return this._utf8BytesToString(e)}static _stringToUtf8Bytes(n){const e=[];for(let o=0;o<n.length;o++){let r=n.charCodeAt(o);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6),e.push(128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12),e.push(128|r>>6&63),e.push(128|r&63);else{o++;const s=r,c=n.charCodeAt(o);if(isNaN(c))throw new Error("代理对不完整");r=65536+((s&1023)<<10)+(c&1023),e.push(240|r>>18),e.push(128|r>>12&63),e.push(128|r>>6&63),e.push(128|r&63)}}return e}static _utf8BytesToString(n){let e="",o=0;for(;o<n.length;){const r=n[o++];if(r<128)e+=String.fromCharCode(r);else if(r>=192&&r<224){const s=n[o++]&63;e+=String.fromCharCode((r&31)<<6|s)}else if(r>=224&&r<240){const s=n[o++]&63,c=n[o++]&63;e+=String.fromCharCode((r&15)<<12|s<<6|c)}else if(r>=240&&r<248){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;e+=String.fromCharCode(d,a)}else e+="�"}return e}static _bytesToBase64(n){let e="",o=0;for(;o<n.length;){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,f=i&63;s?l?e+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+this.BASE64_CHARS.charAt(f):e+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(u)+"=":e+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+"=="}return e}static _base64ToBytes(n){const e=n.length;let o=0;e>=2&&(n[e-1]==="="&&o++,n[e-2]==="="&&o++);const r=Math.floor(e*3/4)-o,s=new Array(r),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<e;){const d=c[n.charCodeAt(i++)],a=c[n.charCodeAt(i++)],u=i<e?c[n.charCodeAt(i++)]:-1,f=i<e?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 w={isEmptyString(t){return typeof t=="string"&&t.trim()===""},isNumber(t){return typeof t=="number"&&!isNaN(t)},isObject(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)},isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},isBoolean(t){return typeof t=="boolean"},isArray(t){return Array.isArray(t)},isFunction(t){return typeof t=="function"},isPromise(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"},isElement(t){return t instanceof Element},isPhone(t){return/^1[3-9]\d{9}$/.test(t)},isEmail(t){return/^[\w.-]+@[\w.-]+\.\w+$/.test(t)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},isImageLoaded(t){return t.complete&&t.naturalWidth!==0},isInViewport(t){const n=t.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(t){return t%4===0&&t%100!==0||t%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},S={getCookie(t){if(!t)return;const n=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(t,n,e=7){const o=new Date;o.setTime(o.getTime()+e*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(n)};expires=${o.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},M={getTimeString(t,n=!1){return n?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,n){const e=new Date(t).getTime(),o=new Date(n).getTime();return e>o?Math.abs(Math.floor((e-o)/(24*3600*1e3))):Math.abs(Math.floor((o-e)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(t,n,e){let o=e;for(let r=1;r<n;r++)switch(r){case 1:case 3:case 5:case 7:case 8:case 10:case 12:o+=31;break;case 2:w.isLeapYear(t)?o+=29:o+=28;break;default:o+=30;break}return o}},U={getOffsetTop(t){if(!t)throw new Error("Element is not provided");if(t instanceof SVGElement){const e=t.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;return e.top+o}let n=0;for(;t;)n+=t.offsetTop,t=t.offsetParent;return n},getScrollValue(){const t={scrollLeft:0,scrollTop:0};return t.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,t.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,t},getPageValue(t){t=t||window.event;const n=t.pageX||t.clientX+this.getScrollValue().scrollLeft,e=t.pageY||t.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:e}},addEventListener(t,n,e){t.addEventListener?t.addEventListener(n,e):t.attachEvent?t.attachEvent("on"+n,e):t["on"+n]=e},getViewportWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},getViewportHeight(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}},B={saveAsBlob(t,n){const e=document.createElement("a"),o=window.URL.createObjectURL(t);e.href=o,e.download=n,document.body.appendChild(e),e.click(),URL.revokeObjectURL(o),document.body.removeChild(e)}},E={animate(t,n){let e=-1;const o=t.series[0].data.length;let r;r=setInterval(()=>{n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:e}),e=(e+1)%o,n.dispatchAction({type:"highlight",seriesIndex:0,dataIndex:e}),n.dispatchAction({type:"showTip",seriesIndex:0,dataIndex:e}),e>o&&(e=0)},2e3),n.on("mouseover",()=>{clearInterval(r),n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:e})})}},C={sortFromA2Z(t){return t?.length?t.sort((e,o)=>{const r=e.toUpperCase(),s=o.toUpperCase();return r<s?-1:r>s?1:0}):void 0}},_={degrees2Radians(t){return t*Math.PI/180},getDistance(t,n,e,o){const r=this.degrees2Radians(t),s=this.degrees2Radians(e),c=r-s,l=this.degrees2Radians(n)-this.degrees2Radians(o);let i=2*Math.asin(Math.sqrt(Math.pow(Math.sin(c/2),2)+Math.cos(r)*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(t,n,e="km"){const o=this,r=t.longitude??t.lng,s=t.latitude??t.lat,c=n.longitude??n.lng,l=n.latitude??n.lat;if(r===void 0||s===void 0||c===void 0||l===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const i=6371,d=o.degrees2Radians(s),a=o.degrees2Radians(l),u=o.degrees2Radians(l-s),f=o.degrees2Radians(c-r),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(e){case"m":return y*1e3;case"mi":return y*.621371;case"nmi":return y*.539957;default:return y}},calculateDistancesByHaversine(t,n="km",e=!1){if(t.length<2)return{segments:[],total:0};const o=[];let r=0;for(let s=0;s<t.length-1;s++){const c=this.calculateDistanceByHaversine(t[s],t[s+1],n);o.push(c),r+=c}if(e&&t.length>2){const s=this.calculateDistanceByHaversine(t[t.length-1],t[0],n);o.push(s),r+=s}return{segments:o,total:r}}};class v{static toStandardFormat(n){try{const e=typeof n=="string"?parseFloat(n):n;if(isNaN(e))throw new Error("输入不是有效的数字");if(!isFinite(e))throw new Error("输入是无穷大");return e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(e){return console.error("格式化失败:",e),"格式错误"}}static toChineseFormat(n){try{const e=typeof n=="string"?parseFloat(n):n;if(isNaN(e))throw new Error("输入不是有效的数字");if(e>9999999999999e-2||e<-9999999999999e-2)throw new Error("输入数字超出范围");const o=e<0,r=Math.abs(e),s=Math.floor(r),c=Math.round((r-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=(o?"负":"")+a+"圆"+f;return p==="零圆整"&&(p="零圆"),p}catch(e){return console.error("转换失败:",e),"格式错误"}}}const O={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:t=>t>25||t<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:t=>t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"})),isNumber(t){return typeof t=="number"&&!isNaN(t)}},x={isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},copy(t,n){for(const e in t)n[e]=t[e]},deepCopy(t,n){for(const e in t){const o=t[e];o instanceof Object?(n[e]={},this.deepCopy(o,n[e])):o instanceof Array?(n[e]=[],this.deepCopy(o,n[e])):n[e]=t[e]}}},R={desensitize(t){return t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""}},L={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(t,n){return Math.floor(Math.random()*(n-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},T={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]*)$/},I={getLocal(t){return localStorage.getItem(t)},setLocal(t,n){localStorage.setItem(t,n)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,n){sessionStorage.setItem(t,n)},removeSession(t){sessionStorage.removeItem(t)}},j={isExist(t,n){if(!t||!n)return!1;const e=t.split(",");return console.log("判断某元素是否在字符串中",e.indexOf(n)===-1),e.indexOf(n)!==-1},includes(t,n){return!t||!n?!1:t.includes(n)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},indexsOfAppear(t,n){let e=-1;const o=[];do e=t.indexOf(n,e+1),e!==-1&&o.push(e);while(e!==-1);return o},getMaxTimesAndVal(t){const n=[0,""],e={};for(let s=0;s<t.length;s++){const c=t.charAt(s);e[c]?e[c]++:e[c]=1}let o=1;for(const s in e)o<e[s]&&(o=e[s]);const r=[];for(const s in e)o==e[s]&&r.push(s);return n[0]=o,n[1]=r.join(),n}},k=t=>{const e=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return e?decodeURIComponent(e[1]):null};function H(t){return new URLSearchParams(window.location.search).get(t)}const P={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:k,getQueryParam:H},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},N={toList(t,n=2){console.log(t,n);const e={};for(let r=0;r<n;r++)e[r]=[];t.forEach((r,s)=>e[s%n].push(r));const o=[];for(const r in e)o.push(...e[r]);return o},jsLayout(t,n,e){const o=t.offsetWidth,r=n[0].offsetWidth,s=parseInt((o/r).toString()),c=(o-r*s)/(s-1),l=[];for(let i=0,d=n.length;i<d;i++){const a=n[i];if(i<s)a.style.left=(r+c)*i+"px",l[i]=a.offsetHeight;else{const{index:u,value:f}=b.getMinValueAndIndex(l);a.style.left=(r+c)*u+"px",a.style.top=f+e+"px",l[u]=a.offsetHeight+e+f}}}};h.Base64Utils=A,h.MoneyFormatter=v,h.arrayUtils=b,h.booleanUtils=w,h.cookieUtils=S,h.dateUtils=M,h.documentUtils=U,h.downloadUtils=B,h.echartsUtils=E,h.letterUtils=C,h.mapUtils=_,h.numberUtils=O,h.objectUtils=x,h.phoneUtils=R,h.randomUtils=L,h.regexpUtils=T,h.storageUtils=I,h.stringUtils=j,h.urlUtils=P,h.waterfallUtils=N,Object.defineProperty(h,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=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 o of e)o===n&&t++;return t},indexsOfAppear(e,n){let t=-1;const o=[];do t=e.indexOf(n,t+1),t!==-1&&o.push(t);while(t!==-1);return o},sort(e,n="asc"){return e?e.sort((t,o)=>n==="asc"?t>o?1:-1:t<o?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,o=e.length;t<o;t++){const r=e[t];n.value>r&&(n.value=r,n.index=t)}return n},getMaxValueAndIndex(e){return e.length===0?{value:0,index:0}:e.reduce((n,t,o)=>t<n.value?{value:t,index:o}:n,{value:e[0],index:0})}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const n={};return e.forEach(t=>{const o=Object.assign({label:t.label,text:t.label},t);n[t?.value]=o}),n}},Symbol.toStringTag,{value:"Module"}))});class M{static BASE64_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";static toBlob(n,t="",o=512){const s=(n.split(",")[1]||n).replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),u=s+c;try{const i=atob(u),d=[];for(let a=0;a<i.length;a+=o){const l=i.slice(a,a+o),f=new Array(l.length);for(let g=0;g<l.length;g++)f[g]=l.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",o="text/plain"){const s=n.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),c="=".repeat((4-s.length%4)%4),u=s+c,i=atob(u),d=[];for(let l=0;l<i.length;l+=512){const f=i.slice(l,l+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:o});return new File([a],t,{type:o})}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 o=0;o<n.length;o++){let r=n.charCodeAt(o);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6),t.push(128|r&63);else if(r<55296||r>=57344)t.push(224|r>>12),t.push(128|r>>6&63),t.push(128|r&63);else{o++;const s=r,c=n.charCodeAt(o);if(isNaN(c))throw new Error("代理对不完整");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)}}return t}static _utf8BytesToString(n){let t="",o=0;for(;o<n.length;){const r=n[o++];if(r<128)t+=String.fromCharCode(r);else if(r>=192&&r<224){const s=n[o++]&63;t+=String.fromCharCode((r&31)<<6|s)}else if(r>=224&&r<240){const s=n[o++]&63,c=n[o++]&63;t+=String.fromCharCode((r&15)<<12|s<<6|c)}else if(r>=240&&r<248){const s=n[o++]&63,c=n[o++]&63,u=n[o++]&63,i=(r&7)<<18|s<<12|c<<6|u,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="",o=0;for(;o<n.length;){const r=n[o++],s=o<n.length,c=s?n[o++]:0,u=o<n.length,i=u?n[o++]:0,d=r>>2,a=(r&3)<<4|c>>4,l=(c&15)<<2|i>>6,f=i&63;s?u?t+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(l)+this.BASE64_CHARS.charAt(f):t+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+this.BASE64_CHARS.charAt(l)+"=":t+=this.BASE64_CHARS.charAt(d)+this.BASE64_CHARS.charAt(a)+"=="}return t}static _base64ToBytes(n){const t=n.length;let o=0;t>=2&&(n[t-1]==="="&&o++,n[t-2]==="="&&o++);const r=Math.floor(t*3/4)-o,s=new Array(r),c=new Array(256).fill(-1);for(let d=0;d<this.BASE64_CHARS.length;d++)c[this.BASE64_CHARS.charCodeAt(d)]=d;let u=0,i=0;for(;i<t;){const d=c[n.charCodeAt(i++)],a=c[n.charCodeAt(i++)],l=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[u++]=p,l!==-1){const g=(a&15)<<4|l>>2;if(s[u++]=g,f!==-1){const y=(l&3)<<6|f;s[u++]=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={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 o=new Date;o.setTime(o.getTime()+t*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(n)};expires=${o.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},E={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(),o=new Date(n).getTime();return t>o?Math.abs(Math.floor((t-o)/(24*3600*1e3))):Math.abs(Math.floor((o-t)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(e,n,t){let o=t;for(let r=1;r<n;r++)switch(r){case 1:case 3:case 5:case 7:case 8:case 10:case 12:o+=31;break;case 2:S.isLeapYear(e)?o+=29:o+=28;break;default:o+=30;break}return o},getTimeStringAutoShort2(e,n){const t=new Date,o=new Date(e),r=t.getFullYear(),s=t.getMonth()+1,c=t.getDate(),u=o.getFullYear(),i=o.getMonth()+1,d=o.getDate();let a="";const l=n?" "+this.formatDate(o,"hh:mm"):"";if(r===u){const g=t.getTime()-e;if(s===i&&c===d)g<60*1e3?a="刚刚":a=this.formatDate(o,"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="昨天"+l;else if(i===b.getMonth()+1&&d===b.getDate())a="前天"+l;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[o.getDay()]+l}else a=this.formatDate(o,"yyyy/M/d")+l}}else a=this.formatDate(o,"yyyy/M/d")+l;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 o in t)new RegExp("("+o+")").test(n)&&(n=n.replace(RegExp.$1,RegExp.$1.length===1?t[o]:("00"+t[o]).substr((""+t[o]).length)));return n}},B={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const t=e.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;return t.top+o}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}},C={saveAsBlob(e,n){const t=document.createElement("a"),o=window.URL.createObjectURL(e);t.href=o,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(o),document.body.removeChild(t)}},D={animate(e,n){let t=-1;const o=e.series[0].data.length;let r;r=setInterval(()=>{n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:t}),t=(t+1)%o,n.dispatchAction({type:"highlight",seriesIndex:0,dataIndex:t}),n.dispatchAction({type:"showTip",seriesIndex:0,dataIndex:t}),t>o&&(t=0)},2e3),n.on("mouseover",()=>{clearInterval(r),n.dispatchAction({type:"downplay",seriesIndex:0,dataIndex:t})})}},x={sortFromA2Z(e){return e?.length?e.sort((t,o)=>{const r=t.toUpperCase(),s=o.toUpperCase();return r<s?-1:r>s?1:0}):void 0}},R={degrees2Radians(e){return e*Math.PI/180},getDistance(e,n,t,o){const r=this.degrees2Radians(e),s=this.degrees2Radians(t),c=r-s,u=this.degrees2Radians(n)-this.degrees2Radians(o);let i=2*Math.asin(Math.sqrt(Math.pow(Math.sin(c/2),2)+Math.cos(r)*Math.cos(s)*Math.pow(Math.sin(u/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 o=this,r=e.longitude??e.lng,s=e.latitude??e.lat,c=n.longitude??n.lng,u=n.latitude??n.lat;if(r===void 0||s===void 0||c===void 0||u===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const i=6371,d=o.degrees2Radians(s),a=o.degrees2Radians(u),l=o.degrees2Radians(u-s),f=o.degrees2Radians(c-r),p=Math.sin(l/2)*Math.sin(l/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 o=[];let r=0;for(let s=0;s<e.length-1;s++){const c=this.calculateDistanceByHaversine(e[s],e[s+1],n);o.push(c),r+=c}if(t&&e.length>2){const s=this.calculateDistanceByHaversine(e[e.length-1],e[0],n);o.push(s),r+=s}return{segments:o,total:r}}};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 o=t<0,r=Math.abs(t),s=Math.floor(r),c=Math.round((r-s)*100),u=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],i=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],d=["角","分"];let a="",l=s;if(l===0)a=u[0];else{let g=0;for(;l>0;){const y=l%10;y!==0?a=u[y]+i[g]+a:a.charAt(0)!==u[0]&&(a=u[y]+a),l=Math.floor(l/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+=u[g]+d[0]),y>0&&(f+=u[y]+d[1])}else f="整";let p=(o?"负":"")+a+"圆"+f;return p==="零圆整"&&(p="零圆"),p}catch(t){return console.error("转换失败:",t),"格式错误"}}}const _={...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)}},v={isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},copy(e,n){for(const t in e)n[t]=e[t]},deepCopy(e,n){for(const t in e){const o=e[t];o instanceof Object?(n[t]={},this.deepCopy(o,n[t])):o instanceof Array?(n[t]=[],this.deepCopy(o,n[t])):n[t]=e[t]}}},O={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},L={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]*)$/},j={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)}},H={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 o=[];do t=e.indexOf(n,t+1),t!==-1&&o.push(t);while(t!==-1);return o},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 o=1;for(const s in t)o<t[s]&&(o=t[s]);const r=[];for(const s in t)o==t[s]&&r.push(s);return n[0]=o,n[1]=r.join(),n}},k=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function $(e){return new URLSearchParams(window.location.search).get(e)}const P={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:k,getQueryParam:$},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},F={toList(e,n=2){console.log(e,n);const t={};for(let r=0;r<n;r++)t[r]=[];e.forEach((r,s)=>t[s%n].push(r));const o=[];for(const r in t)o.push(...t[r]);return o},jsLayout(e,n,t){const o=e.offsetWidth,r=n[0].offsetWidth,s=parseInt((o/r).toString()),c=(o-r*s)/(s-1),u=[];for(let i=0,d=n.length;i<d;i++){const a=n[i];if(i<s)a.style.left=(r+c)*i+"px",u[i]=a.offsetHeight;else{const{index:l,value:f}=A.getMinValueAndIndex(u);a.style.left=(r+c)*l+"px",a.style.top=f+t+"px",u[l]=a.offsetHeight+t+f}}}};h.Base64Utils=M,h.MoneyFormatter=T,h.arrayUtils=A,h.booleanUtils=S,h.cookieUtils=U,h.dateUtils=E,h.documentUtils=B,h.downloadUtils=C,h.echartsUtils=D,h.letterUtils=x,h.mapUtils=R,h.numberUtils=_,h.objectUtils=v,h.phoneUtils=O,h.randomUtils=L,h.regexpUtils=I,h.storageUtils=j,h.stringUtils=H,h.urlUtils=P,h.waterfallUtils=F,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -29,4 +29,18 @@ export declare const dateUtils: {
|
|
|
29
29
|
* @returns 当年的第几天
|
|
30
30
|
*/
|
|
31
31
|
getWhichDays(year: number, month: number, day: number): number;
|
|
32
|
+
/**
|
|
33
|
+
* 获取时间字符串(自动短化)
|
|
34
|
+
* @param timestamp 时间戳
|
|
35
|
+
* @param mustIncludeTime 是否必须包含时间
|
|
36
|
+
* @returns 时间字符串
|
|
37
|
+
*/
|
|
38
|
+
getTimeStringAutoShort2(timestamp: number, mustIncludeTime: boolean): string;
|
|
39
|
+
/**
|
|
40
|
+
* 格式化日期
|
|
41
|
+
* @param date 日期对象
|
|
42
|
+
* @param fmt 格式化字符串
|
|
43
|
+
* @returns 格式化后的日期字符串
|
|
44
|
+
*/
|
|
45
|
+
formatDate(date: Date, fmt: string): string;
|
|
32
46
|
};
|