@whitesev/utils 2.9.2 → 2.9.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.
@@ -5475,7 +5475,7 @@ var Utils = (function () {
5475
5475
  }
5476
5476
  const domUtils = new DOMUtils();
5477
5477
 
5478
- const version = "2.9.2";
5478
+ const version = "2.9.3";
5479
5479
 
5480
5480
  class Utils {
5481
5481
  windowApi;
@@ -7635,30 +7635,34 @@ var Utils = (function () {
7635
7635
  });
7636
7636
  }
7637
7637
  }
7638
- sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
7638
+ sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
7639
7639
  const that = this;
7640
- if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
7640
+ if (typeof getComparePropertyValue !== "function" && typeof getComparePropertyValue !== "string") {
7641
7641
  throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
7642
7642
  }
7643
7643
  if (typeof sortByDesc !== "boolean") {
7644
7644
  throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
7645
7645
  }
7646
- const getObjValue = function (obj) {
7647
- return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
7646
+ const getTargetValue = function (target) {
7647
+ return typeof getComparePropertyValue === "string"
7648
+ ? target[getComparePropertyValue]
7649
+ : getComparePropertyValue(target);
7648
7650
  };
7649
7651
  /**
7650
- * 排序方法
7651
- * @param after_obj
7652
- * @param before_obj
7652
+ * number类型排序方法
7653
+ * @param afterInst
7654
+ * @param beforeInst
7653
7655
  */
7654
- const sortFunc = function (after_obj, before_obj) {
7655
- const beforeValue = getObjValue(before_obj); /* 前 */
7656
- const afterValue = getObjValue(after_obj); /* 后 */
7656
+ const sortFunc = function (afterInst, beforeInst) {
7657
+ const beforeValue = getTargetValue(beforeInst); /* 前 */
7658
+ const afterValue = getTargetValue(afterInst); /* 后 */
7657
7659
  if (sortByDesc) {
7658
- if (afterValue > beforeValue) {
7660
+ // 降序
7661
+ // 5、4、3、2、1
7662
+ if (beforeValue < afterValue) {
7659
7663
  return -1;
7660
7664
  }
7661
- else if (afterValue < beforeValue) {
7665
+ else if (beforeValue > afterValue) {
7662
7666
  return 1;
7663
7667
  }
7664
7668
  else {
@@ -7666,10 +7670,12 @@ var Utils = (function () {
7666
7670
  }
7667
7671
  }
7668
7672
  else {
7669
- if (afterValue < beforeValue) {
7673
+ // 升序
7674
+ // 1、2、3、4、5
7675
+ if (beforeValue > afterValue) {
7670
7676
  return -1;
7671
7677
  }
7672
- else if (afterValue > beforeValue) {
7678
+ else if (beforeValue < afterValue) {
7673
7679
  return 1;
7674
7680
  }
7675
7681
  else {
@@ -7678,18 +7684,18 @@ var Utils = (function () {
7678
7684
  }
7679
7685
  };
7680
7686
  /**
7681
- * 排序元素方法
7687
+ * 元素排序方法
7682
7688
  * @param nodeList 元素列表
7683
7689
  * @param getNodeListFunc 获取元素列表的函数
7684
7690
  */
7685
7691
  const sortNodeFunc = function (nodeList, getNodeListFunc) {
7686
7692
  const nodeListLength = nodeList.length;
7687
- for (let i = 0; i < nodeListLength - 1; i++) {
7688
- for (let j = 0; j < nodeListLength - 1 - i; j++) {
7689
- const beforeNode = nodeList[j];
7690
- const afterNode = nodeList[j + 1];
7691
- const beforeValue = getObjValue(beforeNode); /* 前 */
7692
- const afterValue = getObjValue(afterNode); /* 后 */
7693
+ for (let index = 0; index < nodeListLength - 1; index++) {
7694
+ for (let index2 = 0; index2 < nodeListLength - 1 - index; index2++) {
7695
+ const beforeNode = nodeList[index2];
7696
+ const afterNode = nodeList[index2 + 1];
7697
+ const beforeValue = getTargetValue(beforeNode); /* 前 */
7698
+ const afterValue = getTargetValue(afterNode); /* 后 */
7693
7699
  if ((sortByDesc == true && beforeValue < afterValue) || (sortByDesc == false && beforeValue > afterValue)) {
7694
7700
  /* 升序/降序 */
7695
7701
  /* 相邻元素两两对比 */
@@ -7712,7 +7718,9 @@ var Utils = (function () {
7712
7718
  let getDataFunc = null;
7713
7719
  if (data instanceof Function) {
7714
7720
  getDataFunc = data;
7715
- data = data();
7721
+ const newData = getDataFunc();
7722
+ data = newData;
7723
+ result = newData;
7716
7724
  }
7717
7725
  if (Array.isArray(data)) {
7718
7726
  data.sort(sortFunc);