hy-virtual-tree 2.2.0 → 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,11 @@
1
1
  ## Changelog
2
2
 
3
+ ### 2.3.0
4
+
5
+ _2026-06-01_
6
+
7
+ (1)新增 renderLabel 自定义节点文本
8
+
3
9
  ### 2.2.0
4
10
 
5
11
  _2026-06-01_
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* hy-virtual-tree v2.2.0 */
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';
@@ -9079,14 +9079,28 @@ const useIcon = (config, data, node) => {
9079
9079
  return new Icon({ svgName: 'hy-tree-personnel', width: 16, height: 16 });
9080
9080
  }
9081
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
+ };
9082
9095
  // 生成内容节点
9083
- const useContent = (data, node) => {
9096
+ const useContent = (data, node, config) => {
9084
9097
  return createVNode('div', (vnode) => {
9085
- vnode.el.innerHTML = node.label || '';
9086
- if (node.label) {
9098
+ const label = getLabelHandler(data, node, config);
9099
+ vnode.el.innerHTML = label;
9100
+ if (label) {
9087
9101
  const tooltip = new Tooltip({
9088
9102
  bind: vnode.el,
9089
- content: node.label,
9103
+ content: label,
9090
9104
  placement: 'top',
9091
9105
  trigger: 'hover-overflow'
9092
9106
  });
@@ -9108,11 +9122,11 @@ const generateTotalStats = (data, node) => {
9108
9122
  };
9109
9123
  // 自定义渲染元素
9110
9124
  const customRender = (options) => {
9111
- const { fn, node, parent, className, defaultFn } = options || {};
9125
+ const { fn, node, parent, className, config, defaultFn } = options || {};
9112
9126
  let value;
9113
9127
  // 没有传入的自定义函数则使用默认函数
9114
9128
  if (!fn || !isFunction(fn)) {
9115
- value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node) : undefined;
9129
+ value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node, config) : undefined;
9116
9130
  }
9117
9131
  // 自定义函数处理
9118
9132
  else {
@@ -9131,7 +9145,7 @@ const customRender = (options) => {
9131
9145
  return value;
9132
9146
  }
9133
9147
  if (isBoolean(value) && value) {
9134
- value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node) : undefined;
9148
+ value = defaultFn && isFunction(defaultFn) ? defaultFn(node.data, node, config) : undefined;
9135
9149
  if (value) {
9136
9150
  className && value.el.classList.add(className);
9137
9151
  parent && value.mount(parent);
@@ -9854,13 +9868,14 @@ class VirtualTree {
9854
9868
  fn: config.renderStatus,
9855
9869
  node: item,
9856
9870
  className: 'hy-tree-node__status',
9871
+ config,
9857
9872
  defaultFn: (data, node) => {
9858
9873
  return useStatus(config, data);
9859
9874
  }
9860
9875
  });
9861
9876
  }
9862
9877
  // 右侧内容
9863
- 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 });
9864
9879
  if (!statusSlot && !rightSlot)
9865
9880
  return;
9866
9881
  return createVNode('div', (vnode) => {
@@ -9976,17 +9991,18 @@ class VirtualTree {
9976
9991
  node: item,
9977
9992
  parent: contentContainer,
9978
9993
  className: 'hy-tree-node__node-content',
9979
- defaultFn: (data, node) => {
9994
+ config,
9995
+ defaultFn: (data, node, config) => {
9980
9996
  // 图标
9981
- 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 });
9982
9998
  // 内容
9983
- 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 });
9984
10000
  // 统计
9985
10001
  if (isShowCount(this._props.showCount, item)) {
9986
- 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 });
9987
10003
  }
9988
10004
  // 右侧内容
9989
- customRender({ fn: generateRight, node, parent: contentContainer });
10005
+ customRender({ fn: generateRight, node, parent: contentContainer, config });
9990
10006
  }
9991
10007
  });
9992
10008
  // 挂载内容容器
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hy-virtual-tree",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",