@base-web-kits/base-tools-web 1.2.0-alpha.0 → 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.
@@ -11,8 +11,8 @@ export type WebApiConfig<Res = any, Err = any> = {
11
11
  toastError?: ((e: Err) => boolean | string) | boolean | string;
12
12
  /** 是否显示日志, 默认 true */
13
13
  showLog?: boolean;
14
- /** 处理成功res, 如解密操作 (返回值在成功日志中输出'resFilter'字段) */
15
- resFilter?: (res: Res) => Res;
14
+ /** 成功响应数据的处理, 如解密操作 (返回值在成功日志中输出'resMap'字段) */
15
+ resMap?: (res: any) => Res;
16
16
  /** 成功和失败时,额外输出的日志数据 (可覆盖内部log参数,如'name') */
17
17
  logExtra?: Record<string, unknown>;
18
18
  };
@@ -1 +1 @@
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;I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A+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 range = document.createRange();
1006
- range.selectNodeContents(div);
1005
+ const range2 = document.createRange();
1006
+ range2.selectNodeContents(div);
1007
1007
  selection == null ? void 0 : selection.removeAllRanges();
1008
- selection == null ? void 0 : selection.addRange(range);
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.42.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
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.42.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
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.42.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
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.42.0/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
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.42.0/node_modules/es-toolkit/dist/compat/_internal/tags.mjs
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.42.0/node_modules/es-toolkit/dist/object/cloneDeepWith.mjs
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.42.0/node_modules/es-toolkit/dist/object/cloneDeep.mjs
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.42.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
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.42.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
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.42.0/node_modules/es-toolkit/dist/compat/_internal/isDeepKey.mjs
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.42.0/node_modules/es-toolkit/dist/compat/_internal/toKey.mjs
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.42.0/node_modules/es-toolkit/dist/compat/util/toString.mjs
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.42.0/node_modules/es-toolkit/dist/compat/util/toPath.mjs
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.42.0/node_modules/es-toolkit/dist/compat/object/get.mjs
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
- const promise = new Promise((resolve, reject) => {
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
- }, timeout);
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 = responseInterceptor ? responseInterceptor(resData) : resData;
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,8 +1950,8 @@ var baseToolsWeb = (() => {
1950
1950
  }
1951
1951
  function logRequestInfo(options) {
1952
1952
  const { log } = getBaseToolsConfig();
1953
- const { isLog = true } = options.config;
1954
- if (!log || !isLog) return;
1953
+ const { showLog = true } = options.config;
1954
+ if (!log || !showLog) return;
1955
1955
  const { config, res, fromCache = false, startTime, status, e } = options;
1956
1956
  const { url, data, header, method, logExtra } = config;
1957
1957
  const endTime = Date.now();
@@ -2065,7 +2065,7 @@ var baseToolsWeb = (() => {
2065
2065
  toastSuccess = false,
2066
2066
  toastError = true,
2067
2067
  showLog = true,
2068
- resFilter,
2068
+ resMap,
2069
2069
  logExtra
2070
2070
  } = finalConfig;
2071
2071
  const {
@@ -2082,12 +2082,12 @@ var baseToolsWeb = (() => {
2082
2082
  return new Promise((resolve, reject) => {
2083
2083
  webApi(option, finalConfig).then((res) => {
2084
2084
  if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
2085
- const finalRes = resFilter ? resFilter(res) : res;
2085
+ const finalRes = resMap ? resMap(res) : res;
2086
2086
  if (showLog) {
2087
2087
  const logData = __spreadValues({ name: fname, status: "success", option }, logExtra);
2088
- if (resFilter) {
2088
+ if (resMap) {
2089
2089
  logData.res = res;
2090
- logData.resFilter = cloneDeep(finalRes);
2090
+ logData.resMap = cloneDeep(finalRes);
2091
2091
  } else {
2092
2092
  logData.res = cloneDeep(res);
2093
2093
  }
@@ -2117,7 +2117,7 @@ var baseToolsWeb = (() => {
2117
2117
  return new Promise((resolve, reject) => {
2118
2118
  var _a;
2119
2119
  const xhr = new XMLHttpRequest();
2120
- const { url, file, name = "file", header, formData, timeout = 0 } = option;
2120
+ const { url, file, name = "file", header, formData, timeout: timeout2 = 0 } = option;
2121
2121
  const fail = (error) => reject(error);
2122
2122
  const success = (responseText) => {
2123
2123
  try {
@@ -2159,7 +2159,7 @@ var baseToolsWeb = (() => {
2159
2159
  if (v !== void 0 && v !== null && v !== "") xhr.setRequestHeader(k, String(v));
2160
2160
  });
2161
2161
  }
2162
- xhr.timeout = timeout;
2162
+ xhr.timeout = timeout2;
2163
2163
  const data = new FormData();
2164
2164
  data.append(name, file);
2165
2165
  if (formData) {