hy-virtual-tree 2.1.1 → 2.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## Changelog
2
2
 
3
+ ### 2.1.3
4
+
5
+ _2026-05-20_
6
+
7
+ (1)filterExpandModel 参数新增 result 选项,实时过滤后只展开符合条件的数据
8
+
9
+ ### 2.1.2
10
+
11
+ _2026-05-20_
12
+
13
+ (1)修复 调用setChecked方法时 checkStrictly配置 不生效问题
14
+
3
15
  ### 2.1.1
4
16
 
5
17
  _2026-05-16_
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* hy-virtual-tree v2.1.1 */
1
+ /* hy-virtual-tree v2.1.3 */
2
2
  import './svg_bundle.js';
3
3
  const isString = (e) => typeof e === 'string';
4
4
  const isNumber = (e) => typeof e === 'number';
@@ -8449,7 +8449,7 @@ function useCheck(props, instance) {
8449
8449
  if (!isBusiness || !props.business) {
8450
8450
  const node = treeNodeMap.get(key);
8451
8451
  if (node) {
8452
- toggleCheckbox(node, isChecked, false, true, true, isForce);
8452
+ toggleCheckbox(node, isChecked, false, true, false, isForce);
8453
8453
  }
8454
8454
  return;
8455
8455
  }
@@ -8691,6 +8691,7 @@ function useFilter(config, filterMethod, tree = {
8691
8691
  const isCountFiler = countFilter && isFunction(countFilter);
8692
8692
  const isTotalFiler = totalFilter && isFunction(totalFilter);
8693
8693
  const expandKeySet = new Set();
8694
+ const resultExpandKeySet = new Set();
8694
8695
  const hiddenExpandIconKeys = hiddenExpandIconKeySet;
8695
8696
  const hiddenKeys = hiddenNodeKeySet;
8696
8697
  const family = [];
@@ -8699,8 +8700,12 @@ function useFilter(config, filterMethod, tree = {
8699
8700
  function traverse(nodes, isShow = false) {
8700
8701
  let count = 0;
8701
8702
  let total = 0;
8703
+ let hasFilterResult = false;
8702
8704
  nodes.forEach((node) => {
8703
8705
  family.push(node);
8706
+ if (!hasFilterResult) {
8707
+ hasFilterResult = !!(filterMethod && filterMethod(params, node.data, node));
8708
+ }
8704
8709
  if (isShow || (filterMethod && filterMethod(params, node.data, node))) {
8705
8710
  family.forEach((member) => {
8706
8711
  expandKeySet.add(member.key);
@@ -8711,11 +8716,15 @@ function useFilter(config, filterMethod, tree = {
8711
8716
  }
8712
8717
  const children = node.children;
8713
8718
  if (children) {
8714
- const { count: childCount, total: childTotal } = traverse(children, filterAll ? false : expandKeySet.has(node.key));
8719
+ const { count: childCount, total: childTotal, hasFilterResult: childHasFilterResult } = traverse(children, filterAll ? false : expandKeySet.has(node.key));
8715
8720
  node.count = isCountFiler ? childCount : getCount(node);
8716
8721
  node.total = isTotalFiler ? childTotal : getTotal(node);
8717
8722
  count += childCount;
8718
8723
  total += childTotal;
8724
+ hasFilterResult = hasFilterResult || childHasFilterResult;
8725
+ if (childHasFilterResult) {
8726
+ resultExpandKeySet.add(node.key);
8727
+ }
8719
8728
  }
8720
8729
  else if (!hiddenKeys.has(node.key)) {
8721
8730
  node.count = 0;
@@ -8752,10 +8761,10 @@ function useFilter(config, filterMethod, tree = {
8752
8761
  }
8753
8762
  family.pop();
8754
8763
  });
8755
- return { count, total };
8764
+ return { count, total, hasFilterResult };
8756
8765
  }
8757
8766
  traverse(nodes);
8758
- return expandKeySet;
8767
+ return { expandKeySet, resultExpandKeySet };
8759
8768
  }
8760
8769
  // 通道过滤方法
8761
8770
  function channelFilter(params, filterAll = true) {
@@ -8766,6 +8775,7 @@ function useFilter(config, filterMethod, tree = {
8766
8775
  const isCountFiler = countFilter && isFunction(countFilter);
8767
8776
  const isTotalFiler = totalFilter && isFunction(totalFilter);
8768
8777
  const expandKeySet = new Set();
8778
+ const resultExpandKeySet = new Set();
8769
8779
  const hiddenExpandIconKeys = hiddenExpandIconKeySet;
8770
8780
  const hiddenKeys = hiddenNodeKeySet;
8771
8781
  const family = [];
@@ -8780,9 +8790,13 @@ function useFilter(config, filterMethod, tree = {
8780
8790
  function traverse(nodes, isShow = false) {
8781
8791
  let count = 0;
8782
8792
  let total = 0;
8793
+ let hasFilterResult = false;
8783
8794
  nodes.forEach((node) => {
8784
8795
  const isLeaf = isFilterLeaf(node);
8785
8796
  family.push(node);
8797
+ if (!hasFilterResult) {
8798
+ hasFilterResult = !!(filterMethod && filterMethod(params, node.data, node));
8799
+ }
8786
8800
  if (isShow || (filterMethod && filterMethod(params, node.data, node))) {
8787
8801
  family.forEach((member) => {
8788
8802
  expandKeySet.add(member.key);
@@ -8794,11 +8808,15 @@ function useFilter(config, filterMethod, tree = {
8794
8808
  const children = node.children;
8795
8809
  if (children) {
8796
8810
  if (!isLeaf) {
8797
- const { count: childCount, total: childTotal } = traverse(children, filterAll ? false : expandKeySet.has(node.key));
8811
+ const { count: childCount, total: childTotal, hasFilterResult: childHasFilterResult } = traverse(children, filterAll ? false : expandKeySet.has(node.key));
8798
8812
  node.count = isCountFiler ? childCount : getCount(node);
8799
8813
  node.total = isTotalFiler ? childTotal : getTotal(node);
8800
8814
  count += childCount;
8801
8815
  total += childTotal;
8816
+ hasFilterResult = hasFilterResult || childHasFilterResult;
8817
+ if (childHasFilterResult) {
8818
+ resultExpandKeySet.add(node.key);
8819
+ }
8802
8820
  }
8803
8821
  // 拥有道通的设备
8804
8822
  else if (!hiddenKeys.has(node.key) && node.data.dataType === DataType.DEVICE && !node.isLeaf) {
@@ -8845,10 +8863,10 @@ function useFilter(config, filterMethod, tree = {
8845
8863
  }
8846
8864
  family.pop();
8847
8865
  });
8848
- return { count, total };
8866
+ return { count, total, hasFilterResult };
8849
8867
  }
8850
8868
  traverse(nodes);
8851
- return expandKeySet;
8869
+ return { expandKeySet, resultExpandKeySet };
8852
8870
  }
8853
8871
  // group业务过滤方法
8854
8872
  function doGroupFilter(params, filterAll = true) {
@@ -8857,6 +8875,7 @@ function useFilter(config, filterMethod, tree = {
8857
8875
  }
8858
8876
  useHandleFun(config);
8859
8877
  const expandKeySet = new Set();
8878
+ const resultExpandKeySet = new Set();
8860
8879
  const hiddenExpandIconKeys = hiddenExpandIconKeySet;
8861
8880
  const hiddenKeys = hiddenNodeKeySet;
8862
8881
  const family = [];
@@ -8865,8 +8884,12 @@ function useFilter(config, filterMethod, tree = {
8865
8884
  function traverse(nodes, isShow = false) {
8866
8885
  let count = 0;
8867
8886
  let total = 0;
8887
+ let hasFilterResult = false;
8868
8888
  nodes.forEach((node) => {
8869
8889
  family.push(node);
8890
+ if (!hasFilterResult) {
8891
+ hasFilterResult = !!(filterMethod && filterMethod(params, node.data, node));
8892
+ }
8870
8893
  // if (tree.hiddenNodeKeySet.has(node.key)) return
8871
8894
  if (isShow || (filterMethod && filterMethod(params, node.data, node))) {
8872
8895
  family.forEach((member) => {
@@ -8878,11 +8901,15 @@ function useFilter(config, filterMethod, tree = {
8878
8901
  }
8879
8902
  const children = node.children;
8880
8903
  if (children) {
8881
- const { count: childCount, total: childTotal } = traverse(children, filterAll ? false : expandKeySet.has(node.key));
8904
+ const { count: childCount, total: childTotal, hasFilterResult: childHasFilterResult } = traverse(children, filterAll ? false : expandKeySet.has(node.key));
8882
8905
  node.count = childCount;
8883
8906
  node.total = childTotal;
8884
8907
  count += childCount;
8885
8908
  total += childTotal;
8909
+ hasFilterResult = hasFilterResult || childHasFilterResult;
8910
+ if (childHasFilterResult) {
8911
+ resultExpandKeySet.add(node.key);
8912
+ }
8886
8913
  }
8887
8914
  else if (!hiddenKeys.has(node.key)) {
8888
8915
  if (node.data.dataType !== 4) {
@@ -8917,10 +8944,10 @@ function useFilter(config, filterMethod, tree = {
8917
8944
  }
8918
8945
  family.pop();
8919
8946
  });
8920
- return { count, total };
8947
+ return { count, total, hasFilterResult };
8921
8948
  }
8922
8949
  traverse(nodes);
8923
- return expandKeySet;
8950
+ return { expandKeySet, resultExpandKeySet };
8924
8951
  }
8925
8952
  function isForceHiddenExpandIcon(node) {
8926
8953
  return hiddenExpandIconKeySet.has(node.key);
@@ -10423,16 +10450,20 @@ class VirtualTree {
10423
10450
  business: this._business,
10424
10451
  businessConfig: this._businessConfig
10425
10452
  }, this._filterMethod, this._tree);
10426
- const keys = doFilter(params, filterAll);
10427
- if (keys) {
10453
+ const filterResult = doFilter(params, filterAll);
10454
+ if (filterResult) {
10455
+ const { expandKeySet, resultExpandKeySet } = filterResult;
10428
10456
  const expandModel = params ? this._props.filterExpandModel : this._props.defaultExpandModel;
10429
10457
  if (expandModel === 'all') {
10430
- this._expandedKeySet = keys;
10458
+ this._expandedKeySet = expandKeySet;
10431
10459
  }
10432
10460
  else if (expandModel === 'first') {
10433
- const keysList = Array.from(keys.values());
10461
+ const keysList = Array.from(expandKeySet.values());
10434
10462
  this._expandedKeySet = new Set([keysList[0]].filter(Boolean));
10435
10463
  }
10464
+ else if (expandModel === 'result') {
10465
+ this._expandedKeySet = resultExpandKeySet;
10466
+ }
10436
10467
  this._hiddenExpandIconKeySet = hiddenExpandIconKeySet;
10437
10468
  this._hiddenNodeKeySet = hiddenNodeKeySet;
10438
10469
  this._isRenderInitial = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hy-virtual-tree",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",