hy-virtual-tree 2.1.4 → 2.3.0

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.3.0
4
+
5
+ _2026-06-01_
6
+
7
+ (1)新增 renderLabel 自定义节点文本
8
+
9
+ ### 2.2.0
10
+
11
+ _2026-06-01_
12
+
13
+ (1)新增 filterMethod参数的返回参数,可按需判断每一项是否要独立校验
14
+
3
15
  ### 2.1.4
4
16
 
5
17
  _2026-05-28_
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* hy-virtual-tree v2.1.4 */
1
+ /* hy-virtual-tree v2.3.0 */
2
2
  import './svg_bundle.js';
3
3
  const isString = (e) => typeof e === 'string';
4
4
  const isNumber = (e) => typeof e === 'number';
@@ -8682,6 +8682,13 @@ function useFilter(config, filterMethod, tree = {
8682
8682
  const hiddenNodeKeySet = new Set([]);
8683
8683
  const hiddenExpandIconKeySet = new Set([]);
8684
8684
  let doFilter;
8685
+ function useFilterMethod(filterMethod, filterAll, ...args) {
8686
+ const params = filterMethod(...args);
8687
+ if (isObject(params)) {
8688
+ return { type: params.force ? 'all' : 'default', value: params.value };
8689
+ }
8690
+ return { type: filterAll ? 'all' : 'default', value: params };
8691
+ }
8685
8692
  // 通用过滤方法
8686
8693
  function commitFilter(params, filterAll = true) {
8687
8694
  if (!isFunction(filterMethod)) {
@@ -8702,11 +8709,12 @@ function useFilter(config, filterMethod, tree = {
8702
8709
  let total = 0;
8703
8710
  let hasFilterResult = false;
8704
8711
  nodes.forEach((node) => {
8712
+ const { type: filterType, value: filterValue } = useFilterMethod(filterMethod, filterAll, params, node.data, node);
8705
8713
  family.push(node);
8706
8714
  if (!hasFilterResult) {
8707
- hasFilterResult = !!(filterMethod && filterMethod(params, node.data, node));
8715
+ hasFilterResult = filterValue;
8708
8716
  }
8709
- if (isShow || (filterMethod && filterMethod(params, node.data, node))) {
8717
+ if ((isShow && filterType !== 'all') || filterValue) {
8710
8718
  family.forEach((member) => {
8711
8719
  expandKeySet.add(member.key);
8712
8720
  });
@@ -8793,11 +8801,12 @@ function useFilter(config, filterMethod, tree = {
8793
8801
  let hasFilterResult = false;
8794
8802
  nodes.forEach((node) => {
8795
8803
  const isLeaf = isFilterLeaf(node);
8804
+ const { type: filterType, value: filterValue } = useFilterMethod(filterMethod, filterAll, params, node.data, node);
8796
8805
  family.push(node);
8797
8806
  if (!hasFilterResult) {
8798
- hasFilterResult = !!(filterMethod && filterMethod(params, node.data, node));
8807
+ hasFilterResult = filterValue;
8799
8808
  }
8800
- if (isShow || (filterMethod && filterMethod(params, node.data, node))) {
8809
+ if ((isShow && filterType !== 'all') || filterValue) {
8801
8810
  family.forEach((member) => {
8802
8811
  expandKeySet.add(member.key);
8803
8812
  });
@@ -8886,12 +8895,13 @@ function useFilter(config, filterMethod, tree = {
8886
8895
  let total = 0;
8887
8896
  let hasFilterResult = false;
8888
8897
  nodes.forEach((node) => {
8898
+ const { type: filterType, value: filterValue } = useFilterMethod(filterMethod, filterAll, params, node.data, node);
8889
8899
  family.push(node);
8890
8900
  if (!hasFilterResult) {
8891
- hasFilterResult = !!(filterMethod && filterMethod(params, node.data, node));
8901
+ hasFilterResult = filterValue;
8892
8902
  }
8893
8903
  // if (tree.hiddenNodeKeySet.has(node.key)) return
8894
- if (isShow || (filterMethod && filterMethod(params, node.data, node))) {
8904
+ if ((isShow && filterType !== 'all') || filterValue) {
8895
8905
  family.forEach((member) => {
8896
8906
  expandKeySet.add(member.key);
8897
8907
  });
@@ -9069,14 +9079,28 @@ const useIcon = (config, data, node) => {
9069
9079
  return new Icon({ svgName: 'hy-tree-personnel', width: 16, height: 16 });
9070
9080
  }
9071
9081
  };
9082
+ // 获取节点文本处理
9083
+ const getLabelHandler = (data, node, config) => {
9084
+ if (config.renderLabel && isFunction(config.renderLabel)) {
9085
+ const value = config.renderLabel(data, node);
9086
+ if (isBoolean(value) && value) {
9087
+ return node.label || '';
9088
+ }
9089
+ else {
9090
+ return value || '';
9091
+ }
9092
+ }
9093
+ return node.label || '';
9094
+ };
9072
9095
  // 生成内容节点
9073
- const useContent = (data, node) => {
9096
+ const useContent = (data, node, config) => {
9074
9097
  return createVNode('div', (vnode) => {
9075
- vnode.el.innerHTML = node.label || '';
9076
- if (node.label) {
9098
+ const label = getLabelHandler(data, node, config);
9099
+ vnode.el.innerHTML = label;
9100
+ if (label) {
9077
9101
  const tooltip = new Tooltip({
9078
9102
  bind: vnode.el,
9079
- content: node.label,
9103
+ content: label,
9080
9104
  placement: 'top',
9081
9105
  trigger: 'hover-overflow'
9082
9106
  });
@@ -9098,11 +9122,11 @@ const generateTotalStats = (data, node) => {
9098
9122
  };
9099
9123
  // 自定义渲染元素
9100
9124
  const customRender = (options) => {
9101
- const { fn, node, parent, className, defaultFn } = options || {};
9125
+ const { fn, node, parent, className, config, defaultFn } = options || {};
9102
9126
  let value;
9103
9127
  // 没有传入的自定义函数则使用默认函数
9104
9128
  if (!fn || !isFunction(fn)) {
9105
- value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node) : undefined;
9129
+ value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node, config) : undefined;
9106
9130
  }
9107
9131
  // 自定义函数处理
9108
9132
  else {
@@ -9121,7 +9145,7 @@ const customRender = (options) => {
9121
9145
  return value;
9122
9146
  }
9123
9147
  if (isBoolean(value) && value) {
9124
- value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node) : undefined;
9148
+ value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node, config) : undefined;
9125
9149
  if (value) {
9126
9150
  className && value.el.classList.add(className);
9127
9151
  parent && value.mount(parent);
@@ -9844,13 +9868,14 @@ class VirtualTree {
9844
9868
  fn: config.renderStatus,
9845
9869
  node: item,
9846
9870
  className: 'hy-tree-node__status',
9871
+ config,
9847
9872
  defaultFn: (data, node) => {
9848
9873
  return useStatus(config, data);
9849
9874
  }
9850
9875
  });
9851
9876
  }
9852
9877
  // 右侧内容
9853
- rightSlot = customRender({ fn: config.renderRight, node: item, className: 'hy-tree-node__right-content' });
9878
+ rightSlot = customRender({ fn: config.renderRight, node: item, className: 'hy-tree-node__right-content', config });
9854
9879
  if (!statusSlot && !rightSlot)
9855
9880
  return;
9856
9881
  return createVNode('div', (vnode) => {
@@ -9966,17 +9991,18 @@ class VirtualTree {
9966
9991
  node: item,
9967
9992
  parent: contentContainer,
9968
9993
  className: 'hy-tree-node__node-content',
9969
- defaultFn: (data, node) => {
9994
+ config,
9995
+ defaultFn: (data, node, config) => {
9970
9996
  // 图标
9971
- customRender({ fn: config.renderIcon, node, parent: contentContainer, className: 'hy-tree-icon', defaultFn: generateIcon });
9997
+ customRender({ fn: config.renderIcon, node, parent: contentContainer, className: 'hy-tree-icon', config, defaultFn: generateIcon });
9972
9998
  // 内容
9973
- customRender({ fn: config.renderContent, node, parent: contentContainer, className: 'hy-tree-node__content', defaultFn: useContent });
9999
+ customRender({ fn: config.renderContent, node, parent: contentContainer, className: 'hy-tree-node__content', config, defaultFn: useContent });
9974
10000
  // 统计
9975
10001
  if (isShowCount(this._props.showCount, item)) {
9976
- customRender({ fn: config.renderStats, node, parent: contentContainer, className: 'hy-tree-node__statistics', defaultFn: this._props.statsModel === 'total' ? generateTotalStats : generateStats });
10002
+ customRender({ fn: config.renderStats, node, parent: contentContainer, className: 'hy-tree-node__statistics', config, defaultFn: this._props.statsModel === 'total' ? generateTotalStats : generateStats });
9977
10003
  }
9978
10004
  // 右侧内容
9979
- customRender({ fn: generateRight, node, parent: contentContainer });
10005
+ customRender({ fn: generateRight, node, parent: contentContainer, config });
9980
10006
  }
9981
10007
  });
9982
10008
  // 挂载内容容器
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hy-virtual-tree",
3
- "version": "2.1.4",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",