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