@whitesev/utils 1.7.0 → 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/dist/index.esm.js CHANGED
@@ -3433,7 +3433,7 @@ class Utils {
3433
3433
  UtilsCore.init(option);
3434
3434
  }
3435
3435
  /** 版本号 */
3436
- version = "2024.6.16";
3436
+ version = "2024.7.20";
3437
3437
  addStyle(cssText) {
3438
3438
  if (typeof cssText !== "string") {
3439
3439
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4127,21 +4127,31 @@ class Utils {
4127
4127
  }
4128
4128
  }
4129
4129
  getMaxZIndex(deviation = 1) {
4130
- let nodeIndexList = [];
4131
4130
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4132
- document.querySelectorAll("*").forEach((element) => {
4131
+ // 最大值2147483647
4132
+ let maxZIndex = Math.pow(2, 31) - 1;
4133
+ // 比较值2000000000
4134
+ let maxZIndexCompare = 2 * Math.pow(10, 9);
4135
+ // 当前页面最大的z-index
4136
+ let zIndex = 0;
4137
+ document.querySelectorAll("*").forEach((element, index) => {
4133
4138
  let nodeStyle = window.getComputedStyle(element);
4134
4139
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4135
4140
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4136
- nodeIndexList = nodeIndexList.concat(parseInt(nodeStyle.zIndex));
4141
+ let nodeZIndex = parseInt(nodeStyle.zIndex);
4142
+ if (!isNaN(nodeZIndex)) {
4143
+ if (nodeZIndex > zIndex) {
4144
+ zIndex = nodeZIndex;
4145
+ }
4146
+ }
4137
4147
  }
4138
4148
  });
4139
- /* 过滤非Boolean类型 */
4140
- nodeIndexList = nodeIndexList.filter(Boolean);
4141
- let currentMaxZIndex = nodeIndexList.length
4142
- ? Math.max(...nodeIndexList)
4143
- : 0;
4144
- return currentMaxZIndex + deviation;
4149
+ zIndex += deviation;
4150
+ if (zIndex >= maxZIndexCompare) {
4151
+ // 最好不要超过最大值
4152
+ zIndex = maxZIndex;
4153
+ }
4154
+ return zIndex;
4145
4155
  }
4146
4156
  getMinValue(...args) {
4147
4157
  let result = [...args];