@base-web-kits/base-tools-web 1.0.2-alpha.6 → 1.0.2
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 +1 -1385
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +1 -1214
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1219
- package/dist/index.js.map +1 -1
- package/dist/{network/load.d.ts → load/index.d.ts} +1 -1
- package/dist/load/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/web/index.ts +1 -2
- package/dist/config/index.d.ts +0 -55
- package/dist/config/index.d.ts.map +0 -1
- package/dist/network/index.d.ts +0 -3
- package/dist/network/index.d.ts.map +0 -1
- package/dist/network/load.d.ts.map +0 -1
- package/dist/network/request.d.ts +0 -151
- package/dist/network/request.d.ts.map +0 -1
- package/src/web/config/index.ts +0 -67
- package/src/web/network/index.ts +0 -2
- package/src/web/network/request.ts +0 -491
- /package/src/web/{network/load.ts → load/index.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
|
|
19
1
|
// src/web/clipboard/index.ts
|
|
20
2
|
async function copyText(text) {
|
|
21
3
|
if (typeof text !== "string") text = String(text ?? "");
|
|
@@ -215,15 +197,6 @@ function execCopyFromHtml(html) {
|
|
|
215
197
|
});
|
|
216
198
|
}
|
|
217
199
|
|
|
218
|
-
// src/web/config/index.ts
|
|
219
|
-
var appConfig = {};
|
|
220
|
-
function getAppConfig() {
|
|
221
|
-
return appConfig;
|
|
222
|
-
}
|
|
223
|
-
function setBaseToolsConfig(newConfig) {
|
|
224
|
-
Object.assign(appConfig, newConfig);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
200
|
// src/web/cookie/index.ts
|
|
228
201
|
function setCookie(name, value, days) {
|
|
229
202
|
const date = /* @__PURE__ */ new Date();
|
|
@@ -378,7 +351,7 @@ function unlockBodyScroll() {
|
|
|
378
351
|
window.scrollTo(0, y);
|
|
379
352
|
}
|
|
380
353
|
|
|
381
|
-
// src/web/
|
|
354
|
+
// src/web/load/index.ts
|
|
382
355
|
async function download(url, fileName = "") {
|
|
383
356
|
if (!url) return;
|
|
384
357
|
let blobUrl = "";
|
|
@@ -499,1194 +472,6 @@ function preloadImage(src) {
|
|
|
499
472
|
});
|
|
500
473
|
}
|
|
501
474
|
|
|
502
|
-
// src/ts/index.ts
|
|
503
|
-
var ts_exports = {};
|
|
504
|
-
__export(ts_exports, {
|
|
505
|
-
BigNumber: () => BigNumber,
|
|
506
|
-
EventBus: () => EventBus,
|
|
507
|
-
appendUrlParam: () => appendUrlParam,
|
|
508
|
-
arrayMove: () => arrayMove,
|
|
509
|
-
buildOSSUrl: () => buildOSSUrl,
|
|
510
|
-
createRandId: () => createRandId,
|
|
511
|
-
createTimeRandId: () => createTimeRandId,
|
|
512
|
-
createUUID: () => createUUID,
|
|
513
|
-
dayjs: () => dayjs,
|
|
514
|
-
getAgeByBirthdate: () => getAgeByBirthdate,
|
|
515
|
-
getByteLength: () => getByteLength,
|
|
516
|
-
getCountdownParts: () => getCountdownParts,
|
|
517
|
-
getDateRangeAfter: () => getDateRangeAfter,
|
|
518
|
-
getDateRangeBefore: () => getDateRangeBefore,
|
|
519
|
-
getFileSuffix: () => getFileSuffix,
|
|
520
|
-
getFileType: () => getFileType,
|
|
521
|
-
getOSSAudio: () => getOSSAudio,
|
|
522
|
-
getOSSHls: () => getOSSHls,
|
|
523
|
-
getOSSImg: () => getOSSImg,
|
|
524
|
-
getOSSVideo: () => getOSSVideo,
|
|
525
|
-
getObjectKeys: () => getObjectKeys,
|
|
526
|
-
getObjectValue: () => getObjectValue,
|
|
527
|
-
getQnAudio: () => getQnAudio,
|
|
528
|
-
getQnHls: () => getQnHls,
|
|
529
|
-
getQnImg: () => getQnImg,
|
|
530
|
-
getQnVideo: () => getQnVideo,
|
|
531
|
-
isBankCard: () => isBankCard,
|
|
532
|
-
isChinese: () => isChinese,
|
|
533
|
-
isChineseName: () => isChineseName,
|
|
534
|
-
isDigits: () => isDigits,
|
|
535
|
-
isEmail: () => isEmail,
|
|
536
|
-
isHKMOPermit: () => isHKMOPermit,
|
|
537
|
-
isHexColor: () => isHexColor,
|
|
538
|
-
isIP: () => isIP,
|
|
539
|
-
isIPRange: () => isIPRange,
|
|
540
|
-
isIPv6: () => isIPv6,
|
|
541
|
-
isIdentityCard: () => isIdentityCard,
|
|
542
|
-
isLandline: () => isLandline,
|
|
543
|
-
isLatitude: () => isLatitude,
|
|
544
|
-
isLetter: () => isLetter,
|
|
545
|
-
isLicensePlate: () => isLicensePlate,
|
|
546
|
-
isLongitude: () => isLongitude,
|
|
547
|
-
isMilitaryId: () => isMilitaryId,
|
|
548
|
-
isMobilePhone: () => isMobilePhone,
|
|
549
|
-
isNumeric: () => isNumeric,
|
|
550
|
-
isOfficerId: () => isOfficerId,
|
|
551
|
-
isPassport: () => isPassport,
|
|
552
|
-
isPhone: () => isPhone,
|
|
553
|
-
isPortNumber: () => isPortNumber,
|
|
554
|
-
isSoldierId: () => isSoldierId,
|
|
555
|
-
isTaiwanPermit: () => isTaiwanPermit,
|
|
556
|
-
isTaxID: () => isTaxID,
|
|
557
|
-
isURL: () => isURL,
|
|
558
|
-
mathCompare: () => mathCompare,
|
|
559
|
-
mathDiv: () => mathDiv,
|
|
560
|
-
mathEqual: () => mathEqual,
|
|
561
|
-
mathFixed: () => mathFixed,
|
|
562
|
-
mathGreaterThan: () => mathGreaterThan,
|
|
563
|
-
mathGreaterThanOrEqual: () => mathGreaterThanOrEqual,
|
|
564
|
-
mathLessThan: () => mathLessThan,
|
|
565
|
-
mathLessThanOrEqual: () => mathLessThanOrEqual,
|
|
566
|
-
mathMinus: () => mathMinus,
|
|
567
|
-
mathPlus: () => mathPlus,
|
|
568
|
-
mathPow: () => mathPow,
|
|
569
|
-
mathRound: () => mathRound,
|
|
570
|
-
mathTimes: () => mathTimes,
|
|
571
|
-
randomBoolean: () => randomBoolean,
|
|
572
|
-
setObjectValue: () => setObjectValue,
|
|
573
|
-
toAsync: () => toAsync,
|
|
574
|
-
toChineseCurrency: () => toChineseCurrency,
|
|
575
|
-
toChineseNum: () => toChineseNum,
|
|
576
|
-
toDayjs: () => toDayjs,
|
|
577
|
-
toMaskName: () => toMaskName,
|
|
578
|
-
toMaskPhone: () => toMaskPhone,
|
|
579
|
-
toMaskText: () => toMaskText,
|
|
580
|
-
toThousandth: () => toThousandth,
|
|
581
|
-
withDistance: () => withDistance,
|
|
582
|
-
withUnit: () => withUnit,
|
|
583
|
-
withUnitPx: () => withUnitPx,
|
|
584
|
-
zeroPad: () => zeroPad
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
// src/ts/array/index.ts
|
|
588
|
-
function arrayMove(list, fromIndex, toIndex) {
|
|
589
|
-
const newList = [...list];
|
|
590
|
-
const [removed] = newList.splice(fromIndex, 1);
|
|
591
|
-
newList.splice(toIndex, 0, removed);
|
|
592
|
-
return newList;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// src/ts/async/index.ts
|
|
596
|
-
async function toAsync(p) {
|
|
597
|
-
try {
|
|
598
|
-
const data = await p;
|
|
599
|
-
return [data, null];
|
|
600
|
-
} catch (err) {
|
|
601
|
-
return [null, err];
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/ts/bean/EventBus.ts
|
|
606
|
-
import mitt from "mitt";
|
|
607
|
-
var EventBus = class {
|
|
608
|
-
_emitter = mitt();
|
|
609
|
-
/** 订阅 */
|
|
610
|
-
on(type, fn) {
|
|
611
|
-
this._emitter.on(type, fn);
|
|
612
|
-
return this;
|
|
613
|
-
}
|
|
614
|
-
/** 订阅一次 */
|
|
615
|
-
once(type, fn) {
|
|
616
|
-
const wrap = (event) => {
|
|
617
|
-
this._emitter.off(type, wrap);
|
|
618
|
-
fn(event);
|
|
619
|
-
};
|
|
620
|
-
this._emitter.on(type, wrap);
|
|
621
|
-
return this;
|
|
622
|
-
}
|
|
623
|
-
/** 发布 */
|
|
624
|
-
emit(type, event) {
|
|
625
|
-
this._emitter.emit(type, event);
|
|
626
|
-
return this;
|
|
627
|
-
}
|
|
628
|
-
/** 移除 */
|
|
629
|
-
off(type, fn) {
|
|
630
|
-
this._emitter.off(type, fn);
|
|
631
|
-
return this;
|
|
632
|
-
}
|
|
633
|
-
/** 清空 */
|
|
634
|
-
clear() {
|
|
635
|
-
this._emitter.all.clear();
|
|
636
|
-
return this;
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
// src/ts/day/index.ts
|
|
641
|
-
import dayjs from "dayjs";
|
|
642
|
-
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
643
|
-
import utc from "dayjs/plugin/utc";
|
|
644
|
-
import timezone from "dayjs/plugin/timezone";
|
|
645
|
-
import relativeTime from "dayjs/plugin/relativeTime";
|
|
646
|
-
import advancedFormat from "dayjs/plugin/advancedFormat";
|
|
647
|
-
import "dayjs/locale/zh-cn";
|
|
648
|
-
|
|
649
|
-
// src/ts/number/big.ts
|
|
650
|
-
import BigNumber from "bignumber.js";
|
|
651
|
-
function big(x) {
|
|
652
|
-
return x instanceof BigNumber ? x : new BigNumber(x);
|
|
653
|
-
}
|
|
654
|
-
function mathPlus(...rest) {
|
|
655
|
-
let acc = big(rest[0]);
|
|
656
|
-
for (const x of rest.slice(1)) acc = acc.plus(big(x));
|
|
657
|
-
return acc.toNumber();
|
|
658
|
-
}
|
|
659
|
-
function mathMinus(...rest) {
|
|
660
|
-
let acc = big(rest[0]);
|
|
661
|
-
for (const x of rest.slice(1)) acc = acc.minus(big(x));
|
|
662
|
-
return acc.toNumber();
|
|
663
|
-
}
|
|
664
|
-
function mathTimes(...rest) {
|
|
665
|
-
let acc = big(rest[0]);
|
|
666
|
-
for (const x of rest.slice(1)) acc = acc.times(big(x));
|
|
667
|
-
return acc.toNumber();
|
|
668
|
-
}
|
|
669
|
-
function mathDiv(...rest) {
|
|
670
|
-
let acc = big(rest[0]);
|
|
671
|
-
for (const x of rest.slice(1)) acc = acc.div(big(x));
|
|
672
|
-
return acc.toNumber();
|
|
673
|
-
}
|
|
674
|
-
function mathPow(x, y) {
|
|
675
|
-
return big(x).pow(big(y)).toNumber();
|
|
676
|
-
}
|
|
677
|
-
function mathRound(x, dp = 0, rm = BigNumber.ROUND_HALF_UP) {
|
|
678
|
-
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
679
|
-
}
|
|
680
|
-
function mathFixed(x, dp = 2, rm = BigNumber.ROUND_HALF_UP) {
|
|
681
|
-
return big(x).toFixed(dp, rm);
|
|
682
|
-
}
|
|
683
|
-
function mathCompare(a, b) {
|
|
684
|
-
return big(a).comparedTo(big(b));
|
|
685
|
-
}
|
|
686
|
-
function mathEqual(a, b) {
|
|
687
|
-
return big(a).isEqualTo(big(b));
|
|
688
|
-
}
|
|
689
|
-
function mathGreaterThan(a, b) {
|
|
690
|
-
return big(a).isGreaterThan(big(b));
|
|
691
|
-
}
|
|
692
|
-
function mathGreaterThanOrEqual(a, b) {
|
|
693
|
-
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
694
|
-
}
|
|
695
|
-
function mathLessThan(a, b) {
|
|
696
|
-
return big(a).isLessThan(big(b));
|
|
697
|
-
}
|
|
698
|
-
function mathLessThanOrEqual(a, b) {
|
|
699
|
-
return big(a).isLessThanOrEqualTo(big(b));
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// src/ts/number/format.ts
|
|
703
|
-
function zeroPad(n, len = 2) {
|
|
704
|
-
return String(n).padStart(len, "0");
|
|
705
|
-
}
|
|
706
|
-
function withUnit(num, unit = "") {
|
|
707
|
-
if (num === null || num === void 0 || num === "") return "";
|
|
708
|
-
if (typeof num === "number") return `${num}${unit}`;
|
|
709
|
-
const str = String(num).trim();
|
|
710
|
-
if (str === "") return "";
|
|
711
|
-
return isNaN(+str) ? str : `${str}${unit}`;
|
|
712
|
-
}
|
|
713
|
-
function withUnitPx(num) {
|
|
714
|
-
return withUnit(num, "px");
|
|
715
|
-
}
|
|
716
|
-
function withDistance(m) {
|
|
717
|
-
const n = Number(m ?? 0);
|
|
718
|
-
if (!Number.isFinite(n)) return "0m";
|
|
719
|
-
return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
|
|
720
|
-
}
|
|
721
|
-
function toThousandth(str) {
|
|
722
|
-
const v = String(str ?? "").trim();
|
|
723
|
-
if (v === "") return "";
|
|
724
|
-
let sign = "";
|
|
725
|
-
let num = v;
|
|
726
|
-
if (num[0] === "-" || num[0] === "+") {
|
|
727
|
-
sign = num[0];
|
|
728
|
-
num = num.slice(1);
|
|
729
|
-
}
|
|
730
|
-
const [intPart, decPart] = num.split(".");
|
|
731
|
-
const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
732
|
-
return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
|
|
733
|
-
}
|
|
734
|
-
function toChineseNum(num) {
|
|
735
|
-
const numInt = Math.trunc(+num);
|
|
736
|
-
if (numInt === 0) return "\u96F6";
|
|
737
|
-
const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
|
|
738
|
-
const unit = ["", "\u5341", "\u767E", "\u5343"];
|
|
739
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
740
|
-
const section4 = (n2) => {
|
|
741
|
-
let str = "", zeroFlag = false;
|
|
742
|
-
for (let i = 0; i < 4; i++) {
|
|
743
|
-
const d = n2 % 10;
|
|
744
|
-
n2 = Math.floor(n2 / 10);
|
|
745
|
-
if (d === 0) {
|
|
746
|
-
zeroFlag = true;
|
|
747
|
-
continue;
|
|
748
|
-
}
|
|
749
|
-
if (zeroFlag) str = digit[0] + str;
|
|
750
|
-
str = digit[d] + unit[i] + str;
|
|
751
|
-
zeroFlag = false;
|
|
752
|
-
}
|
|
753
|
-
return str;
|
|
754
|
-
};
|
|
755
|
-
let res = "";
|
|
756
|
-
let sectionIndex = 0;
|
|
757
|
-
let n = Math.abs(numInt);
|
|
758
|
-
while (n > 0) {
|
|
759
|
-
const seg = n % 1e4;
|
|
760
|
-
n = Math.floor(n / 1e4);
|
|
761
|
-
if (seg) {
|
|
762
|
-
const segStr = section4(seg);
|
|
763
|
-
res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
|
|
764
|
-
} else if (res && !res.startsWith("\u96F6")) {
|
|
765
|
-
res = `\u96F6${res}`;
|
|
766
|
-
}
|
|
767
|
-
sectionIndex++;
|
|
768
|
-
}
|
|
769
|
-
res = res.replace(/^一十/, "\u5341");
|
|
770
|
-
return numInt < 0 ? `\u8D1F${res}` : res;
|
|
771
|
-
}
|
|
772
|
-
function toChineseCurrency(amount, opts = {}) {
|
|
773
|
-
const dp = opts.precision ?? 2;
|
|
774
|
-
const rm = opts.rm ?? BigNumber.ROUND_HALF_UP;
|
|
775
|
-
const yuan = opts.yuanChar ?? "\u5143";
|
|
776
|
-
if (amount === null || amount === void 0) return "";
|
|
777
|
-
const bn = new BigNumber(amount);
|
|
778
|
-
if (!bn.isFinite()) return "";
|
|
779
|
-
const s = bn.toFixed(dp, rm);
|
|
780
|
-
const sign = s.startsWith("-") ? "\u8D1F" : "";
|
|
781
|
-
const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
|
|
782
|
-
const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
783
|
-
const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
784
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
785
|
-
const smallUnit = ["\u89D2", "\u5206", "\u5398"];
|
|
786
|
-
const section4 = (n) => {
|
|
787
|
-
let str = "";
|
|
788
|
-
let zeroFlag = false;
|
|
789
|
-
for (let i = 0; i < 4; i++) {
|
|
790
|
-
const d = n.mod(10).toNumber();
|
|
791
|
-
n = n.idiv(10);
|
|
792
|
-
if (d === 0) {
|
|
793
|
-
zeroFlag = true;
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
if (zeroFlag) str = digit[0] + str;
|
|
797
|
-
str = digit[d] + unit[i] + str;
|
|
798
|
-
zeroFlag = false;
|
|
799
|
-
}
|
|
800
|
-
return str.replace(/零+$/g, "");
|
|
801
|
-
};
|
|
802
|
-
const intNum = new BigNumber(intStr);
|
|
803
|
-
let res = "";
|
|
804
|
-
if (intNum.isZero()) {
|
|
805
|
-
res = digit[0];
|
|
806
|
-
} else {
|
|
807
|
-
let n = intNum.abs();
|
|
808
|
-
let sectionIndex = 0;
|
|
809
|
-
while (n.gt(0)) {
|
|
810
|
-
const seg = n.mod(1e4);
|
|
811
|
-
n = n.idiv(1e4);
|
|
812
|
-
if (seg.gt(0)) {
|
|
813
|
-
const segStr = section4(seg);
|
|
814
|
-
const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
|
|
815
|
-
const bu = sectionIndex ? bigUnit[sectionIndex] : "";
|
|
816
|
-
res = segStr + bu + (needZero ? digit[0] : "") + res;
|
|
817
|
-
} else if (res && !res.startsWith(digit[0])) {
|
|
818
|
-
res = digit[0] + res;
|
|
819
|
-
}
|
|
820
|
-
sectionIndex++;
|
|
821
|
-
}
|
|
822
|
-
res = res.replace(/^壹拾/, "\u62FE");
|
|
823
|
-
}
|
|
824
|
-
let frac = "";
|
|
825
|
-
for (let i = 0; i < Math.min(3, dp); i++) {
|
|
826
|
-
const ch = decStr[i] || "0";
|
|
827
|
-
const d = ch.charCodeAt(0) - 48;
|
|
828
|
-
if (d > 0) frac += digit[d] + smallUnit[i];
|
|
829
|
-
}
|
|
830
|
-
return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// src/ts/number/random.ts
|
|
834
|
-
function randomBoolean() {
|
|
835
|
-
return Math.random() < 0.5;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// src/ts/day/index.ts
|
|
839
|
-
dayjs.extend(customParseFormat);
|
|
840
|
-
dayjs.extend(utc);
|
|
841
|
-
dayjs.extend(timezone);
|
|
842
|
-
dayjs.extend(relativeTime);
|
|
843
|
-
dayjs.extend(advancedFormat);
|
|
844
|
-
dayjs.locale("zh-cn");
|
|
845
|
-
function toDayjs(t, fmt) {
|
|
846
|
-
if (t === null || t === void 0) return dayjs();
|
|
847
|
-
if (typeof t === "number") {
|
|
848
|
-
const s = String(Math.trunc(t));
|
|
849
|
-
return dayjs(s.length === 10 ? t * 1e3 : t, fmt);
|
|
850
|
-
}
|
|
851
|
-
if (typeof t === "string") {
|
|
852
|
-
const s = t.trim();
|
|
853
|
-
if (/^\d{10}$/.test(s)) return dayjs(Number(s) * 1e3, fmt);
|
|
854
|
-
if (/^\d{13}$/.test(s)) return dayjs(Number(s), fmt);
|
|
855
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY-MM-DD");
|
|
856
|
-
if (/^\d{4}\/\d{2}\/\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY/MM/DD");
|
|
857
|
-
if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
858
|
-
return dayjs(s, fmt || "YYYY-MM-DD HH:mm:ss");
|
|
859
|
-
if (/^\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
860
|
-
return dayjs(s, fmt || "YYYY/MM/DD HH:mm:ss");
|
|
861
|
-
return dayjs(s, fmt);
|
|
862
|
-
}
|
|
863
|
-
return dayjs(t, fmt);
|
|
864
|
-
}
|
|
865
|
-
function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
|
|
866
|
-
const now = toDayjs(Date.now());
|
|
867
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
868
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
869
|
-
const startDay = now.add(-n, "day");
|
|
870
|
-
const endDay = now;
|
|
871
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
872
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
873
|
-
return [start, end];
|
|
874
|
-
}
|
|
875
|
-
function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
|
|
876
|
-
const now = toDayjs(Date.now());
|
|
877
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
878
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
879
|
-
const startDay = now;
|
|
880
|
-
const endDay = now.add(n, "day");
|
|
881
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
882
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
883
|
-
return [start, end];
|
|
884
|
-
}
|
|
885
|
-
function getCountdownParts(diff) {
|
|
886
|
-
if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
|
|
887
|
-
const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
888
|
-
const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
|
|
889
|
-
const m = Math.floor(diff / (1e3 * 60) % 60);
|
|
890
|
-
const s = Math.floor(diff / 1e3 % 60);
|
|
891
|
-
const ms = diff % 1e3;
|
|
892
|
-
return {
|
|
893
|
-
d: zeroPad(d),
|
|
894
|
-
h: zeroPad(h),
|
|
895
|
-
m: zeroPad(m),
|
|
896
|
-
s: zeroPad(s),
|
|
897
|
-
ms: zeroPad(ms, 3)
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
function getAgeByBirthdate(birthdate) {
|
|
901
|
-
const birth = toDayjs(birthdate, "YYYY-MM-DD");
|
|
902
|
-
const now = toDayjs(Date.now());
|
|
903
|
-
const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
|
|
904
|
-
const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
|
|
905
|
-
if (adjustedMonths >= 12) {
|
|
906
|
-
let age = Math.floor(adjustedMonths / 12);
|
|
907
|
-
const birthdayThisYear = birth.add(age, "year");
|
|
908
|
-
if (now.isBefore(birthdayThisYear)) {
|
|
909
|
-
age--;
|
|
910
|
-
}
|
|
911
|
-
return { age, type: "year" };
|
|
912
|
-
}
|
|
913
|
-
return { age: adjustedMonths, type: "month" };
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
// src/ts/es-toolkit/index.ts
|
|
917
|
-
var es_toolkit_exports = {};
|
|
918
|
-
__reExport(es_toolkit_exports, es_toolkit_star);
|
|
919
|
-
import * as es_toolkit_star from "es-toolkit";
|
|
920
|
-
|
|
921
|
-
// src/ts/index.ts
|
|
922
|
-
__reExport(ts_exports, es_toolkit_exports);
|
|
923
|
-
|
|
924
|
-
// src/ts/object/index.ts
|
|
925
|
-
import { get, set } from "es-toolkit/compat";
|
|
926
|
-
function getObjectKeys(obj) {
|
|
927
|
-
return Object.keys(obj);
|
|
928
|
-
}
|
|
929
|
-
var getObjectValue = get;
|
|
930
|
-
var setObjectValue = set;
|
|
931
|
-
|
|
932
|
-
// src/ts/string/format.ts
|
|
933
|
-
function toMaskText(s, keepLeft = 1, keepRight = 0, maskChar = "*") {
|
|
934
|
-
if (!s) return "";
|
|
935
|
-
const v = String(s);
|
|
936
|
-
const l = Math.max(0, keepLeft);
|
|
937
|
-
const r = Math.max(0, keepRight);
|
|
938
|
-
const len = v.length;
|
|
939
|
-
const left = Math.min(l, len);
|
|
940
|
-
const right = Math.min(r, len - left);
|
|
941
|
-
const mid = len - left - right;
|
|
942
|
-
if (mid <= 0) return v;
|
|
943
|
-
const m = maskChar && maskChar.length > 0 ? maskChar : "*";
|
|
944
|
-
return v.slice(0, left) + m.repeat(mid) + v.slice(len - right);
|
|
945
|
-
}
|
|
946
|
-
function toMaskPhone(phone) {
|
|
947
|
-
return toMaskText(phone, 3, 4);
|
|
948
|
-
}
|
|
949
|
-
function toMaskName(name) {
|
|
950
|
-
if (!name) return "";
|
|
951
|
-
const v = String(name);
|
|
952
|
-
return v.length <= 2 ? toMaskText(v, 1, 0) : toMaskText(v, 1, 1);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
// src/ts/string/random.ts
|
|
956
|
-
function createUUID() {
|
|
957
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
958
|
-
const r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
|
|
959
|
-
return v.toString(16);
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
function createRandId(prefix = "id_") {
|
|
963
|
-
return `${prefix}${Math.random().toString(36).substring(2, 16)}`;
|
|
964
|
-
}
|
|
965
|
-
function createTimeRandId(digits = 6) {
|
|
966
|
-
const base = 10 ** (digits - 1);
|
|
967
|
-
const range = 9 * base;
|
|
968
|
-
const int = Math.floor(Math.random() * range) + base;
|
|
969
|
-
return `${Date.now()}${int}`;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
// src/ts/string/other.ts
|
|
973
|
-
function getByteLength(data) {
|
|
974
|
-
if (typeof data === "string") {
|
|
975
|
-
let byteLen = 0;
|
|
976
|
-
for (let i = 0; i < data.length; i++) {
|
|
977
|
-
const code = data.charCodeAt(i);
|
|
978
|
-
if (code <= 127) {
|
|
979
|
-
byteLen += 1;
|
|
980
|
-
} else if (code <= 2047) {
|
|
981
|
-
byteLen += 2;
|
|
982
|
-
} else if (code >= 55296 && code <= 56319) {
|
|
983
|
-
byteLen += 4;
|
|
984
|
-
i++;
|
|
985
|
-
} else {
|
|
986
|
-
byteLen += 3;
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
return byteLen;
|
|
990
|
-
}
|
|
991
|
-
if ("byteLength" in data) return data.byteLength;
|
|
992
|
-
if ("size" in data) return data.size;
|
|
993
|
-
throw new TypeError("getByteLength: Unsupported type");
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// src/ts/url/file/index.ts
|
|
997
|
-
var FILE_TYPE = {
|
|
998
|
-
img: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
|
|
999
|
-
video: ["mp4", "mov", "m4v"],
|
|
1000
|
-
voice: ["mp3", "wav", "m4a"],
|
|
1001
|
-
excel: ["csv", "xls", "xlsx", "xlsm", "ods"],
|
|
1002
|
-
word: ["txt", "doc", "docx", "pdf", "md", "wps"],
|
|
1003
|
-
zip: ["zip", "gz", "tar", "rar", "7z"],
|
|
1004
|
-
ppt: ["ppt", "pptx", "odp"],
|
|
1005
|
-
app: ["apk", "ipa"]
|
|
1006
|
-
};
|
|
1007
|
-
function getFileSuffix(fileName) {
|
|
1008
|
-
if (fileName.startsWith(".")) return "";
|
|
1009
|
-
const idx = fileName.lastIndexOf(".");
|
|
1010
|
-
return idx > 0 ? fileName.slice(idx + 1).toLowerCase() : "";
|
|
1011
|
-
}
|
|
1012
|
-
function getFileType(fileName) {
|
|
1013
|
-
const suffix = getFileSuffix(fileName);
|
|
1014
|
-
if (!suffix) return "unknown";
|
|
1015
|
-
const keys = getObjectKeys(FILE_TYPE);
|
|
1016
|
-
for (const key of keys) {
|
|
1017
|
-
if (FILE_TYPE[key].includes(suffix)) {
|
|
1018
|
-
return key;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
return "unknown";
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
// src/ts/url/oss/index.ts
|
|
1025
|
-
function getOSSImg(src, option) {
|
|
1026
|
-
return buildOSSUrl(src, "image", option);
|
|
1027
|
-
}
|
|
1028
|
-
function getOSSVideo(src, option) {
|
|
1029
|
-
return buildOSSUrl(src, "video", option);
|
|
1030
|
-
}
|
|
1031
|
-
function getOSSAudio(src, option) {
|
|
1032
|
-
return buildOSSUrl(src, "audio", option);
|
|
1033
|
-
}
|
|
1034
|
-
function getOSSHls(src, option) {
|
|
1035
|
-
return buildOSSUrl(src, "hls", option);
|
|
1036
|
-
}
|
|
1037
|
-
function buildOSSUrl(src, type, option) {
|
|
1038
|
-
if (!src || !option) return src;
|
|
1039
|
-
if (src.startsWith("blob:")) return src;
|
|
1040
|
-
if (src.includes(".svg")) return src;
|
|
1041
|
-
const segs = [];
|
|
1042
|
-
for (const [k, v] of Object.entries(option)) {
|
|
1043
|
-
const seg = k === "watermark" ? getWatermark(v) : getOSSSegs(k, v);
|
|
1044
|
-
if (seg) segs.push(seg);
|
|
1045
|
-
}
|
|
1046
|
-
if (!segs.length) return src;
|
|
1047
|
-
const base = src.split("?")[0];
|
|
1048
|
-
return `${base}?x-oss-process=${type}/${segs.join("/")}`;
|
|
1049
|
-
}
|
|
1050
|
-
function getOSSSegs(type, option) {
|
|
1051
|
-
if (!option && option !== 0) return "";
|
|
1052
|
-
if (option === true) return type;
|
|
1053
|
-
if (typeof option === "number" || typeof option === "string") return `${type},${option}`;
|
|
1054
|
-
const segs = Object.entries(option).map(([k, v]) => `${k}_${v}`).join(",");
|
|
1055
|
-
return segs ? `${type},${segs}` : "";
|
|
1056
|
-
}
|
|
1057
|
-
function getWatermark(w) {
|
|
1058
|
-
if (!w) return "";
|
|
1059
|
-
if (w.image) w.image = toBase64Url(w.image);
|
|
1060
|
-
if (w.text) w.text = toBase64Url(w.text);
|
|
1061
|
-
if (w.type) w.type = toBase64Url(w.type);
|
|
1062
|
-
return getOSSSegs("watermark", w);
|
|
1063
|
-
}
|
|
1064
|
-
function toBase64Url(s) {
|
|
1065
|
-
let b64 = "";
|
|
1066
|
-
if (typeof Buffer !== "undefined") {
|
|
1067
|
-
const buf = Buffer.from(s, "utf-8");
|
|
1068
|
-
b64 = buf.toString("base64");
|
|
1069
|
-
} else {
|
|
1070
|
-
try {
|
|
1071
|
-
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1072
|
-
} catch {
|
|
1073
|
-
b64 = "";
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
// src/ts/url/param/index.ts
|
|
1080
|
-
function appendUrlParam(url, param) {
|
|
1081
|
-
if (!param || typeof param !== "object") return url;
|
|
1082
|
-
const hashIndex = url.indexOf("#");
|
|
1083
|
-
const baseWithoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
1084
|
-
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
1085
|
-
const [base, existingQs] = baseWithoutHash.split("?");
|
|
1086
|
-
const parts = [];
|
|
1087
|
-
if (existingQs) parts.push(existingQs);
|
|
1088
|
-
for (const key in param) {
|
|
1089
|
-
const rawVal = param[key];
|
|
1090
|
-
if (rawVal === null || rawVal === void 0) continue;
|
|
1091
|
-
const val = typeof rawVal === "object" ? JSON.stringify(rawVal) : String(rawVal);
|
|
1092
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`);
|
|
1093
|
-
}
|
|
1094
|
-
const qs = parts.filter(Boolean).join("&");
|
|
1095
|
-
return base + (qs ? `?${qs}` : "") + hash;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// src/ts/url/qn/index.ts
|
|
1099
|
-
function getQnImg(src, option) {
|
|
1100
|
-
if (!src || !option) return src;
|
|
1101
|
-
if (src.startsWith("blob:")) return src;
|
|
1102
|
-
if (src.includes(".svg")) return src;
|
|
1103
|
-
const segs = [];
|
|
1104
|
-
if (option.imageslim) segs.push("imageslim");
|
|
1105
|
-
if (option.imageView2) segs.push(getImageView2(option.imageView2));
|
|
1106
|
-
const mogr = getImageMogr2(option.imageMogr2 ?? option);
|
|
1107
|
-
if (mogr) segs.push(mogr);
|
|
1108
|
-
if (option.watermark) segs.push(getWatermark2(option.watermark));
|
|
1109
|
-
if (option.imageInfo) segs.push("imageInfo");
|
|
1110
|
-
if (!segs.length) return src;
|
|
1111
|
-
const base = src.split("?")[0];
|
|
1112
|
-
return `${base}?${segs.join("|")}`;
|
|
1113
|
-
}
|
|
1114
|
-
function getQnVideo(src, option) {
|
|
1115
|
-
if (!src || !option) return src;
|
|
1116
|
-
if (src.startsWith("blob:")) return src;
|
|
1117
|
-
if (src.includes(".svg")) return src;
|
|
1118
|
-
const segs = [];
|
|
1119
|
-
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1120
|
-
if (option.vframe) segs.push(getVframe(option.vframe));
|
|
1121
|
-
if (!segs.length) return src;
|
|
1122
|
-
const base = src.split("?")[0];
|
|
1123
|
-
return `${base}?${segs.join("|")}`;
|
|
1124
|
-
}
|
|
1125
|
-
function getQnAudio(src, option) {
|
|
1126
|
-
if (!src || !option) return src;
|
|
1127
|
-
if (src.startsWith("blob:")) return src;
|
|
1128
|
-
const segs = [];
|
|
1129
|
-
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1130
|
-
if (!segs.length) return src;
|
|
1131
|
-
const base = src.split("?")[0];
|
|
1132
|
-
return `${base}?${segs.join("|")}`;
|
|
1133
|
-
}
|
|
1134
|
-
function getQnHls(src, option) {
|
|
1135
|
-
if (!src || !option) return src;
|
|
1136
|
-
if (src.startsWith("blob:")) return src;
|
|
1137
|
-
const seg = getAvcvt(option);
|
|
1138
|
-
if (!seg) return src;
|
|
1139
|
-
const base = src.split("?")[0];
|
|
1140
|
-
return `${base}?${seg}`;
|
|
1141
|
-
}
|
|
1142
|
-
function getImageView2(opt) {
|
|
1143
|
-
if (!opt) return "";
|
|
1144
|
-
const mode = typeof opt.mode === "number" ? opt.mode : 0;
|
|
1145
|
-
const kv = [];
|
|
1146
|
-
for (const [k, v] of Object.entries(opt)) {
|
|
1147
|
-
if (k === "mode") continue;
|
|
1148
|
-
if (typeof v === "boolean") {
|
|
1149
|
-
if (v) kv.push(`${k}/1`);
|
|
1150
|
-
} else if (typeof v === "number" || typeof v === "string") {
|
|
1151
|
-
kv.push(`${k}/${v}`);
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
return kv.length ? `imageView2/${mode}/${kv.join("/")}` : `imageView2/${mode}`;
|
|
1155
|
-
}
|
|
1156
|
-
function getImageMogr2(opt) {
|
|
1157
|
-
if (!opt) return "";
|
|
1158
|
-
const parts = [];
|
|
1159
|
-
const tn = opt.thumbnail;
|
|
1160
|
-
if (typeof tn !== "undefined") parts.push(`thumbnail/${tn}`);
|
|
1161
|
-
const cp = opt.crop;
|
|
1162
|
-
if (typeof cp !== "undefined") parts.push(`crop/${cp}`);
|
|
1163
|
-
const rot = opt.rotate;
|
|
1164
|
-
if (typeof rot === "number") parts.push(`rotate/${rot}`);
|
|
1165
|
-
const ao = opt["auto-orient"];
|
|
1166
|
-
if (ao) parts.push("auto-orient");
|
|
1167
|
-
const fmt = opt.format;
|
|
1168
|
-
if (typeof fmt === "string") parts.push(`format/${fmt}`);
|
|
1169
|
-
const il = opt.interlace;
|
|
1170
|
-
if (il === 0 || il === 1) parts.push(`interlace/${il}`);
|
|
1171
|
-
const bg = opt.background;
|
|
1172
|
-
if (typeof bg === "string") parts.push(`background/${bg}`);
|
|
1173
|
-
const q = opt.q;
|
|
1174
|
-
if (typeof q === "number") parts.push(`q/${q}`);
|
|
1175
|
-
const blur = opt.blur;
|
|
1176
|
-
if (typeof blur !== "undefined") {
|
|
1177
|
-
if (typeof blur === "string") parts.push(`blur/${blur}`);
|
|
1178
|
-
else parts.push(`blur/${blur.r}x${blur.s}`);
|
|
1179
|
-
}
|
|
1180
|
-
const colors = opt.colors;
|
|
1181
|
-
if (typeof colors === "number") parts.push(`colors/${colors}`);
|
|
1182
|
-
return parts.length ? `imageMogr2/${parts.join("/")}` : "";
|
|
1183
|
-
}
|
|
1184
|
-
function getWatermark2(w) {
|
|
1185
|
-
if (!w) return "";
|
|
1186
|
-
const mode = w.type === "image" ? 1 : w.type === "text" ? 2 : typeof w.type === "number" ? w.type : 2;
|
|
1187
|
-
const segs = [`watermark/${mode}`];
|
|
1188
|
-
if (mode === 1 && w.image) segs.push(`image/${toBase64Url2(w.image)}`);
|
|
1189
|
-
if (mode === 2 && w.text) segs.push(`text/${toBase64Url2(w.text)}`);
|
|
1190
|
-
if (w.font) segs.push(`font/${toBase64Url2(w.font)}`);
|
|
1191
|
-
if (typeof w.fontsize === "number") segs.push(`fontsize/${w.fontsize}`);
|
|
1192
|
-
if (w.fill) segs.push(`fill/${toBase64Url2(w.fill)}`);
|
|
1193
|
-
if (w.gravity) segs.push(`gravity/${w.gravity}`);
|
|
1194
|
-
if (typeof w.dx === "number") segs.push(`dx/${w.dx}`);
|
|
1195
|
-
if (typeof w.dy === "number") segs.push(`dy/${w.dy}`);
|
|
1196
|
-
if (typeof w.dissolve === "number") segs.push(`dissolve/${w.dissolve}`);
|
|
1197
|
-
return segs.join("/");
|
|
1198
|
-
}
|
|
1199
|
-
function toBase64Url2(s) {
|
|
1200
|
-
let b64 = "";
|
|
1201
|
-
if (typeof Buffer !== "undefined") {
|
|
1202
|
-
const buf = Buffer.from(s, "utf-8");
|
|
1203
|
-
b64 = buf.toString("base64");
|
|
1204
|
-
} else {
|
|
1205
|
-
try {
|
|
1206
|
-
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1207
|
-
} catch {
|
|
1208
|
-
b64 = "";
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1212
|
-
}
|
|
1213
|
-
function getAvthumb(opt) {
|
|
1214
|
-
const parts = [];
|
|
1215
|
-
if (opt.format) parts.push(`avthumb/${opt.format}`);
|
|
1216
|
-
else parts.push("avthumb");
|
|
1217
|
-
if (opt.s) parts.push(`s/${opt.s}`);
|
|
1218
|
-
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1219
|
-
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1220
|
-
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1221
|
-
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1222
|
-
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1223
|
-
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1224
|
-
return parts.join("/");
|
|
1225
|
-
}
|
|
1226
|
-
function getVframe(opt) {
|
|
1227
|
-
const parts = [];
|
|
1228
|
-
parts.push(`vframe/${opt.format || "jpg"}`);
|
|
1229
|
-
if (typeof opt.offset === "number") parts.push(`offset/${opt.offset}`);
|
|
1230
|
-
if (typeof opt.w === "number") parts.push(`w/${opt.w}`);
|
|
1231
|
-
if (typeof opt.h === "number") parts.push(`h/${opt.h}`);
|
|
1232
|
-
return parts.join("/");
|
|
1233
|
-
}
|
|
1234
|
-
function getAvcvt(opt) {
|
|
1235
|
-
const parts = [];
|
|
1236
|
-
const level = typeof opt.level === "number" ? `/${opt.level}` : "/3";
|
|
1237
|
-
parts.push(`avcvt${level}`);
|
|
1238
|
-
parts.push(`format/${opt.format || "m3u8"}`);
|
|
1239
|
-
if (typeof opt.segtime === "number") parts.push(`segtime/${opt.segtime}`);
|
|
1240
|
-
if (typeof opt.t === "string") parts.push(`t/${opt.t}`);
|
|
1241
|
-
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1242
|
-
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1243
|
-
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1244
|
-
if (typeof opt.s === "string") parts.push(`s/${opt.s}`);
|
|
1245
|
-
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1246
|
-
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1247
|
-
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1248
|
-
if (typeof opt.output === "string") parts.push(`output/${toBase64Url2(opt.output)}`);
|
|
1249
|
-
return parts.join("/");
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
// src/ts/validator/index.ts
|
|
1253
|
-
function isLetter(s) {
|
|
1254
|
-
return /^[a-zA-Z]*$/.test(s);
|
|
1255
|
-
}
|
|
1256
|
-
function isChinese(s) {
|
|
1257
|
-
const v = String(s ?? "").trim();
|
|
1258
|
-
return /^[\u4E00-\u9FA5]+$/.test(v);
|
|
1259
|
-
}
|
|
1260
|
-
function isDigits(s) {
|
|
1261
|
-
return /^[0-9]+$/.test(s);
|
|
1262
|
-
}
|
|
1263
|
-
function isNumeric(value, options) {
|
|
1264
|
-
const { negative = false, decimal = 2, thousands = false, leadZero = false } = options || {};
|
|
1265
|
-
if (value === null || value === void 0 || value === "") return false;
|
|
1266
|
-
const str = String(value).trim();
|
|
1267
|
-
const sign = negative && str.startsWith("-") ? "-" : "";
|
|
1268
|
-
const body = sign ? str.slice(1) : str;
|
|
1269
|
-
const thousandsPart = thousands ? "(?:[1-9]\\d{0,2}(,\\d{3})*|0)" : "(?:\\d+)";
|
|
1270
|
-
const intPart = thousands ? thousandsPart : leadZero ? "(?:\\d+)" : "(?:0|[1-9]\\d*)";
|
|
1271
|
-
const fracPart = decimal === 0 ? "" : `(\\.\\d{1,${decimal}})`;
|
|
1272
|
-
const pattern = `^${intPart}${fracPart}$`;
|
|
1273
|
-
const reg = new RegExp(pattern);
|
|
1274
|
-
return reg.test(body);
|
|
1275
|
-
}
|
|
1276
|
-
function isMobilePhone(s) {
|
|
1277
|
-
const v = String(s ?? "").trim();
|
|
1278
|
-
return /^1[3-9]\d{9}$/.test(v);
|
|
1279
|
-
}
|
|
1280
|
-
function isLandline(s) {
|
|
1281
|
-
const v = String(s ?? "").trim();
|
|
1282
|
-
return /^0\d{2,3}-?\d{7,8}(?:-\d{1,6})?$/.test(v);
|
|
1283
|
-
}
|
|
1284
|
-
function isPhone(s) {
|
|
1285
|
-
return isMobilePhone(s) || isLandline(s);
|
|
1286
|
-
}
|
|
1287
|
-
function isEmail(s) {
|
|
1288
|
-
const v = String(s ?? "").trim();
|
|
1289
|
-
if (v === "") return false;
|
|
1290
|
-
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/;
|
|
1291
|
-
return emailRegex.test(v);
|
|
1292
|
-
}
|
|
1293
|
-
function isChineseName(s) {
|
|
1294
|
-
const v = String(s ?? "").trim();
|
|
1295
|
-
return /^[\u4E00-\u9FA5·]{2,20}$/.test(v);
|
|
1296
|
-
}
|
|
1297
|
-
function isIdentityCard(code) {
|
|
1298
|
-
const v = String(code ?? "").trim();
|
|
1299
|
-
if (v === "") return false;
|
|
1300
|
-
const isValidDate = (yyyymmdd) => {
|
|
1301
|
-
const y = Number(yyyymmdd.slice(0, 4));
|
|
1302
|
-
const m = Number(yyyymmdd.slice(4, 6));
|
|
1303
|
-
const d = Number(yyyymmdd.slice(6, 8));
|
|
1304
|
-
if (y < 1900 || y > 2100) return false;
|
|
1305
|
-
const date = new Date(y, m - 1, d);
|
|
1306
|
-
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1307
|
-
};
|
|
1308
|
-
if (/^\d{17}[\dXx]$/.test(v)) {
|
|
1309
|
-
const birth = v.slice(6, 14);
|
|
1310
|
-
if (!isValidDate(birth)) return false;
|
|
1311
|
-
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
1312
|
-
const checkMap = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
|
|
1313
|
-
let sum = 0;
|
|
1314
|
-
for (let i = 0; i < 17; i++) sum += Number(v[i]) * weights[i];
|
|
1315
|
-
const mod = sum % 11;
|
|
1316
|
-
const code18 = v[17].toUpperCase();
|
|
1317
|
-
return checkMap[mod] === code18;
|
|
1318
|
-
}
|
|
1319
|
-
if (/^\d{15}$/.test(v)) {
|
|
1320
|
-
const birth = v.slice(6, 12);
|
|
1321
|
-
const y = Number(`19${birth.slice(0, 2)}`);
|
|
1322
|
-
const m = Number(birth.slice(2, 4));
|
|
1323
|
-
const d = Number(birth.slice(4, 6));
|
|
1324
|
-
const date = new Date(y, m - 1, d);
|
|
1325
|
-
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1326
|
-
}
|
|
1327
|
-
if (/^[A-Za-z][12]\d{8}$/.test(v)) return true;
|
|
1328
|
-
if (/^[A-Za-z]{1,2}\d{6}\(?[0-9A]\)?$/.test(v)) return true;
|
|
1329
|
-
if (/^[157]\d{6}\(?\d\)?$/.test(v)) return true;
|
|
1330
|
-
return false;
|
|
1331
|
-
}
|
|
1332
|
-
function isPassport(s) {
|
|
1333
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim();
|
|
1334
|
-
if (t === "") return false;
|
|
1335
|
-
if (/^[EG]\d{8}$/.test(t)) return true;
|
|
1336
|
-
if (/^[DPS]\d{7}$/.test(t)) return true;
|
|
1337
|
-
if (/^[A-Za-z]\d{8}$/.test(t)) return true;
|
|
1338
|
-
if (/^[A-Za-z0-9]{6,9}$/.test(t)) return true;
|
|
1339
|
-
return false;
|
|
1340
|
-
}
|
|
1341
|
-
function isHKMOPermit(s) {
|
|
1342
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1343
|
-
return /^[HM]\d{8,10}$/.test(t);
|
|
1344
|
-
}
|
|
1345
|
-
function isTaiwanPermit(s) {
|
|
1346
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1347
|
-
if (/^\d{8}$/.test(t)) return true;
|
|
1348
|
-
if (/^[A-Z]\d{8}$/.test(t)) return true;
|
|
1349
|
-
if (/^\d{10}$/.test(t)) return true;
|
|
1350
|
-
return false;
|
|
1351
|
-
}
|
|
1352
|
-
function isOfficerId(s) {
|
|
1353
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1354
|
-
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1355
|
-
}
|
|
1356
|
-
function isSoldierId(s) {
|
|
1357
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1358
|
-
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1359
|
-
}
|
|
1360
|
-
function isMilitaryId(s) {
|
|
1361
|
-
return isOfficerId(s) || isSoldierId(s);
|
|
1362
|
-
}
|
|
1363
|
-
function isBankCard(s) {
|
|
1364
|
-
const t = String(s ?? "").replace(/[-\s]/g, "").trim();
|
|
1365
|
-
if (!/^\d{12,19}$/.test(t)) return false;
|
|
1366
|
-
let sum = 0;
|
|
1367
|
-
let shouldDouble = false;
|
|
1368
|
-
for (let i = t.length - 1; i >= 0; i--) {
|
|
1369
|
-
let digit = Number(t[i]);
|
|
1370
|
-
if (shouldDouble) {
|
|
1371
|
-
digit *= 2;
|
|
1372
|
-
if (digit > 9) digit -= 9;
|
|
1373
|
-
}
|
|
1374
|
-
sum += digit;
|
|
1375
|
-
shouldDouble = !shouldDouble;
|
|
1376
|
-
}
|
|
1377
|
-
return sum % 10 === 0;
|
|
1378
|
-
}
|
|
1379
|
-
function isLicensePlate(s) {
|
|
1380
|
-
const v = String(s ?? "").trim().toUpperCase();
|
|
1381
|
-
const prov = "\u4EAC\u6CAA\u6D25\u6E1D\u5180\u8C6B\u4E91\u8FBD\u9ED1\u6E58\u7696\u9C81\u65B0\u82CF\u6D59\u8D63\u9102\u6842\u7518\u664B\u8499\u9655\u5409\u95FD\u8D35\u9752\u85CF\u5DDD\u5B81\u743C\u7CA4";
|
|
1382
|
-
const std = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9\u6302\u5B66\u8B66\u6E2F\u6FB3]$`);
|
|
1383
|
-
const ne1 = new RegExp(`^[${prov}][A-HJ-NP-Z][DF][A-HJ-NP-Z0-9]{5}$`);
|
|
1384
|
-
const ne2 = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{5}[DF]$`);
|
|
1385
|
-
return std.test(v) || ne1.test(v) || ne2.test(v);
|
|
1386
|
-
}
|
|
1387
|
-
function isTaxID(code) {
|
|
1388
|
-
const v = String(code ?? "").trim();
|
|
1389
|
-
if (!/^[0-9A-HJ-NPQRTUWXY]{18}$/.test(v)) return false;
|
|
1390
|
-
const charset = "0123456789ABCDEFGHJKLMNPQRTUWXY";
|
|
1391
|
-
const weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
|
|
1392
|
-
const map = {};
|
|
1393
|
-
for (let i = 0; i < charset.length; i++) map[charset[i]] = i;
|
|
1394
|
-
let sum = 0;
|
|
1395
|
-
for (let i = 0; i < 17; i++) {
|
|
1396
|
-
sum += map[v[i]] * weights[i];
|
|
1397
|
-
}
|
|
1398
|
-
const logicCheck = (31 - sum % 31) % 31;
|
|
1399
|
-
const expected = charset[logicCheck];
|
|
1400
|
-
return v[17] === expected;
|
|
1401
|
-
}
|
|
1402
|
-
function isHexColor(s) {
|
|
1403
|
-
const v = String(s ?? "").trim();
|
|
1404
|
-
return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(v);
|
|
1405
|
-
}
|
|
1406
|
-
function isURL(s) {
|
|
1407
|
-
const v = String(s ?? "").trim();
|
|
1408
|
-
if (v === "") return false;
|
|
1409
|
-
try {
|
|
1410
|
-
const u = new URL(v);
|
|
1411
|
-
return ["http:", "https:", "ftp:"].includes(u.protocol) && !!u.hostname;
|
|
1412
|
-
} catch {
|
|
1413
|
-
return false;
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
function isIPv4(s) {
|
|
1417
|
-
const v = String(s ?? "").trim();
|
|
1418
|
-
if (v === "") return false;
|
|
1419
|
-
const parts = v.split(".");
|
|
1420
|
-
if (parts.length !== 4) return false;
|
|
1421
|
-
for (const p of parts) {
|
|
1422
|
-
if (!/^\d+$/.test(p)) return false;
|
|
1423
|
-
if (p.length > 1 && p.startsWith("0")) return false;
|
|
1424
|
-
const n = Number(p);
|
|
1425
|
-
if (n < 0 || n > 255) return false;
|
|
1426
|
-
}
|
|
1427
|
-
return true;
|
|
1428
|
-
}
|
|
1429
|
-
function isIPv6(s) {
|
|
1430
|
-
const v = String(s ?? "").trim();
|
|
1431
|
-
if (v === "") return false;
|
|
1432
|
-
const lastColon = v.lastIndexOf(":");
|
|
1433
|
-
if (lastColon !== -1 && v.includes(".")) {
|
|
1434
|
-
const ipv6Part = v.slice(0, lastColon);
|
|
1435
|
-
const ipv4Part = v.slice(lastColon + 1);
|
|
1436
|
-
return isIPv6(ipv6Part) && isIPv4(ipv4Part);
|
|
1437
|
-
}
|
|
1438
|
-
const dblColonCount = (v.match(/::/g) || []).length;
|
|
1439
|
-
if (dblColonCount > 1) return false;
|
|
1440
|
-
const segments = v.split(":");
|
|
1441
|
-
if (v.startsWith("::")) segments.shift();
|
|
1442
|
-
if (v.endsWith("::")) segments.pop();
|
|
1443
|
-
const segmentsFiltered = segments.filter((seg) => seg !== "");
|
|
1444
|
-
if (dblColonCount === 0 && segmentsFiltered.length !== 8) return false;
|
|
1445
|
-
if (dblColonCount === 1 && segmentsFiltered.length >= 1 && segmentsFiltered.length <= 7) {
|
|
1446
|
-
} else if (dblColonCount === 1 && segments.length === 0) {
|
|
1447
|
-
return true;
|
|
1448
|
-
} else if (dblColonCount === 0 && segmentsFiltered.length === 8) {
|
|
1449
|
-
} else {
|
|
1450
|
-
return false;
|
|
1451
|
-
}
|
|
1452
|
-
return segmentsFiltered.every(
|
|
1453
|
-
(seg) => seg.length >= 1 && seg.length <= 4 && /^[0-9a-fA-F]{1,4}$/.test(seg)
|
|
1454
|
-
);
|
|
1455
|
-
}
|
|
1456
|
-
function isIP(s, version) {
|
|
1457
|
-
if (version === 4 || version === "4") return isIPv4(s);
|
|
1458
|
-
if (version === 6 || version === "6") return isIPv6(s);
|
|
1459
|
-
return isIPv4(s) || isIPv6(s);
|
|
1460
|
-
}
|
|
1461
|
-
function isIPRange(s) {
|
|
1462
|
-
const v = String(s ?? "").trim();
|
|
1463
|
-
if (v === "") return false;
|
|
1464
|
-
const parts = v.split("/");
|
|
1465
|
-
if (parts.length !== 2) return false;
|
|
1466
|
-
const [ip, prefixStr] = parts;
|
|
1467
|
-
if (!/^\d+$/.test(prefixStr)) return false;
|
|
1468
|
-
const prefix = Number(prefixStr);
|
|
1469
|
-
if (ip.includes(":")) {
|
|
1470
|
-
if (!isIPv6(ip)) return false;
|
|
1471
|
-
return prefix >= 0 && prefix <= 128;
|
|
1472
|
-
}
|
|
1473
|
-
if (!isIPv4(ip)) return false;
|
|
1474
|
-
return prefix >= 0 && prefix <= 32;
|
|
1475
|
-
}
|
|
1476
|
-
function isPortNumber(s) {
|
|
1477
|
-
const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
|
|
1478
|
-
return Number.isInteger(v) && v >= 0 && v <= 65535;
|
|
1479
|
-
}
|
|
1480
|
-
function isLatitude(s) {
|
|
1481
|
-
const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
|
|
1482
|
-
return Number.isFinite(v) && v >= -90 && v <= 90;
|
|
1483
|
-
}
|
|
1484
|
-
function isLongitude(s) {
|
|
1485
|
-
const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
|
|
1486
|
-
return Number.isFinite(v) && v >= -180 && v <= 180;
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
// src/web/network/request.ts
|
|
1490
|
-
var requestCache = /* @__PURE__ */ new Map();
|
|
1491
|
-
function request(config) {
|
|
1492
|
-
const controller = new AbortController();
|
|
1493
|
-
const signal = controller.signal;
|
|
1494
|
-
let chunkCallback = null;
|
|
1495
|
-
const task = {
|
|
1496
|
-
abort: () => controller.abort(),
|
|
1497
|
-
onChunkReceived: (cb) => {
|
|
1498
|
-
chunkCallback = cb;
|
|
1499
|
-
},
|
|
1500
|
-
offChunkReceived: () => {
|
|
1501
|
-
chunkCallback = null;
|
|
1502
|
-
}
|
|
1503
|
-
};
|
|
1504
|
-
const promise = new Promise((resolve, reject) => {
|
|
1505
|
-
const execute = async () => {
|
|
1506
|
-
const {
|
|
1507
|
-
url,
|
|
1508
|
-
data,
|
|
1509
|
-
header,
|
|
1510
|
-
method = "GET",
|
|
1511
|
-
resKey,
|
|
1512
|
-
msgKey,
|
|
1513
|
-
codeKey,
|
|
1514
|
-
successKey,
|
|
1515
|
-
successCode,
|
|
1516
|
-
reloginCode,
|
|
1517
|
-
showLoading = true,
|
|
1518
|
-
toastError = true,
|
|
1519
|
-
enableChunked = false,
|
|
1520
|
-
cacheTime,
|
|
1521
|
-
responseInterceptor,
|
|
1522
|
-
responseType = "json",
|
|
1523
|
-
timeout = 6e4
|
|
1524
|
-
} = config;
|
|
1525
|
-
const isGet = method === "GET";
|
|
1526
|
-
const isObjectData = (0, ts_exports.isPlainObject)(data);
|
|
1527
|
-
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1528
|
-
const fillData = isObjectData ? (0, ts_exports.pickBy)(data, (val) => val !== void 0) : data;
|
|
1529
|
-
const fillHeader = header ? (0, ts_exports.pickBy)(header, (val) => !!val) : {};
|
|
1530
|
-
if (!isGet && fillData && (isObjectData || isArrayData) && !fillHeader["Content-Type"]) {
|
|
1531
|
-
fillHeader["Content-Type"] = "application/json";
|
|
1532
|
-
}
|
|
1533
|
-
const fillUrl = isGet && isObjectData ? appendUrlParam(url, fillData) : url;
|
|
1534
|
-
const fillBody = !isGet && fillData ? isObjectData || isArrayData ? JSON.stringify(fillData) : fillData : void 0;
|
|
1535
|
-
const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
|
|
1536
|
-
const startTime = Date.now();
|
|
1537
|
-
const isCache = cacheTime && cacheTime > 0;
|
|
1538
|
-
const cacheKey = isCache ? JSON.stringify({ url: fillUrl, data: fillData }) : "";
|
|
1539
|
-
if (isCache) {
|
|
1540
|
-
const res = checkCache(cacheKey);
|
|
1541
|
-
if (res) {
|
|
1542
|
-
logRequestInfo({
|
|
1543
|
-
status: "success",
|
|
1544
|
-
config: logConfig,
|
|
1545
|
-
fromCache: true,
|
|
1546
|
-
startTime,
|
|
1547
|
-
res
|
|
1548
|
-
});
|
|
1549
|
-
resolve(getResult(res, resKey));
|
|
1550
|
-
return;
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
const appConfig2 = getAppConfig();
|
|
1554
|
-
if (showLoading) appConfig2.showLoading?.();
|
|
1555
|
-
let isTimeout = false;
|
|
1556
|
-
const timeoutId = setTimeout(() => {
|
|
1557
|
-
isTimeout = true;
|
|
1558
|
-
controller.abort();
|
|
1559
|
-
}, timeout);
|
|
1560
|
-
try {
|
|
1561
|
-
const response = await fetch(fillUrl, {
|
|
1562
|
-
method,
|
|
1563
|
-
headers: fillHeader,
|
|
1564
|
-
body: fillBody,
|
|
1565
|
-
signal
|
|
1566
|
-
});
|
|
1567
|
-
if (!response.ok) {
|
|
1568
|
-
if (showLoading) appConfig2.hideLoading?.();
|
|
1569
|
-
throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
|
|
1570
|
-
}
|
|
1571
|
-
if (enableChunked) {
|
|
1572
|
-
if (showLoading) appConfig2.hideLoading?.();
|
|
1573
|
-
const res2 = await handleStreamResponse(response, chunkCallback);
|
|
1574
|
-
logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
|
|
1575
|
-
resolve(res2);
|
|
1576
|
-
return;
|
|
1577
|
-
}
|
|
1578
|
-
const resData = await parseResponse(response, responseType);
|
|
1579
|
-
if (showLoading) appConfig2.hideLoading?.();
|
|
1580
|
-
const res = responseInterceptor ? responseInterceptor(resData) : resData;
|
|
1581
|
-
const code = getObjectValue(res, codeKey);
|
|
1582
|
-
const scode = successKey ? getObjectValue(res, successKey) : code;
|
|
1583
|
-
const msg = getObjectValue(res, msgKey);
|
|
1584
|
-
const isSuccess = successCode.includes(scode);
|
|
1585
|
-
const isRelogin = reloginCode.includes(code);
|
|
1586
|
-
logRequestInfo({ status: "success", config: logConfig, startTime, res });
|
|
1587
|
-
if (isSuccess) {
|
|
1588
|
-
if (isCache) requestCache.set(cacheKey, { res, expire: Date.now() + cacheTime });
|
|
1589
|
-
resolve(getResult(res, resKey));
|
|
1590
|
-
} else if (isRelogin) {
|
|
1591
|
-
reject(res);
|
|
1592
|
-
appConfig2.toLogin?.();
|
|
1593
|
-
} else {
|
|
1594
|
-
if (toastError && msg) appConfig2.toast?.({ status: "fail", msg });
|
|
1595
|
-
reject(res);
|
|
1596
|
-
}
|
|
1597
|
-
} catch (e) {
|
|
1598
|
-
const status = "fail";
|
|
1599
|
-
const isAbortError = e instanceof DOMException && e.name === "AbortError";
|
|
1600
|
-
if (isAbortError && isTimeout) {
|
|
1601
|
-
if (toastError) appConfig2.toast?.({ status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
|
|
1602
|
-
const timeoutError = new Error("Request Timeout");
|
|
1603
|
-
logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
|
|
1604
|
-
reject(timeoutError);
|
|
1605
|
-
return;
|
|
1606
|
-
}
|
|
1607
|
-
if (!isAbortError && toastError) appConfig2.toast?.({ status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
|
|
1608
|
-
logRequestInfo({ status, config: logConfig, startTime, e });
|
|
1609
|
-
reject(e);
|
|
1610
|
-
} finally {
|
|
1611
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
execute();
|
|
1615
|
-
});
|
|
1616
|
-
promise.task = task;
|
|
1617
|
-
return promise;
|
|
1618
|
-
}
|
|
1619
|
-
function logRequestInfo(options) {
|
|
1620
|
-
const { log } = getAppConfig();
|
|
1621
|
-
const { isLog = true } = options.config;
|
|
1622
|
-
if (!log || !isLog) return;
|
|
1623
|
-
const { config, res, fromCache = false, startTime, status, e } = options;
|
|
1624
|
-
const { url, data, header, method, extraLog } = config;
|
|
1625
|
-
const endTime = Date.now();
|
|
1626
|
-
const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
|
|
1627
|
-
const info = {
|
|
1628
|
-
name: "request",
|
|
1629
|
-
status,
|
|
1630
|
-
url,
|
|
1631
|
-
data,
|
|
1632
|
-
method,
|
|
1633
|
-
header,
|
|
1634
|
-
fromCache,
|
|
1635
|
-
startTime: toDayjs(startTime).format(fmt),
|
|
1636
|
-
endTime: toDayjs(endTime).format(fmt),
|
|
1637
|
-
duration: endTime - startTime,
|
|
1638
|
-
...extraLog
|
|
1639
|
-
};
|
|
1640
|
-
if (status === "success") {
|
|
1641
|
-
info.res = (0, ts_exports.cloneDeep)(res);
|
|
1642
|
-
log("info", info);
|
|
1643
|
-
} else {
|
|
1644
|
-
info.e = e;
|
|
1645
|
-
log("error", info);
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
function getResult(res, resKey) {
|
|
1649
|
-
if (!res || !resKey || typeof res !== "object") return res;
|
|
1650
|
-
return getObjectValue(res, resKey);
|
|
1651
|
-
}
|
|
1652
|
-
function checkCache(cacheKey) {
|
|
1653
|
-
const cached = requestCache.get(cacheKey);
|
|
1654
|
-
if (!cached) return null;
|
|
1655
|
-
if (cached.expire <= Date.now()) {
|
|
1656
|
-
requestCache.delete(cacheKey);
|
|
1657
|
-
return null;
|
|
1658
|
-
}
|
|
1659
|
-
return cached.res;
|
|
1660
|
-
}
|
|
1661
|
-
async function handleStreamResponse(response, chunkCallback) {
|
|
1662
|
-
if (!response.body) throw new Error("Response body is null");
|
|
1663
|
-
const reader = response.body.getReader();
|
|
1664
|
-
while (true) {
|
|
1665
|
-
const { done, value } = await reader.read();
|
|
1666
|
-
if (done) break;
|
|
1667
|
-
if (chunkCallback && value) {
|
|
1668
|
-
chunkCallback({ data: value.buffer });
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
return "Stream Finished";
|
|
1672
|
-
}
|
|
1673
|
-
async function parseResponse(response, responseType) {
|
|
1674
|
-
let resData;
|
|
1675
|
-
if (responseType === "arraybuffer") {
|
|
1676
|
-
resData = await response.arrayBuffer();
|
|
1677
|
-
} else if (responseType === "text") {
|
|
1678
|
-
resData = await response.text();
|
|
1679
|
-
} else {
|
|
1680
|
-
const text = await response.text();
|
|
1681
|
-
try {
|
|
1682
|
-
resData = JSON.parse(text);
|
|
1683
|
-
} catch {
|
|
1684
|
-
resData = text;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
return resData;
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
475
|
// src/web/storage/index.ts
|
|
1691
476
|
var WK = {
|
|
1692
477
|
val: "__l_val",
|
|
@@ -1762,7 +547,6 @@ export {
|
|
|
1762
547
|
copyText,
|
|
1763
548
|
copyUrl,
|
|
1764
549
|
download,
|
|
1765
|
-
getAppConfig,
|
|
1766
550
|
getBrowserName,
|
|
1767
551
|
getBrowserVersion,
|
|
1768
552
|
getCookie,
|
|
@@ -1796,8 +580,6 @@ export {
|
|
|
1796
580
|
preloadImage,
|
|
1797
581
|
removeCookie,
|
|
1798
582
|
removeLocalStorage,
|
|
1799
|
-
request,
|
|
1800
|
-
setBaseToolsConfig,
|
|
1801
583
|
setCookie,
|
|
1802
584
|
setLocalStorage,
|
|
1803
585
|
unlockBodyScroll,
|