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