@whitesev/utils 1.6.1 → 1.8.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 安装
2
2
 
3
+ + 最新版本:[![npm version](https://img.shields.io/npm/v/@whitesev/utils)](https://www.npmjs.com/package/@whitesev/utils)
4
+
3
5
  ```node
4
6
  npm install @whitesev/utils
5
7
  // 或者
package/dist/index.amd.js CHANGED
@@ -1565,11 +1565,13 @@ define((function () { 'use strict';
1565
1565
  * @private
1566
1566
  */
1567
1567
  beforeRequestCallBack(details) {
1568
- if (!details.allowInterceptConfig) {
1569
- return details;
1570
- }
1571
- if (!details.allowInterceptConfig.beforeRequest) {
1572
- return details;
1568
+ if (details.allowInterceptConfig) {
1569
+ // 首先配置得存在,不然默认允许拦截
1570
+ if (typeof details.allowInterceptConfig.beforeRequest === "boolean" &&
1571
+ !details.allowInterceptConfig.beforeRequest) {
1572
+ // 设置了禁止拦截
1573
+ return details;
1574
+ }
1573
1575
  }
1574
1576
  for (let index = 0; index < this.$config.configList.length; index++) {
1575
1577
  let item = this.$config.configList[index];
@@ -1632,11 +1634,14 @@ define((function () { 'use strict';
1632
1634
  * @param details 请求的配置
1633
1635
  */
1634
1636
  successResponseCallBack(response, details) {
1635
- if (!details.allowInterceptConfig) {
1636
- return details;
1637
- }
1638
- if (!details.allowInterceptConfig.afterResponseSuccess) {
1639
- return details;
1637
+ if (details.allowInterceptConfig) {
1638
+ // 首先配置得存在,不然默认允许拦截
1639
+ if (typeof details.allowInterceptConfig.afterResponseSuccess ===
1640
+ "boolean" &&
1641
+ !details.allowInterceptConfig.afterResponseSuccess) {
1642
+ // 设置了禁止拦截
1643
+ return details;
1644
+ }
1640
1645
  }
1641
1646
  for (let index = 0; index < this.$config.configList.length; index++) {
1642
1647
  let item = this.$config.configList[index];
@@ -1653,11 +1658,14 @@ define((function () { 'use strict';
1653
1658
  * @param data 配置
1654
1659
  */
1655
1660
  errorResponseCallBack(data) {
1656
- if (!data.details.allowInterceptConfig) {
1657
- return data;
1658
- }
1659
- if (!data.details.allowInterceptConfig.afterResponseError) {
1660
- return data;
1661
+ if (data.details.allowInterceptConfig) {
1662
+ // 首先配置得存在,不然默认允许拦截
1663
+ if (typeof data.details.allowInterceptConfig.afterResponseError ===
1664
+ "boolean" &&
1665
+ !data.details.allowInterceptConfig.afterResponseError) {
1666
+ // 设置了禁止拦截
1667
+ return data;
1668
+ }
1661
1669
  }
1662
1670
  for (let index = 0; index < this.$config.configList.length; index++) {
1663
1671
  let item = this.$config.configList[index];
@@ -3278,14 +3286,14 @@ define((function () { 'use strict';
3278
3286
  };
3279
3287
 
3280
3288
  class UtilsDictionary {
3281
- items = {};
3289
+ #items = {};
3282
3290
  constructor() { }
3283
3291
  /**
3284
3292
  * 检查是否有某一个键
3285
3293
  * @param key 键
3286
3294
  */
3287
3295
  has(key) {
3288
- return this.items.hasOwnProperty(key);
3296
+ return this.#items.hasOwnProperty(key);
3289
3297
  }
3290
3298
  /**
3291
3299
  * 检查已有的键中是否以xx开头
@@ -3309,7 +3317,7 @@ define((function () { 'use strict';
3309
3317
  let result = null;
3310
3318
  for (const keyName of allKeys) {
3311
3319
  if (keyName.startsWith(key)) {
3312
- result = this.items[keyName];
3320
+ result = this.#items[keyName];
3313
3321
  break;
3314
3322
  }
3315
3323
  }
@@ -3324,7 +3332,7 @@ define((function () { 'use strict';
3324
3332
  if (key === void 0) {
3325
3333
  throw new Error("Utils.Dictionary().set 参数 key 不能为空");
3326
3334
  }
3327
- this.items[key] = val;
3335
+ this.#items[key] = val;
3328
3336
  }
3329
3337
  /**
3330
3338
  * 删除某一个键
@@ -3332,7 +3340,7 @@ define((function () { 'use strict';
3332
3340
  */
3333
3341
  delete(key) {
3334
3342
  if (this.has(key)) {
3335
- Reflect.deleteProperty(this.items, key);
3343
+ Reflect.deleteProperty(this.#items, key);
3336
3344
  return true;
3337
3345
  }
3338
3346
  return false;
@@ -3360,8 +3368,8 @@ define((function () { 'use strict';
3360
3368
  * 清空字典
3361
3369
  */
3362
3370
  clear() {
3363
- this.items = void 0;
3364
- this.items = {};
3371
+ this.#items = void 0;
3372
+ this.#items = {};
3365
3373
  }
3366
3374
  /**
3367
3375
  * 获取字典的长度
@@ -3379,14 +3387,14 @@ define((function () { 'use strict';
3379
3387
  * 返回字典本身
3380
3388
  */
3381
3389
  getItems() {
3382
- return this.items;
3390
+ return this.#items;
3383
3391
  }
3384
3392
  /**
3385
3393
  * 合并另一个字典
3386
3394
  * @param data 需要合并的字典
3387
3395
  */
3388
3396
  concat(data) {
3389
- this.items = utils.assign(this.items, data.getItems());
3397
+ this.#items = utils.assign(this.#items, data.getItems());
3390
3398
  }
3391
3399
  forEach(callbackfn) {
3392
3400
  for (const key in this.getItems()) {
@@ -3427,7 +3435,7 @@ define((function () { 'use strict';
3427
3435
  UtilsCore.init(option);
3428
3436
  }
3429
3437
  /** 版本号 */
3430
- version = "2024.6.16";
3438
+ version = "2024.7.20";
3431
3439
  addStyle(cssText) {
3432
3440
  if (typeof cssText !== "string") {
3433
3441
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4121,21 +4129,31 @@ define((function () { 'use strict';
4121
4129
  }
4122
4130
  }
4123
4131
  getMaxZIndex(deviation = 1) {
4124
- let nodeIndexList = [];
4125
4132
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4126
- document.querySelectorAll("*").forEach((element) => {
4133
+ // 最大值2147483647
4134
+ let maxZIndex = Math.pow(2, 31) - 1;
4135
+ // 比较值2000000000
4136
+ let maxZIndexCompare = 2 * Math.pow(10, 9);
4137
+ // 当前页面最大的z-index
4138
+ let zIndex = 0;
4139
+ document.querySelectorAll("*").forEach((element, index) => {
4127
4140
  let nodeStyle = window.getComputedStyle(element);
4128
4141
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4129
4142
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4130
- nodeIndexList = nodeIndexList.concat(parseInt(nodeStyle.zIndex));
4143
+ let nodeZIndex = parseInt(nodeStyle.zIndex);
4144
+ if (!isNaN(nodeZIndex)) {
4145
+ if (nodeZIndex > zIndex) {
4146
+ zIndex = nodeZIndex;
4147
+ }
4148
+ }
4131
4149
  }
4132
4150
  });
4133
- /* 过滤非Boolean类型 */
4134
- nodeIndexList = nodeIndexList.filter(Boolean);
4135
- let currentMaxZIndex = nodeIndexList.length
4136
- ? Math.max(...nodeIndexList)
4137
- : 0;
4138
- return currentMaxZIndex + deviation;
4151
+ zIndex += deviation;
4152
+ if (zIndex >= maxZIndexCompare) {
4153
+ // 最好不要超过最大值
4154
+ zIndex = maxZIndex;
4155
+ }
4156
+ return zIndex;
4139
4157
  }
4140
4158
  getMinValue(...args) {
4141
4159
  let result = [...args];