hy-virtual-tree 1.1.15 → 1.1.17
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 +14 -0
- package/dist/index.js +49 -46
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
### 1.1.17
|
|
4
|
+
|
|
5
|
+
_2025-09-10_
|
|
6
|
+
|
|
7
|
+
- 扩展[VirtualTree] 功能
|
|
8
|
+
(1)CustomRenderFn 内置一层dom元素,兼容vue2的new Vue()挂载问题
|
|
9
|
+
|
|
10
|
+
### 1.1.16
|
|
11
|
+
|
|
12
|
+
_2025-09-09_
|
|
13
|
+
|
|
14
|
+
- 扩展[VirtualTree] 功能
|
|
15
|
+
(1)CustomRenderFn 函数类型添加 true返回类型,当返回 true 时,会使用默认渲染逻辑
|
|
16
|
+
|
|
3
17
|
### 1.1.15
|
|
4
18
|
|
|
5
19
|
_2025-09-04_
|
package/dist/index.js
CHANGED
|
@@ -1400,10 +1400,26 @@ function getContainer(config) {
|
|
|
1400
1400
|
return el;
|
|
1401
1401
|
}
|
|
1402
1402
|
/** 获取自定义元素函数的值 */
|
|
1403
|
-
function customRender(fn, node,
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1403
|
+
function customRender(fn, node, options) {
|
|
1404
|
+
const { parent, className, defaultFn } = options || {};
|
|
1405
|
+
let value;
|
|
1406
|
+
if (!fn || !isFunction(fn)) {
|
|
1407
|
+
value = defaultFn && isFunction(defaultFn) && defaultFn(node.data, node);
|
|
1408
|
+
}
|
|
1409
|
+
else {
|
|
1410
|
+
const dom = fn(node.data, node);
|
|
1411
|
+
if (isBoolean(dom) && dom) {
|
|
1412
|
+
value = defaultFn && isFunction(defaultFn) && defaultFn(node.data, node);
|
|
1413
|
+
}
|
|
1414
|
+
else if (isElement(dom)) {
|
|
1415
|
+
value = document.createElement('div');
|
|
1416
|
+
className && value.classList.add(className);
|
|
1417
|
+
value.appendChild(dom);
|
|
1418
|
+
}
|
|
1419
|
+
else {
|
|
1420
|
+
value = dom;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1407
1423
|
if (isEmpty(value))
|
|
1408
1424
|
return;
|
|
1409
1425
|
if (isElement(value)) {
|
|
@@ -1769,7 +1785,6 @@ class VirtualTree {
|
|
|
1769
1785
|
this._refreshRender();
|
|
1770
1786
|
};
|
|
1771
1787
|
const useRenderItems = (config) => {
|
|
1772
|
-
const { renderIcon, renderItem, renderContent, renderStatus, renderRight, onNodeClick, onNodeContextmenu } = config;
|
|
1773
1788
|
/** 生成展开图标 */
|
|
1774
1789
|
const generateExpandIcon = (item) => {
|
|
1775
1790
|
const el = document.createElement('div');
|
|
@@ -1797,8 +1812,6 @@ class VirtualTree {
|
|
|
1797
1812
|
};
|
|
1798
1813
|
/** 生成图标 */
|
|
1799
1814
|
const generateIcon = (data, item) => {
|
|
1800
|
-
if (renderIcon)
|
|
1801
|
-
return renderIcon(data, item);
|
|
1802
1815
|
const icon = useIcon(config, data);
|
|
1803
1816
|
if (!icon)
|
|
1804
1817
|
return;
|
|
@@ -1806,12 +1819,8 @@ class VirtualTree {
|
|
|
1806
1819
|
};
|
|
1807
1820
|
/** 生成内容 */
|
|
1808
1821
|
const generateContent = (data, item) => {
|
|
1809
|
-
if (renderContent)
|
|
1810
|
-
return renderContent(data, item);
|
|
1811
1822
|
const el = document.createElement('div');
|
|
1812
|
-
|
|
1813
|
-
el.innerHTML = item.label;
|
|
1814
|
-
}
|
|
1823
|
+
el.innerHTML = item.label || '';
|
|
1815
1824
|
return el;
|
|
1816
1825
|
};
|
|
1817
1826
|
/** 生成统计 */
|
|
@@ -1828,18 +1837,14 @@ class VirtualTree {
|
|
|
1828
1837
|
let statusSlot, rightSlot;
|
|
1829
1838
|
// 是否显示状态
|
|
1830
1839
|
if (this._props.showStatus) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
}
|
|
1835
|
-
// 业务状态
|
|
1836
|
-
else {
|
|
1837
|
-
statusSlot = useStatus(config, data);
|
|
1838
|
-
}
|
|
1840
|
+
statusSlot = customRender(config.renderStatus, item, {
|
|
1841
|
+
className: 'hy-tree-node__status',
|
|
1842
|
+
defaultFn: (data, node) => useStatus(config, data)
|
|
1843
|
+
});
|
|
1839
1844
|
}
|
|
1840
1845
|
// 右侧内容
|
|
1841
|
-
if (renderRight) {
|
|
1842
|
-
rightSlot = customRender(renderRight, item,
|
|
1846
|
+
if (config.renderRight) {
|
|
1847
|
+
rightSlot = customRender(config.renderRight, item, { className: 'hy-tree-node__right-content' });
|
|
1843
1848
|
}
|
|
1844
1849
|
if (!isElement(statusSlot) && !isElement(rightSlot))
|
|
1845
1850
|
return;
|
|
@@ -1904,7 +1909,7 @@ class VirtualTree {
|
|
|
1904
1909
|
? showSelect
|
|
1905
1910
|
: isFunction(showSelect) && showSelect(item.data, item)) && config.rowSelection.showSelectBox) {
|
|
1906
1911
|
if (type === 'checkbox') {
|
|
1907
|
-
|
|
1912
|
+
new Checkbox({
|
|
1908
1913
|
checked: isChecked(item),
|
|
1909
1914
|
disabled: getDisabled(config, item),
|
|
1910
1915
|
indeterminate: isIndeterminate(item),
|
|
@@ -1918,11 +1923,10 @@ class VirtualTree {
|
|
|
1918
1923
|
}
|
|
1919
1924
|
this.refresh();
|
|
1920
1925
|
}
|
|
1921
|
-
});
|
|
1922
|
-
checkbox.mount(content);
|
|
1926
|
+
}).mount(content);
|
|
1923
1927
|
}
|
|
1924
1928
|
else if (type === 'radio') {
|
|
1925
|
-
|
|
1929
|
+
new Radio({
|
|
1926
1930
|
checked: isChecked(item),
|
|
1927
1931
|
disabled: getDisabled(config, item),
|
|
1928
1932
|
onClick: () => {
|
|
@@ -1930,25 +1934,24 @@ class VirtualTree {
|
|
|
1930
1934
|
toggleCheckbox(item, checked, true, false);
|
|
1931
1935
|
this.refresh();
|
|
1932
1936
|
}
|
|
1933
|
-
});
|
|
1934
|
-
radio.mount(content);
|
|
1937
|
+
}).mount(content);
|
|
1935
1938
|
}
|
|
1936
1939
|
}
|
|
1937
|
-
//
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
}
|
|
1940
|
+
// 整个节点内容
|
|
1941
|
+
customRender(config.renderItem, item, {
|
|
1942
|
+
parent: content,
|
|
1943
|
+
className: 'hy-tree-node__node-content',
|
|
1944
|
+
defaultFn: (data, node) => {
|
|
1945
|
+
// 图标
|
|
1946
|
+
customRender(config.renderIcon, node, { parent: content, className: 'hy-tree-icon', defaultFn: generateIcon });
|
|
1947
|
+
// 内容
|
|
1948
|
+
customRender(config.renderContent, node, { parent: content, className: 'hy-tree-node__content', defaultFn: generateContent });
|
|
1949
|
+
// 统计
|
|
1950
|
+
customRender(generateStats, node, { parent: content });
|
|
1951
|
+
// 右侧内容
|
|
1952
|
+
customRender(generateRight, node, { parent: content });
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1952
1955
|
nodeContainer.appendChild(content);
|
|
1953
1956
|
let nodeClickTimer;
|
|
1954
1957
|
let nodeClickCount = 0;
|
|
@@ -1973,7 +1976,7 @@ class VirtualTree {
|
|
|
1973
1976
|
this._expandedHandle(item);
|
|
1974
1977
|
this._refreshVirtualScroll();
|
|
1975
1978
|
}
|
|
1976
|
-
onNodeClick && onNodeClick(item.data, item, e);
|
|
1979
|
+
config.onNodeClick && config.onNodeClick(item.data, item, e);
|
|
1977
1980
|
};
|
|
1978
1981
|
// 鼠标左键点击事件
|
|
1979
1982
|
nodeContainer.addEventListener('click', (e) => {
|
|
@@ -2011,8 +2014,8 @@ class VirtualTree {
|
|
|
2011
2014
|
});
|
|
2012
2015
|
// 鼠标右键点击事件
|
|
2013
2016
|
nodeContainer.addEventListener('contextmenu', (e) => {
|
|
2014
|
-
if (onNodeContextmenu) {
|
|
2015
|
-
onNodeContextmenu(item.data, item, e);
|
|
2017
|
+
if (config.onNodeContextmenu) {
|
|
2018
|
+
config.onNodeContextmenu(item.data, item, e);
|
|
2016
2019
|
e.preventDefault();
|
|
2017
2020
|
}
|
|
2018
2021
|
});
|