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