@base-web-kits/base-tools-web 1.1.18-alpha.1 → 1.2.0
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/async/index.d.ts +4 -0
- package/dist/async/index.d.ts.map +1 -1
- package/dist/base-tools-web.umd.global.js +64 -52
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +53 -976
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +237 -991
- package/dist/index.js.map +1 -1
- package/dist/network/request.d.ts +33 -28
- package/dist/network/request.d.ts.map +1 -1
- package/dist/storage/index.d.ts +1 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/web/async/index.ts +30 -4
- package/src/web/network/request.ts +70 -61
- package/src/web/storage/index.ts +1 -3
package/dist/async/index.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export type WebApiConfig<Res = any, Err = any> = {
|
|
|
11
11
|
toastError?: ((e: Err) => boolean | string) | boolean | string;
|
|
12
12
|
/** 是否显示日志, 默认 true */
|
|
13
13
|
showLog?: boolean;
|
|
14
|
+
/** 成功响应数据的处理, 如解密操作 (返回值在成功日志中输出'resMap'字段) */
|
|
15
|
+
resMap?: (res: any) => Res;
|
|
16
|
+
/** 成功和失败时,额外输出的日志数据 (可覆盖内部log参数,如'name') */
|
|
17
|
+
logExtra?: Record<string, unknown>;
|
|
14
18
|
};
|
|
15
19
|
/**
|
|
16
20
|
* 拓展 web api, 使其支持loading,toast,log能力
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/async/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/async/index.ts"],"names":[],"mappings":"AAIA,KAAK,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,CACnD,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,KACZ,OAAO,CAAC,GAAG,CAAC,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI;IAC/C,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAE/B,0BAA0B;IAC1B,YAAY,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,KAAK,GAAG,MAAM,CAAC,GAAG,KAAK,GAAG,MAAM,CAAC;IAE/D,wGAAwG;IACxG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,GAAG,MAAM,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC;IAE/D,sBAAsB;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,CAAC;IAE3B,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,EACnC,OAAO,CAAC,EAAE,MAAM,IAER,QAAQ,MAAM,EAAE,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM,kBAiEjE"}
|
|
@@ -1002,10 +1002,10 @@ var baseToolsWeb = (() => {
|
|
|
1002
1002
|
div.innerHTML = html;
|
|
1003
1003
|
document.body.appendChild(div);
|
|
1004
1004
|
const selection = window.getSelection();
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1005
|
+
const range2 = document.createRange();
|
|
1006
|
+
range2.selectNodeContents(div);
|
|
1007
1007
|
selection == null ? void 0 : selection.removeAllRanges();
|
|
1008
|
-
selection == null ? void 0 : selection.addRange(
|
|
1008
|
+
selection == null ? void 0 : selection.addRange(range2);
|
|
1009
1009
|
const ok = document.execCommand("copy");
|
|
1010
1010
|
document.body.removeChild(div);
|
|
1011
1011
|
selection == null ? void 0 : selection.removeAllRanges();
|
|
@@ -1349,22 +1349,22 @@ var baseToolsWeb = (() => {
|
|
|
1349
1349
|
return (0, import_dayjs.default)(t, fmt);
|
|
1350
1350
|
}
|
|
1351
1351
|
|
|
1352
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1352
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
|
|
1353
1353
|
function isPrimitive(value) {
|
|
1354
1354
|
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
1355
1355
|
}
|
|
1356
1356
|
|
|
1357
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1357
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
|
|
1358
1358
|
function isTypedArray(x) {
|
|
1359
1359
|
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
1360
1360
|
}
|
|
1361
1361
|
|
|
1362
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1362
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
|
|
1363
1363
|
function getSymbols(object) {
|
|
1364
1364
|
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
1365
1365
|
}
|
|
1366
1366
|
|
|
1367
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1367
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
|
|
1368
1368
|
function getTag(value) {
|
|
1369
1369
|
if (value == null) {
|
|
1370
1370
|
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
@@ -1372,7 +1372,7 @@ var baseToolsWeb = (() => {
|
|
|
1372
1372
|
return Object.prototype.toString.call(value);
|
|
1373
1373
|
}
|
|
1374
1374
|
|
|
1375
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1375
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/_internal/tags.mjs
|
|
1376
1376
|
var regexpTag = "[object RegExp]";
|
|
1377
1377
|
var stringTag = "[object String]";
|
|
1378
1378
|
var numberTag = "[object Number]";
|
|
@@ -1396,7 +1396,7 @@ var baseToolsWeb = (() => {
|
|
|
1396
1396
|
var float32ArrayTag = "[object Float32Array]";
|
|
1397
1397
|
var float64ArrayTag = "[object Float64Array]";
|
|
1398
1398
|
|
|
1399
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1399
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/object/cloneDeepWith.mjs
|
|
1400
1400
|
function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @__PURE__ */ new Map(), cloneValue = void 0) {
|
|
1401
1401
|
const cloned = cloneValue == null ? void 0 : cloneValue(valueToClone, keyToClone, objectToClone, stack);
|
|
1402
1402
|
if (cloned !== void 0) {
|
|
@@ -1558,12 +1558,12 @@ var baseToolsWeb = (() => {
|
|
|
1558
1558
|
}
|
|
1559
1559
|
}
|
|
1560
1560
|
|
|
1561
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1561
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/object/cloneDeep.mjs
|
|
1562
1562
|
function cloneDeep(obj) {
|
|
1563
1563
|
return cloneDeepWithImpl(obj, void 0, obj, /* @__PURE__ */ new Map(), void 0);
|
|
1564
1564
|
}
|
|
1565
1565
|
|
|
1566
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1566
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
|
|
1567
1567
|
function isPlainObject(value) {
|
|
1568
1568
|
if (!value || typeof value !== "object") {
|
|
1569
1569
|
return false;
|
|
@@ -1576,12 +1576,12 @@ var baseToolsWeb = (() => {
|
|
|
1576
1576
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
1577
1577
|
}
|
|
1578
1578
|
|
|
1579
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1579
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
|
|
1580
1580
|
function isUnsafeProperty(key) {
|
|
1581
1581
|
return key === "__proto__";
|
|
1582
1582
|
}
|
|
1583
1583
|
|
|
1584
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1584
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/_internal/isDeepKey.mjs
|
|
1585
1585
|
function isDeepKey(key) {
|
|
1586
1586
|
switch (typeof key) {
|
|
1587
1587
|
case "number":
|
|
@@ -1594,7 +1594,7 @@ var baseToolsWeb = (() => {
|
|
|
1594
1594
|
}
|
|
1595
1595
|
}
|
|
1596
1596
|
|
|
1597
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1597
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/_internal/toKey.mjs
|
|
1598
1598
|
function toKey(value) {
|
|
1599
1599
|
var _a;
|
|
1600
1600
|
if (typeof value === "string" || typeof value === "symbol") {
|
|
@@ -1606,7 +1606,7 @@ var baseToolsWeb = (() => {
|
|
|
1606
1606
|
return String(value);
|
|
1607
1607
|
}
|
|
1608
1608
|
|
|
1609
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1609
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/util/toString.mjs
|
|
1610
1610
|
function toString(value) {
|
|
1611
1611
|
if (value == null) {
|
|
1612
1612
|
return "";
|
|
@@ -1624,7 +1624,7 @@ var baseToolsWeb = (() => {
|
|
|
1624
1624
|
return result;
|
|
1625
1625
|
}
|
|
1626
1626
|
|
|
1627
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1627
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/util/toPath.mjs
|
|
1628
1628
|
function toPath(deepKey) {
|
|
1629
1629
|
if (Array.isArray(deepKey)) {
|
|
1630
1630
|
return deepKey.map(toKey);
|
|
@@ -1691,7 +1691,7 @@ var baseToolsWeb = (() => {
|
|
|
1691
1691
|
return result;
|
|
1692
1692
|
}
|
|
1693
1693
|
|
|
1694
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
1694
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/object/get.mjs
|
|
1695
1695
|
function get(object, path, defaultValue) {
|
|
1696
1696
|
if (object == null) {
|
|
1697
1697
|
return defaultValue;
|
|
@@ -1787,6 +1787,26 @@ var baseToolsWeb = (() => {
|
|
|
1787
1787
|
// src/web/network/request.ts
|
|
1788
1788
|
var requestCache = /* @__PURE__ */ new Map();
|
|
1789
1789
|
function request(config) {
|
|
1790
|
+
const {
|
|
1791
|
+
url,
|
|
1792
|
+
data,
|
|
1793
|
+
header,
|
|
1794
|
+
method = "GET",
|
|
1795
|
+
resKey,
|
|
1796
|
+
msgKey,
|
|
1797
|
+
codeKey,
|
|
1798
|
+
successKey,
|
|
1799
|
+
successCode,
|
|
1800
|
+
reloginCode,
|
|
1801
|
+
showLoading = true,
|
|
1802
|
+
toastError = true,
|
|
1803
|
+
enableChunked = false,
|
|
1804
|
+
cacheTime,
|
|
1805
|
+
resMap,
|
|
1806
|
+
responseType = "json",
|
|
1807
|
+
timeout: timeout2 = 6e4,
|
|
1808
|
+
onTaskReady
|
|
1809
|
+
} = config;
|
|
1790
1810
|
const controller = new AbortController();
|
|
1791
1811
|
const signal = controller.signal;
|
|
1792
1812
|
let chunkCallback = null;
|
|
@@ -1799,28 +1819,10 @@ var baseToolsWeb = (() => {
|
|
|
1799
1819
|
chunkCallback = null;
|
|
1800
1820
|
}
|
|
1801
1821
|
};
|
|
1802
|
-
|
|
1822
|
+
onTaskReady == null ? void 0 : onTaskReady(task);
|
|
1823
|
+
return new Promise((resolve, reject) => {
|
|
1803
1824
|
const execute = () => __async(null, null, function* () {
|
|
1804
1825
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1805
|
-
const {
|
|
1806
|
-
url,
|
|
1807
|
-
data,
|
|
1808
|
-
header,
|
|
1809
|
-
method = "GET",
|
|
1810
|
-
resKey,
|
|
1811
|
-
msgKey,
|
|
1812
|
-
codeKey,
|
|
1813
|
-
successKey,
|
|
1814
|
-
successCode,
|
|
1815
|
-
reloginCode,
|
|
1816
|
-
showLoading = true,
|
|
1817
|
-
toastError = true,
|
|
1818
|
-
enableChunked = false,
|
|
1819
|
-
cacheTime,
|
|
1820
|
-
responseInterceptor,
|
|
1821
|
-
responseType = "json",
|
|
1822
|
-
timeout = 6e4
|
|
1823
|
-
} = config;
|
|
1824
1826
|
const isGet = method === "GET";
|
|
1825
1827
|
const isObjectData = isPlainObject(data);
|
|
1826
1828
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
@@ -1872,7 +1874,7 @@ var baseToolsWeb = (() => {
|
|
|
1872
1874
|
const timeoutId = setTimeout(() => {
|
|
1873
1875
|
isTimeout = true;
|
|
1874
1876
|
controller.abort();
|
|
1875
|
-
},
|
|
1877
|
+
}, timeout2);
|
|
1876
1878
|
try {
|
|
1877
1879
|
const response = yield fetch(fillUrl, {
|
|
1878
1880
|
method,
|
|
@@ -1893,7 +1895,7 @@ var baseToolsWeb = (() => {
|
|
|
1893
1895
|
}
|
|
1894
1896
|
const resData = yield parseResponse(response, responseType);
|
|
1895
1897
|
if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
|
|
1896
|
-
const res =
|
|
1898
|
+
const res = resMap ? resMap(resData) : resData;
|
|
1897
1899
|
const code = getObjectValue(res, codeKey);
|
|
1898
1900
|
const scode = successKey ? getObjectValue(res, successKey) : code;
|
|
1899
1901
|
const msg = getObjectValue(res, msgKey);
|
|
@@ -1929,8 +1931,6 @@ var baseToolsWeb = (() => {
|
|
|
1929
1931
|
});
|
|
1930
1932
|
execute();
|
|
1931
1933
|
});
|
|
1932
|
-
promise.task = task;
|
|
1933
|
-
return promise;
|
|
1934
1934
|
}
|
|
1935
1935
|
function filterRequestData(data) {
|
|
1936
1936
|
const res = {};
|
|
@@ -1950,10 +1950,10 @@ var baseToolsWeb = (() => {
|
|
|
1950
1950
|
}
|
|
1951
1951
|
function logRequestInfo(options) {
|
|
1952
1952
|
const { log } = getBaseToolsConfig();
|
|
1953
|
-
const {
|
|
1954
|
-
if (!log || !
|
|
1953
|
+
const { showLog = true } = options.config;
|
|
1954
|
+
if (!log || !showLog) return;
|
|
1955
1955
|
const { config, res, fromCache = false, startTime, status, e } = options;
|
|
1956
|
-
const { url, data, header, method,
|
|
1956
|
+
const { url, data, header, method, logExtra } = config;
|
|
1957
1957
|
const endTime = Date.now();
|
|
1958
1958
|
const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
|
|
1959
1959
|
const info = __spreadValues({
|
|
@@ -1967,7 +1967,7 @@ var baseToolsWeb = (() => {
|
|
|
1967
1967
|
startTime: toDayjs(startTime).format(fmt),
|
|
1968
1968
|
endTime: toDayjs(endTime).format(fmt),
|
|
1969
1969
|
duration: endTime - startTime
|
|
1970
|
-
},
|
|
1970
|
+
}, logExtra);
|
|
1971
1971
|
if (status === "success") {
|
|
1972
1972
|
info.res = cloneDeep(res);
|
|
1973
1973
|
log("info", info);
|
|
@@ -2064,7 +2064,9 @@ var baseToolsWeb = (() => {
|
|
|
2064
2064
|
showLoading = false,
|
|
2065
2065
|
toastSuccess = false,
|
|
2066
2066
|
toastError = true,
|
|
2067
|
-
showLog = true
|
|
2067
|
+
showLog = true,
|
|
2068
|
+
resMap,
|
|
2069
|
+
logExtra
|
|
2068
2070
|
} = finalConfig;
|
|
2069
2071
|
const {
|
|
2070
2072
|
log,
|
|
@@ -2080,13 +2082,23 @@ var baseToolsWeb = (() => {
|
|
|
2080
2082
|
return new Promise((resolve, reject) => {
|
|
2081
2083
|
webApi(option, finalConfig).then((res) => {
|
|
2082
2084
|
if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2085
|
+
const finalRes = resMap ? resMap(res) : res;
|
|
2086
|
+
if (showLog) {
|
|
2087
|
+
const logData = __spreadValues({ name: fname, status: "success", option }, logExtra);
|
|
2088
|
+
if (resMap) {
|
|
2089
|
+
logData.res = res;
|
|
2090
|
+
logData.resMap = cloneDeep(finalRes);
|
|
2091
|
+
} else {
|
|
2092
|
+
logData.res = cloneDeep(res);
|
|
2093
|
+
}
|
|
2094
|
+
log == null ? void 0 : log("info", logData);
|
|
2095
|
+
}
|
|
2096
|
+
resolve(finalRes);
|
|
2097
|
+
const msg = typeof toastSuccess === "function" ? toastSuccess(finalRes) : toastSuccess;
|
|
2086
2098
|
if (msg) toast == null ? void 0 : toast({ msg, status: "success" });
|
|
2087
2099
|
}).catch((e) => {
|
|
2088
2100
|
if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
|
|
2089
|
-
if (showLog) log == null ? void 0 : log("error", { name: fname, status: "fail", option, e });
|
|
2101
|
+
if (showLog) log == null ? void 0 : log("error", __spreadValues({ name: fname, status: "fail", option, e }, logExtra));
|
|
2090
2102
|
const msg = typeof toastError === "function" ? toastError(e) : toastError;
|
|
2091
2103
|
if (msg) {
|
|
2092
2104
|
toast == null ? void 0 : toast({
|
|
@@ -2105,7 +2117,7 @@ var baseToolsWeb = (() => {
|
|
|
2105
2117
|
return new Promise((resolve, reject) => {
|
|
2106
2118
|
var _a;
|
|
2107
2119
|
const xhr = new XMLHttpRequest();
|
|
2108
|
-
const { url, file, name = "file", header, formData, timeout = 0 } = option;
|
|
2120
|
+
const { url, file, name = "file", header, formData, timeout: timeout2 = 0 } = option;
|
|
2109
2121
|
const fail = (error) => reject(error);
|
|
2110
2122
|
const success = (responseText) => {
|
|
2111
2123
|
try {
|
|
@@ -2147,7 +2159,7 @@ var baseToolsWeb = (() => {
|
|
|
2147
2159
|
if (v !== void 0 && v !== null && v !== "") xhr.setRequestHeader(k, String(v));
|
|
2148
2160
|
});
|
|
2149
2161
|
}
|
|
2150
|
-
xhr.timeout =
|
|
2162
|
+
xhr.timeout = timeout2;
|
|
2151
2163
|
const data = new FormData();
|
|
2152
2164
|
data.append(name, file);
|
|
2153
2165
|
if (formData) {
|