@whitesev/utils 2.4.1 → 2.4.3

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.
@@ -1540,7 +1540,7 @@ System.register('Utils', [], (function (exports) {
1540
1540
  * @param details 当前的请求配置
1541
1541
  * @private
1542
1542
  */
1543
- beforeRequestCallBack(details) {
1543
+ async beforeRequestCallBack(details) {
1544
1544
  if (typeof details.allowInterceptConfig === "boolean") {
1545
1545
  if (!details.allowInterceptConfig) {
1546
1546
  // 不允许拦截
@@ -1561,7 +1561,7 @@ System.register('Utils', [], (function (exports) {
1561
1561
  for (let index = 0; index < this.$config.configList.length; index++) {
1562
1562
  let item = this.$config.configList[index];
1563
1563
  if (typeof item.fn === "function") {
1564
- let result = item.fn(details);
1564
+ let result = await item.fn(details);
1565
1565
  if (result == null) {
1566
1566
  return;
1567
1567
  }
@@ -1618,7 +1618,7 @@ System.register('Utils', [], (function (exports) {
1618
1618
  * @param response 响应
1619
1619
  * @param details 请求的配置
1620
1620
  */
1621
- successResponseCallBack(response, details) {
1621
+ async successResponseCallBack(response, details) {
1622
1622
  if (typeof details.allowInterceptConfig === "boolean") {
1623
1623
  if (!details.allowInterceptConfig) {
1624
1624
  // 不允许拦截
@@ -1640,7 +1640,8 @@ System.register('Utils', [], (function (exports) {
1640
1640
  for (let index = 0; index < this.$config.configList.length; index++) {
1641
1641
  let item = this.$config.configList[index];
1642
1642
  if (typeof item.successFn === "function") {
1643
- if (item.successFn(response, details) == null) {
1643
+ let result = await item.successFn(response, details);
1644
+ if (result == null) {
1644
1645
  return;
1645
1646
  }
1646
1647
  }
@@ -1653,7 +1654,7 @@ System.register('Utils', [], (function (exports) {
1653
1654
  * @returns
1654
1655
  * 返回null|undefined就是拦截掉了
1655
1656
  */
1656
- errorResponseCallBack(data) {
1657
+ async errorResponseCallBack(data) {
1657
1658
  if (typeof data.details.allowInterceptConfig === "boolean") {
1658
1659
  if (!data.details.allowInterceptConfig) {
1659
1660
  // 不允许拦截
@@ -1675,7 +1676,8 @@ System.register('Utils', [], (function (exports) {
1675
1676
  for (let index = 0; index < this.$config.configList.length; index++) {
1676
1677
  let item = this.$config.configList[index];
1677
1678
  if (typeof item.errorFn === "function") {
1678
- if (item.errorFn(data) == null) {
1679
+ let result = await item.errorFn(data);
1680
+ if (result == null) {
1679
1681
  return;
1680
1682
  }
1681
1683
  }
@@ -1715,7 +1717,7 @@ System.register('Utils', [], (function (exports) {
1715
1717
  this.$config.configList = [];
1716
1718
  },
1717
1719
  };
1718
- HttpxRequestDetails = {
1720
+ HttpxRequestOption = {
1719
1721
  context: this,
1720
1722
  /**
1721
1723
  * 根据传入的参数处理获取details配置
@@ -2063,7 +2065,7 @@ System.register('Utils', [], (function (exports) {
2063
2065
  * @param reject 抛出错误
2064
2066
  * @param argsResult 返回的参数列表
2065
2067
  */
2066
- onAbort(details, resolve, reject, argsResult) {
2068
+ async onAbort(details, resolve, reject, argsResult) {
2067
2069
  // console.log(argsResult);
2068
2070
  if ("onabort" in details) {
2069
2071
  details.onabort.apply(this, argsResult);
@@ -2075,12 +2077,12 @@ System.register('Utils', [], (function (exports) {
2075
2077
  if (response.length) {
2076
2078
  response = response[0];
2077
2079
  }
2078
- if (this.context.HttpxResponseHook.errorResponseCallBack({
2080
+ if ((await this.context.HttpxResponseHook.errorResponseCallBack({
2079
2081
  type: "onabort",
2080
2082
  error: new TypeError("request canceled"),
2081
2083
  response: null,
2082
2084
  details: details,
2083
- }) == null) {
2085
+ })) == null) {
2084
2086
  // reject(new TypeError("response is intercept with onabort"));
2085
2087
  return;
2086
2088
  }
@@ -2100,7 +2102,7 @@ System.register('Utils', [], (function (exports) {
2100
2102
  * @param reject 抛出错误
2101
2103
  * @param argsResult 返回的参数列表
2102
2104
  */
2103
- onError(details, resolve, reject, argsResult) {
2105
+ async onError(details, resolve, reject, argsResult) {
2104
2106
  // console.log(argsResult);
2105
2107
  if ("onerror" in details) {
2106
2108
  details.onerror.apply(this, argsResult);
@@ -2112,12 +2114,12 @@ System.register('Utils', [], (function (exports) {
2112
2114
  if (response.length) {
2113
2115
  response = response[0];
2114
2116
  }
2115
- if (this.context.HttpxResponseHook.errorResponseCallBack({
2117
+ if ((await this.context.HttpxResponseHook.errorResponseCallBack({
2116
2118
  type: "onerror",
2117
2119
  error: new TypeError("request error"),
2118
2120
  response: response,
2119
2121
  details: details,
2120
- }) == null) {
2122
+ })) == null) {
2121
2123
  // reject(new TypeError("response is intercept with onerror"));
2122
2124
  return;
2123
2125
  }
@@ -2137,7 +2139,7 @@ System.register('Utils', [], (function (exports) {
2137
2139
  * @param reject 抛出错误
2138
2140
  * @param argsResult 返回的参数列表
2139
2141
  */
2140
- onTimeout(details, resolve, reject, argsResult) {
2142
+ async onTimeout(details, resolve, reject, argsResult) {
2141
2143
  // console.log(argsResult);
2142
2144
  if ("ontimeout" in details) {
2143
2145
  details.ontimeout.apply(this, argsResult);
@@ -2149,12 +2151,12 @@ System.register('Utils', [], (function (exports) {
2149
2151
  if (response.length) {
2150
2152
  response = response[0];
2151
2153
  }
2152
- if (this.context.HttpxResponseHook.errorResponseCallBack({
2154
+ if ((await this.context.HttpxResponseHook.errorResponseCallBack({
2153
2155
  type: "ontimeout",
2154
2156
  error: new TypeError("request timeout"),
2155
2157
  response: (argsResult || [null])[0],
2156
2158
  details: details,
2157
- }) == null) {
2159
+ })) == null) {
2158
2160
  // reject(new TypeError("response is intercept with ontimeout"));
2159
2161
  return;
2160
2162
  }
@@ -2188,7 +2190,7 @@ System.register('Utils', [], (function (exports) {
2188
2190
  * @param reject 抛出错误
2189
2191
  * @param argsResult 返回的参数列表
2190
2192
  */
2191
- onLoad(details, resolve, reject, argsResult) {
2193
+ async onLoad(details, resolve, reject, argsResult) {
2192
2194
  // console.log(argsResult);
2193
2195
  /* X浏览器会因为设置了responseType导致不返回responseText */
2194
2196
  let originResponse = argsResult[0];
@@ -2259,7 +2261,7 @@ System.register('Utils', [], (function (exports) {
2259
2261
  }
2260
2262
  /* 状态码2xx都是成功的 */
2261
2263
  if (Math.floor(originResponse.status / 100) === 2) {
2262
- if (this.context.HttpxResponseHook.successResponseCallBack(originResponse, details) == null) {
2264
+ if ((await this.context.HttpxResponseHook.successResponseCallBack(originResponse, details)) == null) {
2263
2265
  // reject(new TypeError("response is intercept with onloada"));
2264
2266
  return;
2265
2267
  }
@@ -2311,20 +2313,20 @@ System.register('Utils', [], (function (exports) {
2311
2313
  * 发送请求
2312
2314
  * @param details
2313
2315
  */
2314
- request(details) {
2316
+ async request(details) {
2315
2317
  if (this.context.#LOG_DETAILS) {
2316
2318
  console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
2317
2319
  }
2318
2320
  if (typeof this.context.HttpxRequestHook.beforeRequestCallBack ===
2319
2321
  "function") {
2320
- let hookResult = this.context.HttpxRequestHook.beforeRequestCallBack(details);
2322
+ let hookResult = await this.context.HttpxRequestHook.beforeRequestCallBack(details);
2321
2323
  if (hookResult == null) {
2322
2324
  return;
2323
2325
  }
2324
2326
  }
2325
2327
  if (details.fetch) {
2326
2328
  // 使用fetch请求
2327
- const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestDetails.handleFetchOption(details);
2329
+ const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestOption.handleFetchOption(details);
2328
2330
  return this.fetch(fetchOption, fetchRequestOption, abortController);
2329
2331
  }
2330
2332
  else {
@@ -2612,15 +2614,15 @@ System.register('Utils', [], (function (exports) {
2612
2614
  * @param url 网址
2613
2615
  * @param details 配置
2614
2616
  */
2615
- async get(...args // @ts-ignore
2617
+ get(...args // @ts-ignore
2616
2618
  ) {
2617
- let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2619
+ let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
2618
2620
  let abortFn = null;
2619
- let promise = new globalThis.Promise((resolve, reject) => {
2620
- let requestOption = this.HttpxRequestDetails.getRequestOption("GET", userRequestOption, resolve, reject);
2621
+ let promise = new globalThis.Promise(async (resolve, reject) => {
2622
+ let requestOption = this.HttpxRequestOption.getRequestOption("GET", userRequestOption, resolve, reject);
2621
2623
  Reflect.deleteProperty(requestOption, "onprogress");
2622
- this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2623
- const requestResult = this.HttpxRequest.request(requestOption);
2624
+ this.HttpxRequestOption.removeRequestNullOption(requestOption);
2625
+ const requestResult = await this.HttpxRequest.request(requestOption);
2624
2626
  if (requestResult != null &&
2625
2627
  typeof requestResult.abort === "function") {
2626
2628
  abortFn = requestResult.abort;
@@ -2632,21 +2634,22 @@ System.register('Utils', [], (function (exports) {
2632
2634
  abortFn();
2633
2635
  }
2634
2636
  };
2637
+ // @ts-ignore
2635
2638
  return promise;
2636
2639
  }
2637
2640
  /**
2638
2641
  * POST 请求
2639
2642
  */
2640
- async post(...args // @ts-ignore
2643
+ post(...args // @ts-ignore
2641
2644
  ) {
2642
- let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2645
+ let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
2643
2646
  let abortFn = null;
2644
- let promise = new Promise((resolve, reject) => {
2645
- let requestOption = this.HttpxRequestDetails.getRequestOption("POST", userRequestOption, resolve, reject);
2647
+ let promise = new Promise(async (resolve, reject) => {
2648
+ let requestOption = this.HttpxRequestOption.getRequestOption("POST", userRequestOption, resolve, reject);
2646
2649
  // @ts-ignore
2647
2650
  requestOption =
2648
- this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2649
- const requestResult = this.HttpxRequest.request(requestOption);
2651
+ this.HttpxRequestOption.removeRequestNullOption(requestOption);
2652
+ const requestResult = await this.HttpxRequest.request(requestOption);
2650
2653
  if (requestResult != null &&
2651
2654
  typeof requestResult.abort === "function") {
2652
2655
  abortFn = requestResult.abort;
@@ -2658,22 +2661,23 @@ System.register('Utils', [], (function (exports) {
2658
2661
  abortFn();
2659
2662
  }
2660
2663
  };
2664
+ // @ts-ignore
2661
2665
  return promise;
2662
2666
  }
2663
2667
  /**
2664
2668
  * HEAD 请求
2665
2669
  */
2666
- async head(...args // @ts-ignore
2670
+ head(...args // @ts-ignore
2667
2671
  ) {
2668
- let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2672
+ let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
2669
2673
  let abortFn = null;
2670
- let promise = new Promise((resolve, reject) => {
2671
- let requestOption = this.HttpxRequestDetails.getRequestOption("HEAD", userRequestOption, resolve, reject);
2674
+ let promise = new Promise(async (resolve, reject) => {
2675
+ let requestOption = this.HttpxRequestOption.getRequestOption("HEAD", userRequestOption, resolve, reject);
2672
2676
  Reflect.deleteProperty(requestOption, "onprogress");
2673
2677
  // @ts-ignore
2674
2678
  requestOption =
2675
- this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2676
- const requestResult = this.HttpxRequest.request(requestOption);
2679
+ this.HttpxRequestOption.removeRequestNullOption(requestOption);
2680
+ const requestResult = await this.HttpxRequest.request(requestOption);
2677
2681
  if (requestResult != null &&
2678
2682
  typeof requestResult.abort === "function") {
2679
2683
  abortFn = requestResult.abort;
@@ -2685,22 +2689,23 @@ System.register('Utils', [], (function (exports) {
2685
2689
  abortFn();
2686
2690
  }
2687
2691
  };
2692
+ // @ts-ignore
2688
2693
  return promise;
2689
2694
  }
2690
2695
  /**
2691
2696
  * OPTIONS 请求
2692
2697
  */
2693
- async options(...args // @ts-ignore
2698
+ options(...args // @ts-ignore
2694
2699
  ) {
2695
- let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2700
+ let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
2696
2701
  let abortFn = null;
2697
- let promise = new Promise((resolve, reject) => {
2698
- let requestOption = this.HttpxRequestDetails.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
2702
+ let promise = new Promise(async (resolve, reject) => {
2703
+ let requestOption = this.HttpxRequestOption.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
2699
2704
  Reflect.deleteProperty(requestOption, "onprogress");
2700
2705
  // @ts-ignore
2701
2706
  requestOption =
2702
- this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2703
- const requestResult = this.HttpxRequest.request(requestOption);
2707
+ this.HttpxRequestOption.removeRequestNullOption(requestOption);
2708
+ const requestResult = await this.HttpxRequest.request(requestOption);
2704
2709
  if (requestResult != null &&
2705
2710
  typeof requestResult.abort === "function") {
2706
2711
  abortFn = requestResult.abort;
@@ -2712,22 +2717,23 @@ System.register('Utils', [], (function (exports) {
2712
2717
  abortFn();
2713
2718
  }
2714
2719
  };
2720
+ // @ts-ignore
2715
2721
  return promise;
2716
2722
  }
2717
2723
  /**
2718
2724
  * DELETE 请求
2719
2725
  */
2720
- async delete(...args // @ts-ignore
2726
+ delete(...args // @ts-ignore
2721
2727
  ) {
2722
- let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2728
+ let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
2723
2729
  let abortFn = null;
2724
- let promise = new Promise((resolve, reject) => {
2725
- let requestOption = this.HttpxRequestDetails.getRequestOption("DELETE", userRequestOption, resolve, reject);
2730
+ let promise = new Promise(async (resolve, reject) => {
2731
+ let requestOption = this.HttpxRequestOption.getRequestOption("DELETE", userRequestOption, resolve, reject);
2726
2732
  Reflect.deleteProperty(requestOption, "onprogress");
2727
2733
  // @ts-ignore
2728
2734
  requestOption =
2729
- this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2730
- const requestResult = this.HttpxRequest.request(requestOption);
2735
+ this.HttpxRequestOption.removeRequestNullOption(requestOption);
2736
+ const requestResult = await this.HttpxRequest.request(requestOption);
2731
2737
  if (requestResult != null &&
2732
2738
  typeof requestResult.abort === "function") {
2733
2739
  abortFn = requestResult.abort;
@@ -2739,21 +2745,22 @@ System.register('Utils', [], (function (exports) {
2739
2745
  abortFn();
2740
2746
  }
2741
2747
  };
2748
+ // @ts-ignore
2742
2749
  return promise;
2743
2750
  }
2744
2751
  /**
2745
2752
  * PUT 请求
2746
2753
  */
2747
- async put(...args // @ts-ignore
2754
+ put(...args // @ts-ignore
2748
2755
  ) {
2749
- let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2756
+ let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
2750
2757
  let abortFn = null;
2751
- let promise = new Promise((resolve, reject) => {
2752
- let requestOption = this.HttpxRequestDetails.getRequestOption("PUT", userRequestOption, resolve, reject);
2758
+ let promise = new Promise(async (resolve, reject) => {
2759
+ let requestOption = this.HttpxRequestOption.getRequestOption("PUT", userRequestOption, resolve, reject);
2753
2760
  // @ts-ignore
2754
2761
  requestOption =
2755
- this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2756
- const requestResult = this.HttpxRequest.request(requestOption);
2762
+ this.HttpxRequestOption.removeRequestNullOption(requestOption);
2763
+ const requestResult = await this.HttpxRequest.request(requestOption);
2757
2764
  if (requestResult != null &&
2758
2765
  typeof requestResult.abort === "function") {
2759
2766
  abortFn = requestResult.abort;
@@ -2765,6 +2772,7 @@ System.register('Utils', [], (function (exports) {
2765
2772
  abortFn();
2766
2773
  }
2767
2774
  };
2775
+ // @ts-ignore
2768
2776
  return promise;
2769
2777
  }
2770
2778
  }
@@ -4069,7 +4077,7 @@ System.register('Utils', [], (function (exports) {
4069
4077
  this.windowApi = new WindowApi(option);
4070
4078
  }
4071
4079
  /** 版本号 */
4072
- version = "2024.10.28";
4080
+ version = "2024.10.31";
4073
4081
  addStyle(cssText) {
4074
4082
  if (typeof cssText !== "string") {
4075
4083
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");