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