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