zzz-pc-view 0.0.165 → 0.0.166

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zzz-pc-view",
3
- "version": "0.0.165",
3
+ "version": "0.0.166",
4
4
  "main": "src/index.umd.js",
5
5
  "module": "src/index.es.js",
6
6
  "types": "src/index.d.ts",
@@ -450,6 +450,14 @@ export declare abstract class CurdHandler<T extends object = object, P extends P
450
450
  * 最后,它会将解析后的对象绑定到 FilterTarget 上,并将结果赋值给 searchQueryRef。
451
451
  */
452
452
  protected setSearchQuery(): void;
453
+ protected readonly sortInfoRef: import('vue').ShallowRef<{
454
+ prop: keyof T;
455
+ order: 1 | -1;
456
+ } | undefined, {
457
+ prop: keyof T;
458
+ order: 1 | -1;
459
+ } | undefined>;
460
+ setSortInfo(prop: keyof T, order: 1 | -1): void;
453
461
  /**
454
462
  * 创建一个浅引用,用于存储列表数据。
455
463
  * 这个引用将用于在组件中存储和更新列表数据。
package/src/index.es.js CHANGED
@@ -1544,6 +1544,26 @@ const sort = (list2, sortKey) => {
1544
1544
  return 0;
1545
1545
  });
1546
1546
  };
1547
+ const sortByField = (arr, field, order = 1, nullLast = true) => {
1548
+ const list2 = [...arr];
1549
+ list2.sort((a, b) => {
1550
+ const valA = a[field];
1551
+ const valB = b[field];
1552
+ const isANull = valA === null || valA === void 0;
1553
+ const isBNull = valB === null || valB === void 0;
1554
+ if (isANull && isBNull) return 0;
1555
+ if (isANull) return nullLast ? 1 : -1;
1556
+ if (isBNull) return nullLast ? -1 : 1;
1557
+ if (typeof valA === "number" && typeof valB === "number") {
1558
+ return order * (valA - valB);
1559
+ }
1560
+ const strA = String(valA).trim();
1561
+ const strB = String(valB).trim();
1562
+ const compareRes = strA.localeCompare(strB, void 0, { numeric: true });
1563
+ return order * compareRes;
1564
+ });
1565
+ return list2;
1566
+ };
1547
1567
  const create$1 = (option) => {
1548
1568
  const rootNodes = [];
1549
1569
  const buildMap = {};
@@ -1720,6 +1740,7 @@ const index$g = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
1720
1740
  ratioByHorizontal,
1721
1741
  ratioByVertical,
1722
1742
  sort,
1743
+ sortByField,
1723
1744
  sumGroupByHorizontal,
1724
1745
  sumGroupByVertical,
1725
1746
  toKeyValue,
@@ -5639,6 +5660,7 @@ class CurdHandler extends FilterHandler {
5639
5660
  * @description 这对于性能优化很重要,因为它避免了不必要的更新。
5640
5661
  */
5641
5662
  __publicField(this, "searchQueryRef", shallowRef());
5663
+ __publicField(this, "sortInfoRef", shallowRef());
5642
5664
  /**
5643
5665
  * 创建一个浅引用,用于存储列表数据。
5644
5666
  * 这个引用将用于在组件中存储和更新列表数据。
@@ -5657,6 +5679,10 @@ class CurdHandler extends FilterHandler {
5657
5679
  */
5658
5680
  __publicField(this, "displayListComputed", computed(() => {
5659
5681
  let displayList = this.listRef.value;
5682
+ const sortInfo = this.sortInfoRef.value;
5683
+ if (sortInfo) {
5684
+ displayList = sortByField([...displayList], sortInfo.prop, sortInfo.order);
5685
+ }
5660
5686
  const { pagination } = this;
5661
5687
  if (!this.api.hasServerPagination && pagination) {
5662
5688
  const { currentPage, pageSize } = pagination;
@@ -5964,6 +5990,9 @@ class CurdHandler extends FilterHandler {
5964
5990
  }
5965
5991
  this.searchQueryRef.value = searchQuery;
5966
5992
  }
5993
+ setSortInfo(prop, order) {
5994
+ this.sortInfoRef.value = { prop, order };
5995
+ }
5967
5996
  /**
5968
5997
  * 获取当前显示的列表数据。
5969
5998
  * 这个方法返回 displayListComputed 计算属性的值,它表示当前显示的列表数据。