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