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