@whitesev/utils 1.7.0 → 1.9.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/index.umd.js CHANGED
@@ -1569,14 +1569,23 @@
1569
1569
  * @private
1570
1570
  */
1571
1571
  beforeRequestCallBack(details) {
1572
- if (details.allowInterceptConfig) {
1573
- // 首先配置得存在,不然默认允许拦截
1574
- if (typeof details.allowInterceptConfig.beforeRequest === "boolean" &&
1575
- !details.allowInterceptConfig.beforeRequest) {
1576
- // 设置了禁止拦截
1572
+ if (typeof details.allowInterceptConfig === "boolean") {
1573
+ if (!details.allowInterceptConfig) {
1574
+ // 不允许拦截
1577
1575
  return details;
1578
1576
  }
1579
1577
  }
1578
+ else {
1579
+ if (details.allowInterceptConfig != null) {
1580
+ // 配置存在
1581
+ // 细分处理是否拦截
1582
+ if (typeof details.allowInterceptConfig.beforeRequest === "boolean" &&
1583
+ !details.allowInterceptConfig.beforeRequest) {
1584
+ // 设置了禁止拦截
1585
+ return details;
1586
+ }
1587
+ }
1588
+ }
1580
1589
  for (let index = 0; index < this.$config.configList.length; index++) {
1581
1590
  let item = this.$config.configList[index];
1582
1591
  if (typeof item.fn === "function") {
@@ -1638,15 +1647,24 @@
1638
1647
  * @param details 请求的配置
1639
1648
  */
1640
1649
  successResponseCallBack(response, details) {
1641
- if (details.allowInterceptConfig) {
1642
- // 首先配置得存在,不然默认允许拦截
1643
- if (typeof details.allowInterceptConfig.afterResponseSuccess ===
1644
- "boolean" &&
1645
- !details.allowInterceptConfig.afterResponseSuccess) {
1646
- // 设置了禁止拦截
1650
+ if (typeof details.allowInterceptConfig === "boolean") {
1651
+ if (!details.allowInterceptConfig) {
1652
+ // 不允许拦截
1647
1653
  return details;
1648
1654
  }
1649
1655
  }
1656
+ else {
1657
+ if (details.allowInterceptConfig != null) {
1658
+ // 配置存在
1659
+ // 细分处理是否拦截
1660
+ if (typeof details.allowInterceptConfig.afterResponseSuccess ===
1661
+ "boolean" &&
1662
+ !details.allowInterceptConfig.afterResponseSuccess) {
1663
+ // 设置了禁止拦截
1664
+ return details;
1665
+ }
1666
+ }
1667
+ }
1650
1668
  for (let index = 0; index < this.$config.configList.length; index++) {
1651
1669
  let item = this.$config.configList[index];
1652
1670
  if (typeof item.successFn === "function") {
@@ -1660,17 +1678,28 @@
1660
1678
  /**
1661
1679
  * 失败的回调
1662
1680
  * @param data 配置
1681
+ * @returns
1682
+ * 返回null|undefined就是拦截掉了
1663
1683
  */
1664
1684
  errorResponseCallBack(data) {
1665
- if (data.details.allowInterceptConfig) {
1666
- // 首先配置得存在,不然默认允许拦截
1667
- if (typeof data.details.allowInterceptConfig.afterResponseError ===
1668
- "boolean" &&
1669
- !data.details.allowInterceptConfig.afterResponseError) {
1670
- // 设置了禁止拦截
1685
+ if (typeof data.details.allowInterceptConfig === "boolean") {
1686
+ if (!data.details.allowInterceptConfig) {
1687
+ // 不允许拦截
1671
1688
  return data;
1672
1689
  }
1673
1690
  }
1691
+ else {
1692
+ if (data.details.allowInterceptConfig != null) {
1693
+ // 配置存在
1694
+ // 细分处理是否拦截
1695
+ if (typeof data.details.allowInterceptConfig.afterResponseError ===
1696
+ "boolean" &&
1697
+ !data.details.allowInterceptConfig.afterResponseError) {
1698
+ // 设置了禁止拦截
1699
+ return data;
1700
+ }
1701
+ }
1702
+ }
1674
1703
  for (let index = 0; index < this.$config.configList.length; index++) {
1675
1704
  let item = this.$config.configList[index];
1676
1705
  if (typeof item.errorFn === "function") {
@@ -1741,10 +1770,11 @@
1741
1770
  /**
1742
1771
  * 获取请求配置
1743
1772
  * @param method 当前请求方法,默认get
1744
- * @param resolve promise回调
1745
1773
  * @param details 请求配置
1774
+ * @param resolve promise回调
1775
+ * @param reject 抛出错误回调
1746
1776
  */
1747
- getDetails(method, resolve, details) {
1777
+ getDetails(method, details, resolve, reject) {
1748
1778
  let that = this;
1749
1779
  let result = {
1750
1780
  url: details.url || this.context.#defaultDetails.url,
@@ -1770,10 +1800,10 @@
1770
1800
  user: details.user || this.context.#defaultDetails.user,
1771
1801
  password: details.password || this.context.#defaultDetails.password,
1772
1802
  onabort(...args) {
1773
- that.context.HttpxCallBack.onAbort(details, resolve, args);
1803
+ that.context.HttpxCallBack.onAbort(details, resolve, reject, args);
1774
1804
  },
1775
1805
  onerror(...args) {
1776
- that.context.HttpxCallBack.onError(details, resolve, args);
1806
+ that.context.HttpxCallBack.onError(details, resolve, reject, args);
1777
1807
  },
1778
1808
  onloadstart(...args) {
1779
1809
  that.context.HttpxCallBack.onLoadStart(details, args);
@@ -1785,10 +1815,10 @@
1785
1815
  that.context.HttpxCallBack.onReadyStateChange(details, args);
1786
1816
  },
1787
1817
  ontimeout(...args) {
1788
- that.context.HttpxCallBack.onTimeout(details, resolve, args);
1818
+ that.context.HttpxCallBack.onTimeout(details, resolve, reject, args);
1789
1819
  },
1790
1820
  onload(...args) {
1791
- that.context.HttpxCallBack.onLoad(details, resolve, args);
1821
+ that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
1792
1822
  },
1793
1823
  };
1794
1824
  if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
@@ -1918,9 +1948,10 @@
1918
1948
  * onabort请求被取消-触发
1919
1949
  * @param details 配置
1920
1950
  * @param resolve 回调
1951
+ * @param reject 抛出错误
1921
1952
  * @param argumentsList 参数列表
1922
1953
  */
1923
- onAbort(details, resolve, argumentsList) {
1954
+ onAbort(details, resolve, reject, argumentsList) {
1924
1955
  if ("onabort" in details) {
1925
1956
  details.onabort.apply(this, argumentsList);
1926
1957
  }
@@ -1933,6 +1964,7 @@
1933
1964
  response: null,
1934
1965
  details: details,
1935
1966
  }) == null) {
1967
+ // reject(new TypeError("response is intercept with onabort"));
1936
1968
  return;
1937
1969
  }
1938
1970
  resolve({
@@ -1946,9 +1978,10 @@
1946
1978
  * onerror请求异常-触发
1947
1979
  * @param details 配置
1948
1980
  * @param resolve 回调
1981
+ * @param reject 抛出错误
1949
1982
  * @param argumentsList 响应的参数列表
1950
1983
  */
1951
- onError(details, resolve, argumentsList) {
1984
+ onError(details, resolve, reject, argumentsList) {
1952
1985
  if ("onerror" in details) {
1953
1986
  details.onerror.apply(this, argumentsList);
1954
1987
  }
@@ -1965,6 +1998,7 @@
1965
1998
  response: response,
1966
1999
  details: details,
1967
2000
  }) == null) {
2001
+ // reject(new TypeError("response is intercept with onerror"));
1968
2002
  return;
1969
2003
  }
1970
2004
  resolve({
@@ -1979,9 +2013,10 @@
1979
2013
  * ontimeout请求超时-触发
1980
2014
  * @param details 配置
1981
2015
  * @param resolve 回调
2016
+ * @param reject 抛出错误
1982
2017
  * @param argumentsList 参数列表
1983
2018
  */
1984
- onTimeout(details, resolve, argumentsList) {
2019
+ onTimeout(details, resolve, reject, argumentsList) {
1985
2020
  if ("ontimeout" in details) {
1986
2021
  details.ontimeout.apply(this, argumentsList);
1987
2022
  }
@@ -1994,6 +2029,7 @@
1994
2029
  response: (argumentsList || [null])[0],
1995
2030
  details: details,
1996
2031
  }) == null) {
2032
+ // reject(new TypeError("response is intercept with ontimeout"));
1997
2033
  return;
1998
2034
  }
1999
2035
  resolve({
@@ -2020,9 +2056,10 @@
2020
2056
  * onload加载完毕-触发
2021
2057
  * @param details 请求的配置
2022
2058
  * @param resolve 回调
2059
+ * @param reject 抛出错误
2023
2060
  * @param argumentsList 参数列表
2024
2061
  */
2025
- onLoad(details, resolve, argumentsList) {
2062
+ onLoad(details, resolve, reject, argumentsList) {
2026
2063
  /* X浏览器会因为设置了responseType导致不返回responseText */
2027
2064
  let Response = argumentsList[0];
2028
2065
  /* responseText为空,response不为空的情况 */
@@ -2077,6 +2114,7 @@
2077
2114
  /* 状态码2xx都是成功的 */
2078
2115
  if (Math.floor(Response.status / 100) === 2) {
2079
2116
  if (this.context.HttpxResponseHook.successResponseCallBack(Response, details) == null) {
2117
+ // reject(new TypeError("response is intercept with onloada"));
2080
2118
  return;
2081
2119
  }
2082
2120
  resolve({
@@ -2088,7 +2126,7 @@
2088
2126
  });
2089
2127
  }
2090
2128
  else {
2091
- this.context.HttpxCallBack.onError(details, resolve, argumentsList);
2129
+ this.context.HttpxCallBack.onError(details, resolve, reject, argumentsList);
2092
2130
  }
2093
2131
  },
2094
2132
  /**
@@ -2399,8 +2437,8 @@
2399
2437
  async get(...args) {
2400
2438
  let that = this;
2401
2439
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2402
- return new Promise((resolve) => {
2403
- let requestDetails = that.HttpxRequestDetails.getDetails("get", resolve, details);
2440
+ return new Promise((resolve, reject) => {
2441
+ let requestDetails = that.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
2404
2442
  Reflect.deleteProperty(requestDetails, "onprogress");
2405
2443
  requestDetails = that.HttpxRequestDetails.handle(requestDetails);
2406
2444
  that.HttpxRequest.request(requestDetails);
@@ -2412,8 +2450,8 @@
2412
2450
  async post(...args) {
2413
2451
  let that = this;
2414
2452
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2415
- return new Promise((resolve) => {
2416
- let requestDetails = that.HttpxRequestDetails.getDetails("post", resolve, details);
2453
+ return new Promise((resolve, reject) => {
2454
+ let requestDetails = that.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
2417
2455
  requestDetails = that.HttpxRequestDetails.handle(requestDetails);
2418
2456
  that.HttpxRequest.request(requestDetails);
2419
2457
  });
@@ -2424,8 +2462,8 @@
2424
2462
  async head(...args) {
2425
2463
  let that = this;
2426
2464
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2427
- return new Promise((resolve) => {
2428
- let requestDetails = that.HttpxRequestDetails.getDetails("head", resolve, details);
2465
+ return new Promise((resolve, reject) => {
2466
+ let requestDetails = that.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
2429
2467
  Reflect.deleteProperty(requestDetails, "onprogress");
2430
2468
  requestDetails = that.HttpxRequestDetails.handle(requestDetails);
2431
2469
  that.HttpxRequest.request(requestDetails);
@@ -2437,8 +2475,8 @@
2437
2475
  async options(...args) {
2438
2476
  let that = this;
2439
2477
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2440
- return new Promise((resolve) => {
2441
- let requestDetails = that.HttpxRequestDetails.getDetails("options", resolve, details);
2478
+ return new Promise((resolve, reject) => {
2479
+ let requestDetails = that.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
2442
2480
  Reflect.deleteProperty(requestDetails, "onprogress");
2443
2481
  requestDetails = that.HttpxRequestDetails.handle(requestDetails);
2444
2482
  that.HttpxRequest.request(requestDetails);
@@ -2450,8 +2488,8 @@
2450
2488
  async delete(...args) {
2451
2489
  let that = this;
2452
2490
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2453
- return new Promise((resolve) => {
2454
- let requestDetails = that.HttpxRequestDetails.getDetails("delete", resolve, details);
2491
+ return new Promise((resolve, reject) => {
2492
+ let requestDetails = that.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
2455
2493
  Reflect.deleteProperty(requestDetails, "onprogress");
2456
2494
  requestDetails = that.HttpxRequestDetails.handle(requestDetails);
2457
2495
  that.HttpxRequest.request(requestDetails);
@@ -2463,8 +2501,8 @@
2463
2501
  async put(...args) {
2464
2502
  let that = this;
2465
2503
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2466
- return new Promise((resolve) => {
2467
- let requestDetails = that.HttpxRequestDetails.getDetails("put", resolve, details);
2504
+ return new Promise((resolve, reject) => {
2505
+ let requestDetails = that.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
2468
2506
  requestDetails = that.HttpxRequestDetails.handle(requestDetails);
2469
2507
  that.HttpxRequest.request(requestDetails);
2470
2508
  });
@@ -3439,7 +3477,7 @@
3439
3477
  UtilsCore.init(option);
3440
3478
  }
3441
3479
  /** 版本号 */
3442
- version = "2024.6.16";
3480
+ version = "2024.7.20";
3443
3481
  addStyle(cssText) {
3444
3482
  if (typeof cssText !== "string") {
3445
3483
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4133,21 +4171,31 @@
4133
4171
  }
4134
4172
  }
4135
4173
  getMaxZIndex(deviation = 1) {
4136
- let nodeIndexList = [];
4137
4174
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4138
- document.querySelectorAll("*").forEach((element) => {
4175
+ // 最大值2147483647
4176
+ let maxZIndex = Math.pow(2, 31) - 1;
4177
+ // 比较值2000000000
4178
+ let maxZIndexCompare = 2 * Math.pow(10, 9);
4179
+ // 当前页面最大的z-index
4180
+ let zIndex = 0;
4181
+ document.querySelectorAll("*").forEach((element, index) => {
4139
4182
  let nodeStyle = window.getComputedStyle(element);
4140
4183
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4141
4184
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4142
- nodeIndexList = nodeIndexList.concat(parseInt(nodeStyle.zIndex));
4185
+ let nodeZIndex = parseInt(nodeStyle.zIndex);
4186
+ if (!isNaN(nodeZIndex)) {
4187
+ if (nodeZIndex > zIndex) {
4188
+ zIndex = nodeZIndex;
4189
+ }
4190
+ }
4143
4191
  }
4144
4192
  });
4145
- /* 过滤非Boolean类型 */
4146
- nodeIndexList = nodeIndexList.filter(Boolean);
4147
- let currentMaxZIndex = nodeIndexList.length
4148
- ? Math.max(...nodeIndexList)
4149
- : 0;
4150
- return currentMaxZIndex + deviation;
4193
+ zIndex += deviation;
4194
+ if (zIndex >= maxZIndexCompare) {
4195
+ // 最好不要超过最大值
4196
+ zIndex = maxZIndex;
4197
+ }
4198
+ return zIndex;
4151
4199
  }
4152
4200
  getMinValue(...args) {
4153
4201
  let result = [...args];