@base-web-kits/base-tools-web 1.1.5 → 1.1.8
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/README.md +4 -4
- package/dist/base-tools-web.umd.global.js +337 -264
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +345 -1269
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +343 -1265
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/web/network/request.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,176 +1,218 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
8
18
|
};
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
16
39
|
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
40
|
|
|
19
41
|
// src/web/clipboard/index.ts
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
try {
|
|
31
|
-
const textarea = document.createElement("textarea");
|
|
32
|
-
textarea.value = text;
|
|
33
|
-
textarea.setAttribute("readonly", "");
|
|
34
|
-
textarea.style.position = "fixed";
|
|
35
|
-
textarea.style.top = "0";
|
|
36
|
-
textarea.style.right = "-9999px";
|
|
37
|
-
textarea.style.opacity = "0";
|
|
38
|
-
textarea.style.pointerEvents = "none";
|
|
39
|
-
document.body.appendChild(textarea);
|
|
40
|
-
textarea.focus();
|
|
41
|
-
textarea.select();
|
|
42
|
-
textarea.setSelectionRange(0, textarea.value.length);
|
|
43
|
-
const ok = document.execCommand("copy");
|
|
44
|
-
document.body.removeChild(textarea);
|
|
45
|
-
if (ok) {
|
|
46
|
-
resolve();
|
|
47
|
-
} else {
|
|
48
|
-
reject(new Error("Copy failed: clipboard unavailable"));
|
|
42
|
+
function copyText(text) {
|
|
43
|
+
return __async(this, null, function* () {
|
|
44
|
+
if (typeof text !== "string") text = String(text != null ? text : "");
|
|
45
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
46
|
+
try {
|
|
47
|
+
yield navigator.clipboard.writeText(text);
|
|
48
|
+
return;
|
|
49
|
+
} catch (e) {
|
|
49
50
|
}
|
|
50
|
-
} catch (e) {
|
|
51
|
-
reject(e);
|
|
52
51
|
}
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
try {
|
|
54
|
+
const textarea = document.createElement("textarea");
|
|
55
|
+
textarea.value = text;
|
|
56
|
+
textarea.setAttribute("readonly", "");
|
|
57
|
+
textarea.style.position = "fixed";
|
|
58
|
+
textarea.style.top = "0";
|
|
59
|
+
textarea.style.right = "-9999px";
|
|
60
|
+
textarea.style.opacity = "0";
|
|
61
|
+
textarea.style.pointerEvents = "none";
|
|
62
|
+
document.body.appendChild(textarea);
|
|
63
|
+
textarea.focus();
|
|
64
|
+
textarea.select();
|
|
65
|
+
textarea.setSelectionRange(0, textarea.value.length);
|
|
66
|
+
const ok = document.execCommand("copy");
|
|
67
|
+
document.body.removeChild(textarea);
|
|
68
|
+
if (ok) {
|
|
69
|
+
resolve();
|
|
70
|
+
} else {
|
|
71
|
+
reject(new Error("Copy failed: clipboard unavailable"));
|
|
72
|
+
}
|
|
73
|
+
} catch (e) {
|
|
74
|
+
reject(e);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
53
77
|
});
|
|
54
78
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
function copyHtml(html) {
|
|
80
|
+
return __async(this, null, function* () {
|
|
81
|
+
const s = String(html != null ? html : "");
|
|
82
|
+
if (canWriteClipboard()) {
|
|
83
|
+
const plain = htmlToText(s);
|
|
84
|
+
yield writeClipboard({
|
|
85
|
+
"text/html": new Blob([s], { type: "text/html" }),
|
|
86
|
+
"text/plain": new Blob([plain], { type: "text/plain" })
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
return execCopyFromHtml(s);
|
|
91
|
+
});
|
|
66
92
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
93
|
+
function copyNode(node) {
|
|
94
|
+
return __async(this, null, function* () {
|
|
95
|
+
if (canWriteClipboard()) {
|
|
96
|
+
const { html: html2, text } = nodeToHtmlText(node);
|
|
97
|
+
yield writeClipboard({
|
|
98
|
+
"text/html": new Blob([html2], { type: "text/html" }),
|
|
99
|
+
"text/plain": new Blob([text], { type: "text/plain" })
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const { html } = nodeToHtmlText(node);
|
|
104
|
+
return execCopyFromHtml(html);
|
|
105
|
+
});
|
|
78
106
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
function copyImage(image) {
|
|
108
|
+
return __async(this, null, function* () {
|
|
109
|
+
const blob = yield toImageBlob(image);
|
|
110
|
+
if (!blob) throw new Error("Unsupported image source");
|
|
111
|
+
if (canWriteClipboard()) {
|
|
112
|
+
const type = blob.type || "image/png";
|
|
113
|
+
yield writeClipboard({ [type]: blob });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
throw new Error("Clipboard image write not supported");
|
|
117
|
+
});
|
|
88
118
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
119
|
+
function copyUrl(url) {
|
|
120
|
+
return __async(this, null, function* () {
|
|
121
|
+
const s = String(url != null ? url : "");
|
|
122
|
+
if (canWriteClipboard()) {
|
|
123
|
+
yield writeClipboard({
|
|
124
|
+
"text/uri-list": new Blob([s], { type: "text/uri-list" }),
|
|
125
|
+
"text/plain": new Blob([s], { type: "text/plain" })
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
yield copyText(s);
|
|
130
|
+
});
|
|
99
131
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
132
|
+
function copyBlob(blob) {
|
|
133
|
+
return __async(this, null, function* () {
|
|
134
|
+
if (canWriteClipboard()) {
|
|
135
|
+
const type = blob.type || "application/octet-stream";
|
|
136
|
+
yield writeClipboard({ [type]: blob });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
throw new Error("Clipboard blob write not supported");
|
|
140
|
+
});
|
|
107
141
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
142
|
+
function copyRtf(rtf) {
|
|
143
|
+
return __async(this, null, function* () {
|
|
144
|
+
const s = String(rtf != null ? rtf : "");
|
|
145
|
+
if (canWriteClipboard()) {
|
|
146
|
+
const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
|
|
147
|
+
yield writeClipboard({
|
|
148
|
+
"text/rtf": new Blob([s], { type: "text/rtf" }),
|
|
149
|
+
"text/plain": new Blob([plain], { type: "text/plain" })
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
yield copyText(s);
|
|
154
|
+
});
|
|
119
155
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
function copyTable(rows) {
|
|
157
|
+
return __async(this, null, function* () {
|
|
158
|
+
const data = Array.isArray(rows) ? rows : [];
|
|
159
|
+
const escapeHtml = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
160
|
+
const html = (() => {
|
|
161
|
+
const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
|
|
162
|
+
return `<table>${trs}</table>`;
|
|
163
|
+
})();
|
|
164
|
+
const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
|
|
165
|
+
const csv = data.map(
|
|
166
|
+
(r) => r.map((c) => {
|
|
167
|
+
const s = String(c);
|
|
168
|
+
const needQuote = /[",\n]/.test(s);
|
|
169
|
+
const escaped = s.replace(/"/g, '""');
|
|
170
|
+
return needQuote ? `"${escaped}"` : escaped;
|
|
171
|
+
}).join(",")
|
|
172
|
+
).join("\n");
|
|
173
|
+
if (canWriteClipboard()) {
|
|
174
|
+
yield writeClipboard({
|
|
175
|
+
"text/html": new Blob([html], { type: "text/html" }),
|
|
176
|
+
"text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
|
|
177
|
+
"text/csv": new Blob([csv], { type: "text/csv" }),
|
|
178
|
+
"text/plain": new Blob([tsv], { type: "text/plain" })
|
|
179
|
+
});
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
yield copyText(tsv);
|
|
183
|
+
});
|
|
146
184
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
185
|
+
function toImageBlob(image) {
|
|
186
|
+
return __async(this, null, function* () {
|
|
187
|
+
if (image instanceof Blob) return image;
|
|
188
|
+
if (image instanceof HTMLCanvasElement)
|
|
189
|
+
return yield new Promise((resolve, reject) => {
|
|
190
|
+
image.toBlob(
|
|
191
|
+
(b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
|
|
192
|
+
"image/png"
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
|
|
196
|
+
if (isBitmap) {
|
|
197
|
+
const cnv = document.createElement("canvas");
|
|
198
|
+
cnv.width = image.width;
|
|
199
|
+
cnv.height = image.height;
|
|
200
|
+
const ctx = cnv.getContext("2d");
|
|
201
|
+
ctx == null ? void 0 : ctx.drawImage(image, 0, 0);
|
|
202
|
+
return yield new Promise((resolve, reject) => {
|
|
203
|
+
cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
});
|
|
168
208
|
}
|
|
169
209
|
function canWriteClipboard() {
|
|
170
210
|
return !!(navigator.clipboard && typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined");
|
|
171
211
|
}
|
|
172
|
-
|
|
173
|
-
|
|
212
|
+
function writeClipboard(items) {
|
|
213
|
+
return __async(this, null, function* () {
|
|
214
|
+
yield navigator.clipboard.write([new ClipboardItem(items)]);
|
|
215
|
+
});
|
|
174
216
|
}
|
|
175
217
|
function htmlToText(html) {
|
|
176
218
|
const div = document.createElement("div");
|
|
@@ -178,9 +220,10 @@ function htmlToText(html) {
|
|
|
178
220
|
return div.textContent || "";
|
|
179
221
|
}
|
|
180
222
|
function nodeToHtmlText(node) {
|
|
223
|
+
var _a;
|
|
181
224
|
const container = document.createElement("div");
|
|
182
225
|
container.appendChild(node.cloneNode(true));
|
|
183
|
-
const html = node instanceof Element ? node.outerHTML
|
|
226
|
+
const html = node instanceof Element ? (_a = node.outerHTML) != null ? _a : container.innerHTML : container.innerHTML;
|
|
184
227
|
const text = container.textContent || "";
|
|
185
228
|
return { html, text };
|
|
186
229
|
}
|
|
@@ -199,11 +242,11 @@ function execCopyFromHtml(html) {
|
|
|
199
242
|
const selection = window.getSelection();
|
|
200
243
|
const range = document.createRange();
|
|
201
244
|
range.selectNodeContents(div);
|
|
202
|
-
selection
|
|
203
|
-
selection
|
|
245
|
+
selection == null ? void 0 : selection.removeAllRanges();
|
|
246
|
+
selection == null ? void 0 : selection.addRange(range);
|
|
204
247
|
const ok = document.execCommand("copy");
|
|
205
248
|
document.body.removeChild(div);
|
|
206
|
-
selection
|
|
249
|
+
selection == null ? void 0 : selection.removeAllRanges();
|
|
207
250
|
if (ok) {
|
|
208
251
|
resolve();
|
|
209
252
|
} else {
|
|
@@ -232,10 +275,11 @@ function setCookie(name, value, days) {
|
|
|
232
275
|
document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}`;
|
|
233
276
|
}
|
|
234
277
|
function getCookie(name) {
|
|
278
|
+
var _a;
|
|
235
279
|
const value = `; ${document.cookie}`;
|
|
236
280
|
const parts = value.split(`; ${name}=`);
|
|
237
281
|
if (parts.length === 2) {
|
|
238
|
-
const v = parts.pop()
|
|
282
|
+
const v = (_a = parts.pop()) == null ? void 0 : _a.split(";").shift();
|
|
239
283
|
return v ? decodeURIComponent(v) : null;
|
|
240
284
|
}
|
|
241
285
|
return null;
|
|
@@ -379,80 +423,87 @@ function unlockBodyScroll() {
|
|
|
379
423
|
}
|
|
380
424
|
|
|
381
425
|
// src/web/network/load.ts
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
} else if (url.includes(";base64,")) {
|
|
391
|
-
blobUrl = url;
|
|
392
|
-
} else {
|
|
393
|
-
if (fileName) {
|
|
394
|
-
const res = await fetch(url);
|
|
395
|
-
if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
|
|
396
|
-
const blob = await res.blob();
|
|
397
|
-
blobUrl = URL.createObjectURL(blob);
|
|
426
|
+
function download(url, fileName = "") {
|
|
427
|
+
return __async(this, null, function* () {
|
|
428
|
+
if (!url) return;
|
|
429
|
+
let blobUrl = "";
|
|
430
|
+
let needRevoke = false;
|
|
431
|
+
try {
|
|
432
|
+
if (url instanceof Blob) {
|
|
433
|
+
blobUrl = URL.createObjectURL(url);
|
|
398
434
|
needRevoke = true;
|
|
399
|
-
} else {
|
|
435
|
+
} else if (url.includes(";base64,")) {
|
|
400
436
|
blobUrl = url;
|
|
437
|
+
} else {
|
|
438
|
+
if (fileName) {
|
|
439
|
+
const res = yield fetch(url);
|
|
440
|
+
if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
|
|
441
|
+
const blob = yield res.blob();
|
|
442
|
+
blobUrl = URL.createObjectURL(blob);
|
|
443
|
+
needRevoke = true;
|
|
444
|
+
} else {
|
|
445
|
+
blobUrl = url;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const a = document.createElement("a");
|
|
449
|
+
a.href = blobUrl;
|
|
450
|
+
a.download = fileName;
|
|
451
|
+
document.body.appendChild(a);
|
|
452
|
+
a.click();
|
|
453
|
+
document.body.removeChild(a);
|
|
454
|
+
} finally {
|
|
455
|
+
if (needRevoke) {
|
|
456
|
+
setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
|
|
401
457
|
}
|
|
402
458
|
}
|
|
403
|
-
|
|
404
|
-
a.href = blobUrl;
|
|
405
|
-
a.download = fileName;
|
|
406
|
-
document.body.appendChild(a);
|
|
407
|
-
a.click();
|
|
408
|
-
document.body.removeChild(a);
|
|
409
|
-
} finally {
|
|
410
|
-
if (needRevoke) {
|
|
411
|
-
setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
459
|
+
});
|
|
414
460
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
461
|
+
function parseAxiosBlob(res) {
|
|
462
|
+
return __async(this, null, function* () {
|
|
463
|
+
const { data, headers, status, statusText, config } = res;
|
|
464
|
+
if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
|
|
465
|
+
if (data.type.includes("application/json")) {
|
|
466
|
+
const txt = yield data.text();
|
|
467
|
+
throw JSON.parse(txt);
|
|
468
|
+
}
|
|
469
|
+
const fileName = getDispositionFileName(headers["content-disposition"]);
|
|
470
|
+
return { blob: data, fileName };
|
|
471
|
+
});
|
|
424
472
|
}
|
|
425
473
|
function getDispositionFileName(disposition) {
|
|
474
|
+
var _a;
|
|
426
475
|
if (!disposition) return "";
|
|
427
476
|
const rfc5987 = /filename\*\s*=\s*([^']*)''([^;]*)/i.exec(disposition);
|
|
428
|
-
if (rfc5987
|
|
477
|
+
if (rfc5987 == null ? void 0 : rfc5987[2]) {
|
|
429
478
|
try {
|
|
430
479
|
return decodeURIComponent(rfc5987[2].trim()).replace(/[\r\n]+/g, "");
|
|
431
|
-
} catch {
|
|
480
|
+
} catch (e) {
|
|
432
481
|
return rfc5987[2].trim().replace(/[\r\n]+/g, "");
|
|
433
482
|
}
|
|
434
483
|
}
|
|
435
484
|
const old = /filename\s*=\s*(?:"([^"]*)"|([^";]*))(?=;|$)/i.exec(disposition);
|
|
436
|
-
if (old) return (old[1]
|
|
485
|
+
if (old) return ((_a = old[1]) != null ? _a : old[2]).trim().replace(/[\r\n]+/g, "");
|
|
437
486
|
return "";
|
|
438
487
|
}
|
|
439
|
-
|
|
440
|
-
return
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
488
|
+
function loadJs(src, attrs) {
|
|
489
|
+
return __async(this, null, function* () {
|
|
490
|
+
return new Promise((resolve, reject) => {
|
|
491
|
+
if (hasJs(src)) return resolve();
|
|
492
|
+
const script = document.createElement("script");
|
|
493
|
+
script.type = "text/javascript";
|
|
494
|
+
script.src = src;
|
|
495
|
+
if (attrs) {
|
|
496
|
+
const keys = Object.keys(attrs);
|
|
497
|
+
keys.forEach((key) => {
|
|
498
|
+
const v = attrs[key];
|
|
499
|
+
if (v === null || v === void 0 || v === false) return;
|
|
500
|
+
script.setAttribute(key, typeof v === "boolean" ? "" : v);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
script.onload = () => resolve();
|
|
504
|
+
script.onerror = (e) => reject(e);
|
|
505
|
+
document.head.appendChild(script);
|
|
506
|
+
});
|
|
456
507
|
});
|
|
457
508
|
}
|
|
458
509
|
function hasJs(src) {
|
|
@@ -463,23 +514,25 @@ function hasJs(src) {
|
|
|
463
514
|
return src2 && new URL(src2, document.baseURI).href === target;
|
|
464
515
|
});
|
|
465
516
|
}
|
|
466
|
-
|
|
467
|
-
return
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
517
|
+
function loadCss(href, attrs) {
|
|
518
|
+
return __async(this, null, function* () {
|
|
519
|
+
return new Promise((resolve, reject) => {
|
|
520
|
+
if (hasCss(href)) return resolve();
|
|
521
|
+
const link = document.createElement("link");
|
|
522
|
+
link.rel = "stylesheet";
|
|
523
|
+
link.href = href;
|
|
524
|
+
if (attrs) {
|
|
525
|
+
const keys = Object.keys(attrs);
|
|
526
|
+
keys.forEach((key) => {
|
|
527
|
+
const v = attrs[key];
|
|
528
|
+
if (v === null || v === void 0) return;
|
|
529
|
+
link.setAttribute(key, String(v));
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
link.onload = () => resolve();
|
|
533
|
+
link.onerror = (e) => reject(e);
|
|
534
|
+
document.head.appendChild(link);
|
|
535
|
+
});
|
|
483
536
|
});
|
|
484
537
|
}
|
|
485
538
|
function hasCss(href) {
|
|
@@ -499,994 +552,15 @@ function preloadImage(src) {
|
|
|
499
552
|
});
|
|
500
553
|
}
|
|
501
554
|
|
|
502
|
-
// src/ts/index.ts
|
|
503
|
-
var ts_exports = {};
|
|
504
|
-
__export(ts_exports, {
|
|
505
|
-
BigNumber: () => BigNumber,
|
|
506
|
-
EventBus: () => EventBus,
|
|
507
|
-
appendUrlParam: () => appendUrlParam,
|
|
508
|
-
arrayMove: () => arrayMove,
|
|
509
|
-
buildOSSUrl: () => buildOSSUrl,
|
|
510
|
-
createTimeRandId: () => createTimeRandId,
|
|
511
|
-
createUUID: () => createUUID,
|
|
512
|
-
createViewRandId: () => createViewRandId,
|
|
513
|
-
dayjs: () => dayjs,
|
|
514
|
-
getAgeByBirthdate: () => getAgeByBirthdate,
|
|
515
|
-
getByteLength: () => getByteLength,
|
|
516
|
-
getCountdownParts: () => getCountdownParts,
|
|
517
|
-
getDateRangeAfter: () => getDateRangeAfter,
|
|
518
|
-
getDateRangeBefore: () => getDateRangeBefore,
|
|
519
|
-
getFileSuffix: () => getFileSuffix,
|
|
520
|
-
getFileType: () => getFileType,
|
|
521
|
-
getOSSAudio: () => getOSSAudio,
|
|
522
|
-
getOSSHls: () => getOSSHls,
|
|
523
|
-
getOSSImg: () => getOSSImg,
|
|
524
|
-
getOSSVideo: () => getOSSVideo,
|
|
525
|
-
getObjectKeys: () => getObjectKeys,
|
|
526
|
-
getObjectValue: () => getObjectValue,
|
|
527
|
-
getQnAudio: () => getQnAudio,
|
|
528
|
-
getQnHls: () => getQnHls,
|
|
529
|
-
getQnImg: () => getQnImg,
|
|
530
|
-
getQnVideo: () => getQnVideo,
|
|
531
|
-
isBankCard: () => isBankCard,
|
|
532
|
-
isChinese: () => isChinese,
|
|
533
|
-
isChineseName: () => isChineseName,
|
|
534
|
-
isDigits: () => isDigits,
|
|
535
|
-
isEmail: () => isEmail,
|
|
536
|
-
isHKMOPermit: () => isHKMOPermit,
|
|
537
|
-
isHexColor: () => isHexColor,
|
|
538
|
-
isIP: () => isIP,
|
|
539
|
-
isIPRange: () => isIPRange,
|
|
540
|
-
isIPv6: () => isIPv6,
|
|
541
|
-
isIdentityCard: () => isIdentityCard,
|
|
542
|
-
isLandline: () => isLandline,
|
|
543
|
-
isLatitude: () => isLatitude,
|
|
544
|
-
isLetter: () => isLetter,
|
|
545
|
-
isLicensePlate: () => isLicensePlate,
|
|
546
|
-
isLongitude: () => isLongitude,
|
|
547
|
-
isMilitaryId: () => isMilitaryId,
|
|
548
|
-
isMobilePhone: () => isMobilePhone,
|
|
549
|
-
isNumeric: () => isNumeric,
|
|
550
|
-
isOfficerId: () => isOfficerId,
|
|
551
|
-
isPassport: () => isPassport,
|
|
552
|
-
isPhone: () => isPhone,
|
|
553
|
-
isPortNumber: () => isPortNumber,
|
|
554
|
-
isSoldierId: () => isSoldierId,
|
|
555
|
-
isTaiwanPermit: () => isTaiwanPermit,
|
|
556
|
-
isTaxID: () => isTaxID,
|
|
557
|
-
isURL: () => isURL,
|
|
558
|
-
mathCompare: () => mathCompare,
|
|
559
|
-
mathDiv: () => mathDiv,
|
|
560
|
-
mathEqual: () => mathEqual,
|
|
561
|
-
mathFixed: () => mathFixed,
|
|
562
|
-
mathGreaterThan: () => mathGreaterThan,
|
|
563
|
-
mathGreaterThanOrEqual: () => mathGreaterThanOrEqual,
|
|
564
|
-
mathLessThan: () => mathLessThan,
|
|
565
|
-
mathLessThanOrEqual: () => mathLessThanOrEqual,
|
|
566
|
-
mathMinus: () => mathMinus,
|
|
567
|
-
mathPlus: () => mathPlus,
|
|
568
|
-
mathPow: () => mathPow,
|
|
569
|
-
mathRound: () => mathRound,
|
|
570
|
-
mathTimes: () => mathTimes,
|
|
571
|
-
randomBoolean: () => randomBoolean,
|
|
572
|
-
setObjectValue: () => setObjectValue,
|
|
573
|
-
toAsync: () => toAsync,
|
|
574
|
-
toChineseCurrency: () => toChineseCurrency,
|
|
575
|
-
toChineseNum: () => toChineseNum,
|
|
576
|
-
toDayjs: () => toDayjs,
|
|
577
|
-
toMaskName: () => toMaskName,
|
|
578
|
-
toMaskPhone: () => toMaskPhone,
|
|
579
|
-
toMaskText: () => toMaskText,
|
|
580
|
-
toThousandth: () => toThousandth,
|
|
581
|
-
withDistance: () => withDistance,
|
|
582
|
-
withUnit: () => withUnit,
|
|
583
|
-
withUnitPx: () => withUnitPx,
|
|
584
|
-
zeroPad: () => zeroPad
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
// src/ts/array/index.ts
|
|
588
|
-
function arrayMove(list, fromIndex, toIndex) {
|
|
589
|
-
const newList = [...list];
|
|
590
|
-
const [removed] = newList.splice(fromIndex, 1);
|
|
591
|
-
newList.splice(toIndex, 0, removed);
|
|
592
|
-
return newList;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// src/ts/async/index.ts
|
|
596
|
-
async function toAsync(p) {
|
|
597
|
-
try {
|
|
598
|
-
const data = await p;
|
|
599
|
-
return [data, null];
|
|
600
|
-
} catch (err) {
|
|
601
|
-
return [null, err];
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/ts/bean/EventBus.ts
|
|
606
|
-
import mitt from "mitt";
|
|
607
|
-
var EventBus = class {
|
|
608
|
-
_emitter = mitt();
|
|
609
|
-
/** 订阅 */
|
|
610
|
-
on(type, fn) {
|
|
611
|
-
this._emitter.on(type, fn);
|
|
612
|
-
return this;
|
|
613
|
-
}
|
|
614
|
-
/** 订阅一次 */
|
|
615
|
-
once(type, fn) {
|
|
616
|
-
const wrap = (event) => {
|
|
617
|
-
this._emitter.off(type, wrap);
|
|
618
|
-
fn(event);
|
|
619
|
-
};
|
|
620
|
-
this._emitter.on(type, wrap);
|
|
621
|
-
return this;
|
|
622
|
-
}
|
|
623
|
-
/** 发布 */
|
|
624
|
-
emit(type, event) {
|
|
625
|
-
this._emitter.emit(type, event);
|
|
626
|
-
return this;
|
|
627
|
-
}
|
|
628
|
-
/** 移除 */
|
|
629
|
-
off(type, fn) {
|
|
630
|
-
this._emitter.off(type, fn);
|
|
631
|
-
return this;
|
|
632
|
-
}
|
|
633
|
-
/** 清空 */
|
|
634
|
-
clear() {
|
|
635
|
-
this._emitter.all.clear();
|
|
636
|
-
return this;
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
// src/ts/day/index.ts
|
|
641
|
-
import dayjs from "dayjs";
|
|
642
|
-
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
643
|
-
import utc from "dayjs/plugin/utc";
|
|
644
|
-
import timezone from "dayjs/plugin/timezone";
|
|
645
|
-
import relativeTime from "dayjs/plugin/relativeTime";
|
|
646
|
-
import advancedFormat from "dayjs/plugin/advancedFormat";
|
|
647
|
-
import "dayjs/locale/zh-cn";
|
|
648
|
-
|
|
649
|
-
// src/ts/number/big.ts
|
|
650
|
-
import BigNumber from "bignumber.js";
|
|
651
|
-
function big(x) {
|
|
652
|
-
return x instanceof BigNumber ? x : new BigNumber(x);
|
|
653
|
-
}
|
|
654
|
-
function mathPlus(...rest) {
|
|
655
|
-
let acc = big(rest[0]);
|
|
656
|
-
for (const x of rest.slice(1)) acc = acc.plus(big(x));
|
|
657
|
-
return acc.toNumber();
|
|
658
|
-
}
|
|
659
|
-
function mathMinus(...rest) {
|
|
660
|
-
let acc = big(rest[0]);
|
|
661
|
-
for (const x of rest.slice(1)) acc = acc.minus(big(x));
|
|
662
|
-
return acc.toNumber();
|
|
663
|
-
}
|
|
664
|
-
function mathTimes(...rest) {
|
|
665
|
-
let acc = big(rest[0]);
|
|
666
|
-
for (const x of rest.slice(1)) acc = acc.times(big(x));
|
|
667
|
-
return acc.toNumber();
|
|
668
|
-
}
|
|
669
|
-
function mathDiv(...rest) {
|
|
670
|
-
let acc = big(rest[0]);
|
|
671
|
-
for (const x of rest.slice(1)) acc = acc.div(big(x));
|
|
672
|
-
return acc.toNumber();
|
|
673
|
-
}
|
|
674
|
-
function mathPow(x, y) {
|
|
675
|
-
return big(x).pow(big(y)).toNumber();
|
|
676
|
-
}
|
|
677
|
-
function mathRound(x, dp = 0, rm = BigNumber.ROUND_HALF_UP) {
|
|
678
|
-
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
679
|
-
}
|
|
680
|
-
function mathFixed(x, dp = 2, rm = BigNumber.ROUND_HALF_UP) {
|
|
681
|
-
return big(x).toFixed(dp, rm);
|
|
682
|
-
}
|
|
683
|
-
function mathCompare(a, b) {
|
|
684
|
-
return big(a).comparedTo(big(b));
|
|
685
|
-
}
|
|
686
|
-
function mathEqual(a, b) {
|
|
687
|
-
return big(a).isEqualTo(big(b));
|
|
688
|
-
}
|
|
689
|
-
function mathGreaterThan(a, b) {
|
|
690
|
-
return big(a).isGreaterThan(big(b));
|
|
691
|
-
}
|
|
692
|
-
function mathGreaterThanOrEqual(a, b) {
|
|
693
|
-
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
694
|
-
}
|
|
695
|
-
function mathLessThan(a, b) {
|
|
696
|
-
return big(a).isLessThan(big(b));
|
|
697
|
-
}
|
|
698
|
-
function mathLessThanOrEqual(a, b) {
|
|
699
|
-
return big(a).isLessThanOrEqualTo(big(b));
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// src/ts/number/format.ts
|
|
703
|
-
function zeroPad(n, len = 2) {
|
|
704
|
-
return String(n).padStart(len, "0");
|
|
705
|
-
}
|
|
706
|
-
function withUnit(num, unit = "") {
|
|
707
|
-
if (num === null || num === void 0 || num === "") return "";
|
|
708
|
-
if (typeof num === "number") return `${num}${unit}`;
|
|
709
|
-
const str = String(num).trim();
|
|
710
|
-
if (str === "") return "";
|
|
711
|
-
return isNaN(+str) ? str : `${str}${unit}`;
|
|
712
|
-
}
|
|
713
|
-
function withUnitPx(num) {
|
|
714
|
-
return withUnit(num, "px");
|
|
715
|
-
}
|
|
716
|
-
function withDistance(m) {
|
|
717
|
-
const n = Number(m ?? 0);
|
|
718
|
-
if (!Number.isFinite(n)) return "0m";
|
|
719
|
-
return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
|
|
720
|
-
}
|
|
721
|
-
function toThousandth(str) {
|
|
722
|
-
const v = String(str ?? "").trim();
|
|
723
|
-
if (v === "") return "";
|
|
724
|
-
let sign = "";
|
|
725
|
-
let num = v;
|
|
726
|
-
if (num[0] === "-" || num[0] === "+") {
|
|
727
|
-
sign = num[0];
|
|
728
|
-
num = num.slice(1);
|
|
729
|
-
}
|
|
730
|
-
const [intPart, decPart] = num.split(".");
|
|
731
|
-
const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
732
|
-
return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
|
|
733
|
-
}
|
|
734
|
-
function toChineseNum(num) {
|
|
735
|
-
const numInt = Math.trunc(+num);
|
|
736
|
-
if (numInt === 0) return "\u96F6";
|
|
737
|
-
const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
|
|
738
|
-
const unit = ["", "\u5341", "\u767E", "\u5343"];
|
|
739
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
740
|
-
const section4 = (n2) => {
|
|
741
|
-
let str = "", zeroFlag = false;
|
|
742
|
-
for (let i = 0; i < 4; i++) {
|
|
743
|
-
const d = n2 % 10;
|
|
744
|
-
n2 = Math.floor(n2 / 10);
|
|
745
|
-
if (d === 0) {
|
|
746
|
-
zeroFlag = true;
|
|
747
|
-
continue;
|
|
748
|
-
}
|
|
749
|
-
if (zeroFlag) str = digit[0] + str;
|
|
750
|
-
str = digit[d] + unit[i] + str;
|
|
751
|
-
zeroFlag = false;
|
|
752
|
-
}
|
|
753
|
-
return str;
|
|
754
|
-
};
|
|
755
|
-
let res = "";
|
|
756
|
-
let sectionIndex = 0;
|
|
757
|
-
let n = Math.abs(numInt);
|
|
758
|
-
while (n > 0) {
|
|
759
|
-
const seg = n % 1e4;
|
|
760
|
-
n = Math.floor(n / 1e4);
|
|
761
|
-
if (seg) {
|
|
762
|
-
const segStr = section4(seg);
|
|
763
|
-
res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
|
|
764
|
-
} else if (res && !res.startsWith("\u96F6")) {
|
|
765
|
-
res = `\u96F6${res}`;
|
|
766
|
-
}
|
|
767
|
-
sectionIndex++;
|
|
768
|
-
}
|
|
769
|
-
res = res.replace(/^一十/, "\u5341");
|
|
770
|
-
return numInt < 0 ? `\u8D1F${res}` : res;
|
|
771
|
-
}
|
|
772
|
-
function toChineseCurrency(amount, opts = {}) {
|
|
773
|
-
const dp = opts.precision ?? 2;
|
|
774
|
-
const rm = opts.rm ?? BigNumber.ROUND_HALF_UP;
|
|
775
|
-
const yuan = opts.yuanChar ?? "\u5143";
|
|
776
|
-
if (amount === null || amount === void 0) return "";
|
|
777
|
-
const bn = new BigNumber(amount);
|
|
778
|
-
if (!bn.isFinite()) return "";
|
|
779
|
-
const s = bn.toFixed(dp, rm);
|
|
780
|
-
const sign = s.startsWith("-") ? "\u8D1F" : "";
|
|
781
|
-
const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
|
|
782
|
-
const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
783
|
-
const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
784
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
785
|
-
const smallUnit = ["\u89D2", "\u5206", "\u5398"];
|
|
786
|
-
const section4 = (n) => {
|
|
787
|
-
let str = "";
|
|
788
|
-
let zeroFlag = false;
|
|
789
|
-
for (let i = 0; i < 4; i++) {
|
|
790
|
-
const d = n.mod(10).toNumber();
|
|
791
|
-
n = n.idiv(10);
|
|
792
|
-
if (d === 0) {
|
|
793
|
-
zeroFlag = true;
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
if (zeroFlag) str = digit[0] + str;
|
|
797
|
-
str = digit[d] + unit[i] + str;
|
|
798
|
-
zeroFlag = false;
|
|
799
|
-
}
|
|
800
|
-
return str.replace(/零+$/g, "");
|
|
801
|
-
};
|
|
802
|
-
const intNum = new BigNumber(intStr);
|
|
803
|
-
let res = "";
|
|
804
|
-
if (intNum.isZero()) {
|
|
805
|
-
res = digit[0];
|
|
806
|
-
} else {
|
|
807
|
-
let n = intNum.abs();
|
|
808
|
-
let sectionIndex = 0;
|
|
809
|
-
while (n.gt(0)) {
|
|
810
|
-
const seg = n.mod(1e4);
|
|
811
|
-
n = n.idiv(1e4);
|
|
812
|
-
if (seg.gt(0)) {
|
|
813
|
-
const segStr = section4(seg);
|
|
814
|
-
const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
|
|
815
|
-
const bu = sectionIndex ? bigUnit[sectionIndex] : "";
|
|
816
|
-
res = segStr + bu + (needZero ? digit[0] : "") + res;
|
|
817
|
-
} else if (res && !res.startsWith(digit[0])) {
|
|
818
|
-
res = digit[0] + res;
|
|
819
|
-
}
|
|
820
|
-
sectionIndex++;
|
|
821
|
-
}
|
|
822
|
-
res = res.replace(/^壹拾/, "\u62FE");
|
|
823
|
-
}
|
|
824
|
-
let frac = "";
|
|
825
|
-
for (let i = 0; i < Math.min(3, dp); i++) {
|
|
826
|
-
const ch = decStr[i] || "0";
|
|
827
|
-
const d = ch.charCodeAt(0) - 48;
|
|
828
|
-
if (d > 0) frac += digit[d] + smallUnit[i];
|
|
829
|
-
}
|
|
830
|
-
return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// src/ts/number/random.ts
|
|
834
|
-
function randomBoolean() {
|
|
835
|
-
return Math.random() < 0.5;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// src/ts/day/index.ts
|
|
839
|
-
dayjs.extend(customParseFormat);
|
|
840
|
-
dayjs.extend(utc);
|
|
841
|
-
dayjs.extend(timezone);
|
|
842
|
-
dayjs.extend(relativeTime);
|
|
843
|
-
dayjs.extend(advancedFormat);
|
|
844
|
-
dayjs.locale("zh-cn");
|
|
845
|
-
function toDayjs(t, fmt) {
|
|
846
|
-
if (t === null || t === void 0) return dayjs();
|
|
847
|
-
if (typeof t === "number") {
|
|
848
|
-
const s = String(Math.trunc(t));
|
|
849
|
-
return dayjs(s.length === 10 ? t * 1e3 : t, fmt);
|
|
850
|
-
}
|
|
851
|
-
if (typeof t === "string") {
|
|
852
|
-
const s = t.trim();
|
|
853
|
-
if (/^\d{10}$/.test(s)) return dayjs(Number(s) * 1e3, fmt);
|
|
854
|
-
if (/^\d{13}$/.test(s)) return dayjs(Number(s), fmt);
|
|
855
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY-MM-DD");
|
|
856
|
-
if (/^\d{4}\/\d{2}\/\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY/MM/DD");
|
|
857
|
-
if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
858
|
-
return dayjs(s, fmt || "YYYY-MM-DD HH:mm:ss");
|
|
859
|
-
if (/^\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
860
|
-
return dayjs(s, fmt || "YYYY/MM/DD HH:mm:ss");
|
|
861
|
-
return dayjs(s, fmt);
|
|
862
|
-
}
|
|
863
|
-
return dayjs(t, fmt);
|
|
864
|
-
}
|
|
865
|
-
function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
|
|
866
|
-
const now = toDayjs(Date.now());
|
|
867
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
868
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
869
|
-
const startDay = now.add(-n, "day");
|
|
870
|
-
const endDay = now;
|
|
871
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
872
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
873
|
-
return [start, end];
|
|
874
|
-
}
|
|
875
|
-
function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
|
|
876
|
-
const now = toDayjs(Date.now());
|
|
877
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
878
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
879
|
-
const startDay = now;
|
|
880
|
-
const endDay = now.add(n, "day");
|
|
881
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
882
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
883
|
-
return [start, end];
|
|
884
|
-
}
|
|
885
|
-
function getCountdownParts(diff) {
|
|
886
|
-
if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
|
|
887
|
-
const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
888
|
-
const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
|
|
889
|
-
const m = Math.floor(diff / (1e3 * 60) % 60);
|
|
890
|
-
const s = Math.floor(diff / 1e3 % 60);
|
|
891
|
-
const ms = diff % 1e3;
|
|
892
|
-
return {
|
|
893
|
-
d: zeroPad(d),
|
|
894
|
-
h: zeroPad(h),
|
|
895
|
-
m: zeroPad(m),
|
|
896
|
-
s: zeroPad(s),
|
|
897
|
-
ms: zeroPad(ms, 3)
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
function getAgeByBirthdate(birthdate) {
|
|
901
|
-
const birth = toDayjs(birthdate, "YYYY-MM-DD");
|
|
902
|
-
const now = toDayjs(Date.now());
|
|
903
|
-
const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
|
|
904
|
-
const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
|
|
905
|
-
if (adjustedMonths >= 12) {
|
|
906
|
-
let age = Math.floor(adjustedMonths / 12);
|
|
907
|
-
const birthdayThisYear = birth.add(age, "year");
|
|
908
|
-
if (now.isBefore(birthdayThisYear)) {
|
|
909
|
-
age--;
|
|
910
|
-
}
|
|
911
|
-
return { age, type: "year" };
|
|
912
|
-
}
|
|
913
|
-
return { age: adjustedMonths, type: "month" };
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
// src/ts/es-toolkit/index.ts
|
|
917
|
-
var es_toolkit_exports = {};
|
|
918
|
-
__reExport(es_toolkit_exports, es_toolkit_star);
|
|
919
|
-
import * as es_toolkit_star from "es-toolkit";
|
|
920
|
-
|
|
921
|
-
// src/ts/index.ts
|
|
922
|
-
__reExport(ts_exports, es_toolkit_exports);
|
|
923
|
-
|
|
924
|
-
// src/ts/object/index.ts
|
|
925
|
-
import { get, set } from "es-toolkit/compat";
|
|
926
|
-
function getObjectKeys(obj) {
|
|
927
|
-
return Object.keys(obj);
|
|
928
|
-
}
|
|
929
|
-
var getObjectValue = get;
|
|
930
|
-
var setObjectValue = set;
|
|
931
|
-
|
|
932
|
-
// src/ts/string/format.ts
|
|
933
|
-
function toMaskText(s, keepLeft = 1, keepRight = 0, maskChar = "*") {
|
|
934
|
-
if (!s) return "";
|
|
935
|
-
const v = String(s);
|
|
936
|
-
const l = Math.max(0, keepLeft);
|
|
937
|
-
const r = Math.max(0, keepRight);
|
|
938
|
-
const len = v.length;
|
|
939
|
-
const left = Math.min(l, len);
|
|
940
|
-
const right = Math.min(r, len - left);
|
|
941
|
-
const mid = len - left - right;
|
|
942
|
-
if (mid <= 0) return v;
|
|
943
|
-
const m = maskChar && maskChar.length > 0 ? maskChar : "*";
|
|
944
|
-
return v.slice(0, left) + m.repeat(mid) + v.slice(len - right);
|
|
945
|
-
}
|
|
946
|
-
function toMaskPhone(phone) {
|
|
947
|
-
return toMaskText(phone, 3, 4);
|
|
948
|
-
}
|
|
949
|
-
function toMaskName(name) {
|
|
950
|
-
if (!name) return "";
|
|
951
|
-
const v = String(name);
|
|
952
|
-
return v.length <= 2 ? toMaskText(v, 1, 0) : toMaskText(v, 1, 1);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
// src/ts/string/random.ts
|
|
956
|
-
function createUUID() {
|
|
957
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
958
|
-
const r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
|
|
959
|
-
return v.toString(16);
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
function createViewRandId(prefix = "id_") {
|
|
963
|
-
return `${prefix}${Math.random().toString(36).substring(2, 16)}`;
|
|
964
|
-
}
|
|
965
|
-
function createTimeRandId(digits = 6) {
|
|
966
|
-
const base = 10 ** (digits - 1);
|
|
967
|
-
const range = 9 * base;
|
|
968
|
-
const int = Math.floor(Math.random() * range) + base;
|
|
969
|
-
return `${Date.now()}${int}`;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
// src/ts/string/other.ts
|
|
973
|
-
function getByteLength(data) {
|
|
974
|
-
if (typeof data === "string") {
|
|
975
|
-
let byteLen = 0;
|
|
976
|
-
for (let i = 0; i < data.length; i++) {
|
|
977
|
-
const code = data.charCodeAt(i);
|
|
978
|
-
if (code <= 127) {
|
|
979
|
-
byteLen += 1;
|
|
980
|
-
} else if (code <= 2047) {
|
|
981
|
-
byteLen += 2;
|
|
982
|
-
} else if (code >= 55296 && code <= 56319) {
|
|
983
|
-
byteLen += 4;
|
|
984
|
-
i++;
|
|
985
|
-
} else {
|
|
986
|
-
byteLen += 3;
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
return byteLen;
|
|
990
|
-
}
|
|
991
|
-
if ("byteLength" in data) return data.byteLength;
|
|
992
|
-
if ("size" in data) return data.size;
|
|
993
|
-
throw new TypeError("getByteLength: Unsupported type");
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// src/ts/url/file/index.ts
|
|
997
|
-
var FILE_TYPE = {
|
|
998
|
-
img: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
|
|
999
|
-
video: ["mp4", "mov", "m4v"],
|
|
1000
|
-
voice: ["mp3", "wav", "m4a"],
|
|
1001
|
-
excel: ["csv", "xls", "xlsx", "xlsm", "ods"],
|
|
1002
|
-
word: ["txt", "doc", "docx", "pdf", "md", "wps"],
|
|
1003
|
-
zip: ["zip", "gz", "tar", "rar", "7z"],
|
|
1004
|
-
ppt: ["ppt", "pptx", "odp"],
|
|
1005
|
-
app: ["apk", "ipa"]
|
|
1006
|
-
};
|
|
1007
|
-
function getFileSuffix(fileName) {
|
|
1008
|
-
if (fileName.startsWith(".")) return "";
|
|
1009
|
-
const idx = fileName.lastIndexOf(".");
|
|
1010
|
-
return idx > 0 ? fileName.slice(idx + 1).toLowerCase() : "";
|
|
1011
|
-
}
|
|
1012
|
-
function getFileType(fileName) {
|
|
1013
|
-
const suffix = getFileSuffix(fileName);
|
|
1014
|
-
if (!suffix) return "unknown";
|
|
1015
|
-
const keys = getObjectKeys(FILE_TYPE);
|
|
1016
|
-
for (const key of keys) {
|
|
1017
|
-
if (FILE_TYPE[key].includes(suffix)) {
|
|
1018
|
-
return key;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
return "unknown";
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
// src/ts/url/oss/index.ts
|
|
1025
|
-
function getOSSImg(src, option) {
|
|
1026
|
-
return buildOSSUrl(src, "image", option);
|
|
1027
|
-
}
|
|
1028
|
-
function getOSSVideo(src, option) {
|
|
1029
|
-
return buildOSSUrl(src, "video", option);
|
|
1030
|
-
}
|
|
1031
|
-
function getOSSAudio(src, option) {
|
|
1032
|
-
return buildOSSUrl(src, "audio", option);
|
|
1033
|
-
}
|
|
1034
|
-
function getOSSHls(src, option) {
|
|
1035
|
-
return buildOSSUrl(src, "hls", option);
|
|
1036
|
-
}
|
|
1037
|
-
function buildOSSUrl(src, type, option) {
|
|
1038
|
-
if (!src || !option) return src;
|
|
1039
|
-
if (src.startsWith("blob:")) return src;
|
|
1040
|
-
if (src.includes(".svg")) return src;
|
|
1041
|
-
const segs = [];
|
|
1042
|
-
for (const [k, v] of Object.entries(option)) {
|
|
1043
|
-
const seg = k === "watermark" ? getWatermark(v) : getOSSSegs(k, v);
|
|
1044
|
-
if (seg) segs.push(seg);
|
|
1045
|
-
}
|
|
1046
|
-
if (!segs.length) return src;
|
|
1047
|
-
const base = src.split("?")[0];
|
|
1048
|
-
return `${base}?x-oss-process=${type}/${segs.join("/")}`;
|
|
1049
|
-
}
|
|
1050
|
-
function getOSSSegs(type, option) {
|
|
1051
|
-
if (!option && option !== 0) return "";
|
|
1052
|
-
if (option === true) return type;
|
|
1053
|
-
if (typeof option === "number" || typeof option === "string") return `${type},${option}`;
|
|
1054
|
-
const segs = Object.entries(option).map(([k, v]) => `${k}_${v}`).join(",");
|
|
1055
|
-
return segs ? `${type},${segs}` : "";
|
|
1056
|
-
}
|
|
1057
|
-
function getWatermark(w) {
|
|
1058
|
-
if (!w) return "";
|
|
1059
|
-
if (w.image) w.image = toBase64Url(w.image);
|
|
1060
|
-
if (w.text) w.text = toBase64Url(w.text);
|
|
1061
|
-
if (w.type) w.type = toBase64Url(w.type);
|
|
1062
|
-
return getOSSSegs("watermark", w);
|
|
1063
|
-
}
|
|
1064
|
-
function toBase64Url(s) {
|
|
1065
|
-
let b64 = "";
|
|
1066
|
-
if (typeof Buffer !== "undefined") {
|
|
1067
|
-
const buf = Buffer.from(s, "utf-8");
|
|
1068
|
-
b64 = buf.toString("base64");
|
|
1069
|
-
} else {
|
|
1070
|
-
try {
|
|
1071
|
-
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1072
|
-
} catch {
|
|
1073
|
-
b64 = "";
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
// src/ts/url/param/index.ts
|
|
1080
|
-
function appendUrlParam(url, param) {
|
|
1081
|
-
if (!param || typeof param !== "object") return url;
|
|
1082
|
-
const hashIndex = url.indexOf("#");
|
|
1083
|
-
const baseWithoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
1084
|
-
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
1085
|
-
const [base, existingQs] = baseWithoutHash.split("?");
|
|
1086
|
-
const parts = [];
|
|
1087
|
-
if (existingQs) parts.push(existingQs);
|
|
1088
|
-
for (const key in param) {
|
|
1089
|
-
const rawVal = param[key];
|
|
1090
|
-
if (rawVal === null || rawVal === void 0) continue;
|
|
1091
|
-
const val = typeof rawVal === "object" ? JSON.stringify(rawVal) : String(rawVal);
|
|
1092
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`);
|
|
1093
|
-
}
|
|
1094
|
-
const qs = parts.filter(Boolean).join("&");
|
|
1095
|
-
return base + (qs ? `?${qs}` : "") + hash;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// src/ts/url/qn/index.ts
|
|
1099
|
-
function getQnImg(src, option) {
|
|
1100
|
-
if (!src || !option) return src;
|
|
1101
|
-
if (src.startsWith("blob:")) return src;
|
|
1102
|
-
if (src.includes(".svg")) return src;
|
|
1103
|
-
const segs = [];
|
|
1104
|
-
if (option.imageslim) segs.push("imageslim");
|
|
1105
|
-
if (option.imageView2) segs.push(getImageView2(option.imageView2));
|
|
1106
|
-
const mogr = getImageMogr2(option.imageMogr2 ?? option);
|
|
1107
|
-
if (mogr) segs.push(mogr);
|
|
1108
|
-
if (option.watermark) segs.push(getWatermark2(option.watermark));
|
|
1109
|
-
if (option.imageInfo) segs.push("imageInfo");
|
|
1110
|
-
if (!segs.length) return src;
|
|
1111
|
-
const base = src.split("?")[0];
|
|
1112
|
-
return `${base}?${segs.join("|")}`;
|
|
1113
|
-
}
|
|
1114
|
-
function getQnVideo(src, option) {
|
|
1115
|
-
if (!src || !option) return src;
|
|
1116
|
-
if (src.startsWith("blob:")) return src;
|
|
1117
|
-
if (src.includes(".svg")) return src;
|
|
1118
|
-
const segs = [];
|
|
1119
|
-
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1120
|
-
if (option.vframe) segs.push(getVframe(option.vframe));
|
|
1121
|
-
if (!segs.length) return src;
|
|
1122
|
-
const base = src.split("?")[0];
|
|
1123
|
-
return `${base}?${segs.join("|")}`;
|
|
1124
|
-
}
|
|
1125
|
-
function getQnAudio(src, option) {
|
|
1126
|
-
if (!src || !option) return src;
|
|
1127
|
-
if (src.startsWith("blob:")) return src;
|
|
1128
|
-
const segs = [];
|
|
1129
|
-
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1130
|
-
if (!segs.length) return src;
|
|
1131
|
-
const base = src.split("?")[0];
|
|
1132
|
-
return `${base}?${segs.join("|")}`;
|
|
1133
|
-
}
|
|
1134
|
-
function getQnHls(src, option) {
|
|
1135
|
-
if (!src || !option) return src;
|
|
1136
|
-
if (src.startsWith("blob:")) return src;
|
|
1137
|
-
const seg = getAvcvt(option);
|
|
1138
|
-
if (!seg) return src;
|
|
1139
|
-
const base = src.split("?")[0];
|
|
1140
|
-
return `${base}?${seg}`;
|
|
1141
|
-
}
|
|
1142
|
-
function getImageView2(opt) {
|
|
1143
|
-
if (!opt) return "";
|
|
1144
|
-
const mode = typeof opt.mode === "number" ? opt.mode : 0;
|
|
1145
|
-
const kv = [];
|
|
1146
|
-
for (const [k, v] of Object.entries(opt)) {
|
|
1147
|
-
if (k === "mode") continue;
|
|
1148
|
-
if (typeof v === "boolean") {
|
|
1149
|
-
if (v) kv.push(`${k}/1`);
|
|
1150
|
-
} else if (typeof v === "number" || typeof v === "string") {
|
|
1151
|
-
kv.push(`${k}/${v}`);
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
return kv.length ? `imageView2/${mode}/${kv.join("/")}` : `imageView2/${mode}`;
|
|
1155
|
-
}
|
|
1156
|
-
function getImageMogr2(opt) {
|
|
1157
|
-
if (!opt) return "";
|
|
1158
|
-
const parts = [];
|
|
1159
|
-
const tn = opt.thumbnail;
|
|
1160
|
-
if (typeof tn !== "undefined") parts.push(`thumbnail/${tn}`);
|
|
1161
|
-
const cp = opt.crop;
|
|
1162
|
-
if (typeof cp !== "undefined") parts.push(`crop/${cp}`);
|
|
1163
|
-
const rot = opt.rotate;
|
|
1164
|
-
if (typeof rot === "number") parts.push(`rotate/${rot}`);
|
|
1165
|
-
const ao = opt["auto-orient"];
|
|
1166
|
-
if (ao) parts.push("auto-orient");
|
|
1167
|
-
const fmt = opt.format;
|
|
1168
|
-
if (typeof fmt === "string") parts.push(`format/${fmt}`);
|
|
1169
|
-
const il = opt.interlace;
|
|
1170
|
-
if (il === 0 || il === 1) parts.push(`interlace/${il}`);
|
|
1171
|
-
const bg = opt.background;
|
|
1172
|
-
if (typeof bg === "string") parts.push(`background/${bg}`);
|
|
1173
|
-
const q = opt.q;
|
|
1174
|
-
if (typeof q === "number") parts.push(`q/${q}`);
|
|
1175
|
-
const blur = opt.blur;
|
|
1176
|
-
if (typeof blur !== "undefined") {
|
|
1177
|
-
if (typeof blur === "string") parts.push(`blur/${blur}`);
|
|
1178
|
-
else parts.push(`blur/${blur.r}x${blur.s}`);
|
|
1179
|
-
}
|
|
1180
|
-
const colors = opt.colors;
|
|
1181
|
-
if (typeof colors === "number") parts.push(`colors/${colors}`);
|
|
1182
|
-
return parts.length ? `imageMogr2/${parts.join("/")}` : "";
|
|
1183
|
-
}
|
|
1184
|
-
function getWatermark2(w) {
|
|
1185
|
-
if (!w) return "";
|
|
1186
|
-
const mode = w.type === "image" ? 1 : w.type === "text" ? 2 : typeof w.type === "number" ? w.type : 2;
|
|
1187
|
-
const segs = [`watermark/${mode}`];
|
|
1188
|
-
if (mode === 1 && w.image) segs.push(`image/${toBase64Url2(w.image)}`);
|
|
1189
|
-
if (mode === 2 && w.text) segs.push(`text/${toBase64Url2(w.text)}`);
|
|
1190
|
-
if (w.font) segs.push(`font/${toBase64Url2(w.font)}`);
|
|
1191
|
-
if (typeof w.fontsize === "number") segs.push(`fontsize/${w.fontsize}`);
|
|
1192
|
-
if (w.fill) segs.push(`fill/${toBase64Url2(w.fill)}`);
|
|
1193
|
-
if (w.gravity) segs.push(`gravity/${w.gravity}`);
|
|
1194
|
-
if (typeof w.dx === "number") segs.push(`dx/${w.dx}`);
|
|
1195
|
-
if (typeof w.dy === "number") segs.push(`dy/${w.dy}`);
|
|
1196
|
-
if (typeof w.dissolve === "number") segs.push(`dissolve/${w.dissolve}`);
|
|
1197
|
-
return segs.join("/");
|
|
1198
|
-
}
|
|
1199
|
-
function toBase64Url2(s) {
|
|
1200
|
-
let b64 = "";
|
|
1201
|
-
if (typeof Buffer !== "undefined") {
|
|
1202
|
-
const buf = Buffer.from(s, "utf-8");
|
|
1203
|
-
b64 = buf.toString("base64");
|
|
1204
|
-
} else {
|
|
1205
|
-
try {
|
|
1206
|
-
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1207
|
-
} catch {
|
|
1208
|
-
b64 = "";
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1212
|
-
}
|
|
1213
|
-
function getAvthumb(opt) {
|
|
1214
|
-
const parts = [];
|
|
1215
|
-
if (opt.format) parts.push(`avthumb/${opt.format}`);
|
|
1216
|
-
else parts.push("avthumb");
|
|
1217
|
-
if (opt.s) parts.push(`s/${opt.s}`);
|
|
1218
|
-
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1219
|
-
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1220
|
-
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1221
|
-
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1222
|
-
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1223
|
-
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1224
|
-
return parts.join("/");
|
|
1225
|
-
}
|
|
1226
|
-
function getVframe(opt) {
|
|
1227
|
-
const parts = [];
|
|
1228
|
-
parts.push(`vframe/${opt.format || "jpg"}`);
|
|
1229
|
-
if (typeof opt.offset === "number") parts.push(`offset/${opt.offset}`);
|
|
1230
|
-
if (typeof opt.w === "number") parts.push(`w/${opt.w}`);
|
|
1231
|
-
if (typeof opt.h === "number") parts.push(`h/${opt.h}`);
|
|
1232
|
-
return parts.join("/");
|
|
1233
|
-
}
|
|
1234
|
-
function getAvcvt(opt) {
|
|
1235
|
-
const parts = [];
|
|
1236
|
-
const level = typeof opt.level === "number" ? `/${opt.level}` : "/3";
|
|
1237
|
-
parts.push(`avcvt${level}`);
|
|
1238
|
-
parts.push(`format/${opt.format || "m3u8"}`);
|
|
1239
|
-
if (typeof opt.segtime === "number") parts.push(`segtime/${opt.segtime}`);
|
|
1240
|
-
if (typeof opt.t === "string") parts.push(`t/${opt.t}`);
|
|
1241
|
-
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1242
|
-
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1243
|
-
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1244
|
-
if (typeof opt.s === "string") parts.push(`s/${opt.s}`);
|
|
1245
|
-
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1246
|
-
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1247
|
-
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1248
|
-
if (typeof opt.output === "string") parts.push(`output/${toBase64Url2(opt.output)}`);
|
|
1249
|
-
return parts.join("/");
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
// src/ts/validator/index.ts
|
|
1253
|
-
function isLetter(s) {
|
|
1254
|
-
return /^[a-zA-Z]*$/.test(s);
|
|
1255
|
-
}
|
|
1256
|
-
function isChinese(s) {
|
|
1257
|
-
const v = String(s ?? "").trim();
|
|
1258
|
-
return /^[\u4E00-\u9FA5]+$/.test(v);
|
|
1259
|
-
}
|
|
1260
|
-
function isDigits(s) {
|
|
1261
|
-
return /^[0-9]+$/.test(s);
|
|
1262
|
-
}
|
|
1263
|
-
function isNumeric(value, options) {
|
|
1264
|
-
const { negative = false, decimal = 2, thousands = false, leadZero = false } = options || {};
|
|
1265
|
-
if (value === null || value === void 0 || value === "") return false;
|
|
1266
|
-
const str = String(value).trim();
|
|
1267
|
-
const sign = negative && str.startsWith("-") ? "-" : "";
|
|
1268
|
-
const body = sign ? str.slice(1) : str;
|
|
1269
|
-
const thousandsPart = thousands ? "(?:[1-9]\\d{0,2}(,\\d{3})*|0)" : "(?:\\d+)";
|
|
1270
|
-
const intPart = thousands ? thousandsPart : leadZero ? "(?:\\d+)" : "(?:0|[1-9]\\d*)";
|
|
1271
|
-
const fracPart = decimal === 0 ? "" : `(\\.\\d{1,${decimal}})`;
|
|
1272
|
-
const pattern = `^${intPart}${fracPart}$`;
|
|
1273
|
-
const reg = new RegExp(pattern);
|
|
1274
|
-
return reg.test(body);
|
|
1275
|
-
}
|
|
1276
|
-
function isMobilePhone(s) {
|
|
1277
|
-
const v = String(s ?? "").trim();
|
|
1278
|
-
return /^1[3-9]\d{9}$/.test(v);
|
|
1279
|
-
}
|
|
1280
|
-
function isLandline(s) {
|
|
1281
|
-
const v = String(s ?? "").trim();
|
|
1282
|
-
return /^0\d{2,3}-?\d{7,8}(?:-\d{1,6})?$/.test(v);
|
|
1283
|
-
}
|
|
1284
|
-
function isPhone(s) {
|
|
1285
|
-
return isMobilePhone(s) || isLandline(s);
|
|
1286
|
-
}
|
|
1287
|
-
function isEmail(s) {
|
|
1288
|
-
const v = String(s ?? "").trim();
|
|
1289
|
-
if (v === "") return false;
|
|
1290
|
-
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/;
|
|
1291
|
-
return emailRegex.test(v);
|
|
1292
|
-
}
|
|
1293
|
-
function isChineseName(s) {
|
|
1294
|
-
const v = String(s ?? "").trim();
|
|
1295
|
-
return /^[\u4E00-\u9FA5·]{2,20}$/.test(v);
|
|
1296
|
-
}
|
|
1297
|
-
function isIdentityCard(code) {
|
|
1298
|
-
const v = String(code ?? "").trim();
|
|
1299
|
-
if (v === "") return false;
|
|
1300
|
-
const isValidDate = (yyyymmdd) => {
|
|
1301
|
-
const y = Number(yyyymmdd.slice(0, 4));
|
|
1302
|
-
const m = Number(yyyymmdd.slice(4, 6));
|
|
1303
|
-
const d = Number(yyyymmdd.slice(6, 8));
|
|
1304
|
-
if (y < 1900 || y > 2100) return false;
|
|
1305
|
-
const date = new Date(y, m - 1, d);
|
|
1306
|
-
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1307
|
-
};
|
|
1308
|
-
if (/^\d{17}[\dXx]$/.test(v)) {
|
|
1309
|
-
const birth = v.slice(6, 14);
|
|
1310
|
-
if (!isValidDate(birth)) return false;
|
|
1311
|
-
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
1312
|
-
const checkMap = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
|
|
1313
|
-
let sum = 0;
|
|
1314
|
-
for (let i = 0; i < 17; i++) sum += Number(v[i]) * weights[i];
|
|
1315
|
-
const mod = sum % 11;
|
|
1316
|
-
const code18 = v[17].toUpperCase();
|
|
1317
|
-
return checkMap[mod] === code18;
|
|
1318
|
-
}
|
|
1319
|
-
if (/^\d{15}$/.test(v)) {
|
|
1320
|
-
const birth = v.slice(6, 12);
|
|
1321
|
-
const y = Number(`19${birth.slice(0, 2)}`);
|
|
1322
|
-
const m = Number(birth.slice(2, 4));
|
|
1323
|
-
const d = Number(birth.slice(4, 6));
|
|
1324
|
-
const date = new Date(y, m - 1, d);
|
|
1325
|
-
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1326
|
-
}
|
|
1327
|
-
if (/^[A-Za-z][12]\d{8}$/.test(v)) return true;
|
|
1328
|
-
if (/^[A-Za-z]{1,2}\d{6}\(?[0-9A]\)?$/.test(v)) return true;
|
|
1329
|
-
if (/^[157]\d{6}\(?\d\)?$/.test(v)) return true;
|
|
1330
|
-
return false;
|
|
1331
|
-
}
|
|
1332
|
-
function isPassport(s) {
|
|
1333
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim();
|
|
1334
|
-
if (t === "") return false;
|
|
1335
|
-
if (/^[EG]\d{8}$/.test(t)) return true;
|
|
1336
|
-
if (/^[DPS]\d{7}$/.test(t)) return true;
|
|
1337
|
-
if (/^[A-Za-z]\d{8}$/.test(t)) return true;
|
|
1338
|
-
if (/^[A-Za-z0-9]{6,9}$/.test(t)) return true;
|
|
1339
|
-
return false;
|
|
1340
|
-
}
|
|
1341
|
-
function isHKMOPermit(s) {
|
|
1342
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1343
|
-
return /^[HM]\d{8,10}$/.test(t);
|
|
1344
|
-
}
|
|
1345
|
-
function isTaiwanPermit(s) {
|
|
1346
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1347
|
-
if (/^\d{8}$/.test(t)) return true;
|
|
1348
|
-
if (/^[A-Z]\d{8}$/.test(t)) return true;
|
|
1349
|
-
if (/^\d{10}$/.test(t)) return true;
|
|
1350
|
-
return false;
|
|
1351
|
-
}
|
|
1352
|
-
function isOfficerId(s) {
|
|
1353
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1354
|
-
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1355
|
-
}
|
|
1356
|
-
function isSoldierId(s) {
|
|
1357
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1358
|
-
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1359
|
-
}
|
|
1360
|
-
function isMilitaryId(s) {
|
|
1361
|
-
return isOfficerId(s) || isSoldierId(s);
|
|
1362
|
-
}
|
|
1363
|
-
function isBankCard(s) {
|
|
1364
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim();
|
|
1365
|
-
if (!/^\d{12,19}$/.test(t)) return false;
|
|
1366
|
-
let sum = 0;
|
|
1367
|
-
let shouldDouble = false;
|
|
1368
|
-
for (let i = t.length - 1; i >= 0; i--) {
|
|
1369
|
-
let digit = Number(t[i]);
|
|
1370
|
-
if (shouldDouble) {
|
|
1371
|
-
digit *= 2;
|
|
1372
|
-
if (digit > 9) digit -= 9;
|
|
1373
|
-
}
|
|
1374
|
-
sum += digit;
|
|
1375
|
-
shouldDouble = !shouldDouble;
|
|
1376
|
-
}
|
|
1377
|
-
return sum % 10 === 0;
|
|
1378
|
-
}
|
|
1379
|
-
function isLicensePlate(s) {
|
|
1380
|
-
const v = String(s ?? "").trim().toUpperCase();
|
|
1381
|
-
const prov = "\u4EAC\u6CAA\u6D25\u6E1D\u5180\u8C6B\u4E91\u8FBD\u9ED1\u6E58\u7696\u9C81\u65B0\u82CF\u6D59\u8D63\u9102\u6842\u7518\u664B\u8499\u9655\u5409\u95FD\u8D35\u9752\u85CF\u5DDD\u5B81\u743C\u7CA4";
|
|
1382
|
-
const std = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9\u6302\u5B66\u8B66\u6E2F\u6FB3]$`);
|
|
1383
|
-
const ne1 = new RegExp(`^[${prov}][A-HJ-NP-Z][DF][A-HJ-NP-Z0-9]{5}$`);
|
|
1384
|
-
const ne2 = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{5}[DF]$`);
|
|
1385
|
-
return std.test(v) || ne1.test(v) || ne2.test(v);
|
|
1386
|
-
}
|
|
1387
|
-
function isTaxID(code) {
|
|
1388
|
-
const v = String(code ?? "").trim();
|
|
1389
|
-
if (!/^[0-9A-HJ-NPQRTUWXY]{18}$/.test(v)) return false;
|
|
1390
|
-
const charset = "0123456789ABCDEFGHJKLMNPQRTUWXY";
|
|
1391
|
-
const weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
|
|
1392
|
-
const map = {};
|
|
1393
|
-
for (let i = 0; i < charset.length; i++) map[charset[i]] = i;
|
|
1394
|
-
let sum = 0;
|
|
1395
|
-
for (let i = 0; i < 17; i++) {
|
|
1396
|
-
sum += map[v[i]] * weights[i];
|
|
1397
|
-
}
|
|
1398
|
-
const logicCheck = (31 - sum % 31) % 31;
|
|
1399
|
-
const expected = charset[logicCheck];
|
|
1400
|
-
return v[17] === expected;
|
|
1401
|
-
}
|
|
1402
|
-
function isHexColor(s) {
|
|
1403
|
-
const v = String(s ?? "").trim();
|
|
1404
|
-
return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(v);
|
|
1405
|
-
}
|
|
1406
|
-
function isURL(s) {
|
|
1407
|
-
const v = String(s ?? "").trim();
|
|
1408
|
-
if (v === "") return false;
|
|
1409
|
-
try {
|
|
1410
|
-
const u = new URL(v);
|
|
1411
|
-
return ["http:", "https:", "ftp:"].includes(u.protocol) && !!u.hostname;
|
|
1412
|
-
} catch {
|
|
1413
|
-
return false;
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
function isIPv4(s) {
|
|
1417
|
-
const v = String(s ?? "").trim();
|
|
1418
|
-
if (v === "") return false;
|
|
1419
|
-
const parts = v.split(".");
|
|
1420
|
-
if (parts.length !== 4) return false;
|
|
1421
|
-
for (const p of parts) {
|
|
1422
|
-
if (!/^\d+$/.test(p)) return false;
|
|
1423
|
-
if (p.length > 1 && p.startsWith("0")) return false;
|
|
1424
|
-
const n = Number(p);
|
|
1425
|
-
if (n < 0 || n > 255) return false;
|
|
1426
|
-
}
|
|
1427
|
-
return true;
|
|
1428
|
-
}
|
|
1429
|
-
function isIPv6(s) {
|
|
1430
|
-
const v = String(s ?? "").trim();
|
|
1431
|
-
if (v === "") return false;
|
|
1432
|
-
const lastColon = v.lastIndexOf(":");
|
|
1433
|
-
if (lastColon !== -1 && v.includes(".")) {
|
|
1434
|
-
const ipv6Part = v.slice(0, lastColon);
|
|
1435
|
-
const ipv4Part = v.slice(lastColon + 1);
|
|
1436
|
-
return isIPv6(ipv6Part) && isIPv4(ipv4Part);
|
|
1437
|
-
}
|
|
1438
|
-
const dblColonCount = (v.match(/::/g) || []).length;
|
|
1439
|
-
if (dblColonCount > 1) return false;
|
|
1440
|
-
const segments = v.split(":");
|
|
1441
|
-
if (v.startsWith("::")) segments.shift();
|
|
1442
|
-
if (v.endsWith("::")) segments.pop();
|
|
1443
|
-
const segmentsFiltered = segments.filter((seg) => seg !== "");
|
|
1444
|
-
if (dblColonCount === 0 && segmentsFiltered.length !== 8) return false;
|
|
1445
|
-
if (dblColonCount === 1 && segmentsFiltered.length >= 1 && segmentsFiltered.length <= 7) {
|
|
1446
|
-
} else if (dblColonCount === 1 && segments.length === 0) {
|
|
1447
|
-
return true;
|
|
1448
|
-
} else if (dblColonCount === 0 && segmentsFiltered.length === 8) {
|
|
1449
|
-
} else {
|
|
1450
|
-
return false;
|
|
1451
|
-
}
|
|
1452
|
-
return segmentsFiltered.every(
|
|
1453
|
-
(seg) => seg.length >= 1 && seg.length <= 4 && /^[0-9a-fA-F]{1,4}$/.test(seg)
|
|
1454
|
-
);
|
|
1455
|
-
}
|
|
1456
|
-
function isIP(s, version) {
|
|
1457
|
-
if (version === 4 || version === "4") return isIPv4(s);
|
|
1458
|
-
if (version === 6 || version === "6") return isIPv6(s);
|
|
1459
|
-
return isIPv4(s) || isIPv6(s);
|
|
1460
|
-
}
|
|
1461
|
-
function isIPRange(s) {
|
|
1462
|
-
const v = String(s ?? "").trim();
|
|
1463
|
-
if (v === "") return false;
|
|
1464
|
-
const parts = v.split("/");
|
|
1465
|
-
if (parts.length !== 2) return false;
|
|
1466
|
-
const [ip, prefixStr] = parts;
|
|
1467
|
-
if (!/^\d+$/.test(prefixStr)) return false;
|
|
1468
|
-
const prefix = Number(prefixStr);
|
|
1469
|
-
if (ip.includes(":")) {
|
|
1470
|
-
if (!isIPv6(ip)) return false;
|
|
1471
|
-
return prefix >= 0 && prefix <= 128;
|
|
1472
|
-
}
|
|
1473
|
-
if (!isIPv4(ip)) return false;
|
|
1474
|
-
return prefix >= 0 && prefix <= 32;
|
|
1475
|
-
}
|
|
1476
|
-
function isPortNumber(s) {
|
|
1477
|
-
const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
|
|
1478
|
-
return Number.isInteger(v) && v >= 0 && v <= 65535;
|
|
1479
|
-
}
|
|
1480
|
-
function isLatitude(s) {
|
|
1481
|
-
const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
|
|
1482
|
-
return Number.isFinite(v) && v >= -90 && v <= 90;
|
|
1483
|
-
}
|
|
1484
|
-
function isLongitude(s) {
|
|
1485
|
-
const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
|
|
1486
|
-
return Number.isFinite(v) && v >= -180 && v <= 180;
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
555
|
// src/web/network/request.ts
|
|
556
|
+
import {
|
|
557
|
+
appendUrlParam,
|
|
558
|
+
cloneDeep,
|
|
559
|
+
getObjectValue,
|
|
560
|
+
isPlainObject,
|
|
561
|
+
pickBy,
|
|
562
|
+
toDayjs
|
|
563
|
+
} from "@base-web-kits/base-tools-ts";
|
|
1490
564
|
var requestCache = /* @__PURE__ */ new Map();
|
|
1491
565
|
function request(config) {
|
|
1492
566
|
const controller = new AbortController();
|
|
@@ -1502,7 +576,8 @@ function request(config) {
|
|
|
1502
576
|
}
|
|
1503
577
|
};
|
|
1504
578
|
const promise = new Promise((resolve, reject) => {
|
|
1505
|
-
const execute =
|
|
579
|
+
const execute = () => __async(null, null, function* () {
|
|
580
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1506
581
|
const {
|
|
1507
582
|
url,
|
|
1508
583
|
data,
|
|
@@ -1523,10 +598,10 @@ function request(config) {
|
|
|
1523
598
|
timeout = 6e4
|
|
1524
599
|
} = config;
|
|
1525
600
|
const isGet = method === "GET";
|
|
1526
|
-
const isObjectData =
|
|
601
|
+
const isObjectData = isPlainObject(data);
|
|
1527
602
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1528
|
-
const fillData = isObjectData ?
|
|
1529
|
-
const fillHeader = header ?
|
|
603
|
+
const fillData = isObjectData ? pickBy(data, (val) => val !== void 0) : data;
|
|
604
|
+
const fillHeader = header ? pickBy(header, (val) => !!val) : {};
|
|
1530
605
|
const contentTypeKey = Object.keys(fillHeader).find(
|
|
1531
606
|
(k) => k.toLowerCase() === "content-type"
|
|
1532
607
|
);
|
|
@@ -1548,7 +623,7 @@ function request(config) {
|
|
|
1548
623
|
fillBody = fillData;
|
|
1549
624
|
}
|
|
1550
625
|
}
|
|
1551
|
-
const logConfig = {
|
|
626
|
+
const logConfig = __spreadProps(__spreadValues({}, config), { data: fillData, header: fillHeader, url: fillUrl });
|
|
1552
627
|
const startTime = Date.now();
|
|
1553
628
|
const isCache = cacheTime && cacheTime > 0;
|
|
1554
629
|
const cacheKey = isCache ? JSON.stringify({ url: fillUrl, data: fillData }) : "";
|
|
@@ -1567,32 +642,32 @@ function request(config) {
|
|
|
1567
642
|
}
|
|
1568
643
|
}
|
|
1569
644
|
const appConfig2 = getBaseToolsConfig();
|
|
1570
|
-
if (showLoading) appConfig2.showLoading
|
|
645
|
+
if (showLoading) (_a = appConfig2.showLoading) == null ? void 0 : _a.call(appConfig2);
|
|
1571
646
|
let isTimeout = false;
|
|
1572
647
|
const timeoutId = setTimeout(() => {
|
|
1573
648
|
isTimeout = true;
|
|
1574
649
|
controller.abort();
|
|
1575
650
|
}, timeout);
|
|
1576
651
|
try {
|
|
1577
|
-
const response =
|
|
652
|
+
const response = yield fetch(fillUrl, {
|
|
1578
653
|
method,
|
|
1579
654
|
headers: fillHeader,
|
|
1580
655
|
body: fillBody,
|
|
1581
656
|
signal
|
|
1582
657
|
});
|
|
1583
658
|
if (!response.ok) {
|
|
1584
|
-
if (showLoading) appConfig2.hideLoading
|
|
659
|
+
if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
|
|
1585
660
|
throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
|
|
1586
661
|
}
|
|
1587
662
|
if (enableChunked) {
|
|
1588
|
-
if (showLoading) appConfig2.hideLoading
|
|
1589
|
-
const res2 =
|
|
663
|
+
if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
|
|
664
|
+
const res2 = yield handleStreamResponse(response, chunkCallback);
|
|
1590
665
|
logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
|
|
1591
666
|
resolve(res2);
|
|
1592
667
|
return;
|
|
1593
668
|
}
|
|
1594
|
-
const resData =
|
|
1595
|
-
if (showLoading) appConfig2.hideLoading
|
|
669
|
+
const resData = yield parseResponse(response, responseType);
|
|
670
|
+
if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
|
|
1596
671
|
const res = responseInterceptor ? responseInterceptor(resData) : resData;
|
|
1597
672
|
const code = getObjectValue(res, codeKey);
|
|
1598
673
|
const scode = successKey ? getObjectValue(res, successKey) : code;
|
|
@@ -1605,28 +680,28 @@ function request(config) {
|
|
|
1605
680
|
resolve(getResult(res, resKey));
|
|
1606
681
|
} else if (isRelogin) {
|
|
1607
682
|
reject(res);
|
|
1608
|
-
appConfig2.toLogin
|
|
683
|
+
(_e = appConfig2.toLogin) == null ? void 0 : _e.call(appConfig2);
|
|
1609
684
|
} else {
|
|
1610
|
-
if (toastError && msg) appConfig2.toast
|
|
685
|
+
if (toastError && msg) (_f = appConfig2.toast) == null ? void 0 : _f.call(appConfig2, { status: "fail", msg });
|
|
1611
686
|
reject(res);
|
|
1612
687
|
}
|
|
1613
688
|
} catch (e) {
|
|
1614
689
|
const status = "fail";
|
|
1615
690
|
const isAbortError = e instanceof DOMException && e.name === "AbortError";
|
|
1616
691
|
if (isAbortError && isTimeout) {
|
|
1617
|
-
if (toastError) appConfig2.toast
|
|
692
|
+
if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
|
|
1618
693
|
const timeoutError = new Error("Request Timeout");
|
|
1619
694
|
logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
|
|
1620
695
|
reject(timeoutError);
|
|
1621
696
|
return;
|
|
1622
697
|
}
|
|
1623
|
-
if (!isAbortError && toastError) appConfig2.toast
|
|
698
|
+
if (!isAbortError && toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
|
|
1624
699
|
logRequestInfo({ status, config: logConfig, startTime, e });
|
|
1625
700
|
reject(e);
|
|
1626
701
|
} finally {
|
|
1627
702
|
if (timeoutId) clearTimeout(timeoutId);
|
|
1628
703
|
}
|
|
1629
|
-
};
|
|
704
|
+
});
|
|
1630
705
|
execute();
|
|
1631
706
|
});
|
|
1632
707
|
promise.task = task;
|
|
@@ -1640,7 +715,7 @@ function logRequestInfo(options) {
|
|
|
1640
715
|
const { url, data, header, method, extraLog } = config;
|
|
1641
716
|
const endTime = Date.now();
|
|
1642
717
|
const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
|
|
1643
|
-
const info = {
|
|
718
|
+
const info = __spreadValues({
|
|
1644
719
|
name: "request",
|
|
1645
720
|
status,
|
|
1646
721
|
url,
|
|
@@ -1650,11 +725,10 @@ function logRequestInfo(options) {
|
|
|
1650
725
|
fromCache,
|
|
1651
726
|
startTime: toDayjs(startTime).format(fmt),
|
|
1652
727
|
endTime: toDayjs(endTime).format(fmt),
|
|
1653
|
-
duration: endTime - startTime
|
|
1654
|
-
|
|
1655
|
-
};
|
|
728
|
+
duration: endTime - startTime
|
|
729
|
+
}, extraLog);
|
|
1656
730
|
if (status === "success") {
|
|
1657
|
-
info.res =
|
|
731
|
+
info.res = cloneDeep(res);
|
|
1658
732
|
log("info", info);
|
|
1659
733
|
} else {
|
|
1660
734
|
info.e = e;
|
|
@@ -1674,33 +748,37 @@ function checkCache(cacheKey) {
|
|
|
1674
748
|
}
|
|
1675
749
|
return cached.res;
|
|
1676
750
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
chunkCallback
|
|
751
|
+
function handleStreamResponse(response, chunkCallback) {
|
|
752
|
+
return __async(this, null, function* () {
|
|
753
|
+
if (!response.body) throw new Error("Response body is null");
|
|
754
|
+
const reader = response.body.getReader();
|
|
755
|
+
while (true) {
|
|
756
|
+
const { done, value } = yield reader.read();
|
|
757
|
+
if (done) break;
|
|
758
|
+
if (chunkCallback && value) {
|
|
759
|
+
chunkCallback({ data: value.buffer });
|
|
760
|
+
}
|
|
1685
761
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
762
|
+
return "Stream Finished";
|
|
763
|
+
});
|
|
1688
764
|
}
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
765
|
+
function parseResponse(response, responseType) {
|
|
766
|
+
return __async(this, null, function* () {
|
|
767
|
+
let resData;
|
|
768
|
+
if (responseType === "arraybuffer") {
|
|
769
|
+
resData = yield response.arrayBuffer();
|
|
770
|
+
} else if (responseType === "text") {
|
|
771
|
+
resData = yield response.text();
|
|
772
|
+
} else {
|
|
773
|
+
const text = yield response.text();
|
|
774
|
+
try {
|
|
775
|
+
resData = JSON.parse(text);
|
|
776
|
+
} catch (e) {
|
|
777
|
+
resData = text;
|
|
778
|
+
}
|
|
1701
779
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
780
|
+
return resData;
|
|
781
|
+
});
|
|
1704
782
|
}
|
|
1705
783
|
function toSearchParams(data) {
|
|
1706
784
|
const params = new URLSearchParams();
|
|
@@ -1772,7 +850,7 @@ function getLocalStorage(key) {
|
|
|
1772
850
|
return parsed[WK.val];
|
|
1773
851
|
}
|
|
1774
852
|
return parsed;
|
|
1775
|
-
} catch {
|
|
853
|
+
} catch (e) {
|
|
1776
854
|
return raw;
|
|
1777
855
|
}
|
|
1778
856
|
}
|