hy-virtual-tree 1.1.15 → 1.1.16
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 +7 -0
- package/dist/index.js +42 -46
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1400,10 +1400,18 @@ 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
|
+
value = fn(node.data, node);
|
|
1411
|
+
if (isBoolean(value) && value) {
|
|
1412
|
+
value = defaultFn && isFunction(defaultFn) && defaultFn(node.data, node);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1407
1415
|
if (isEmpty(value))
|
|
1408
1416
|
return;
|
|
1409
1417
|
if (isElement(value)) {
|
|
@@ -1769,7 +1777,6 @@ class VirtualTree {
|
|
|
1769
1777
|
this._refreshRender();
|
|
1770
1778
|
};
|
|
1771
1779
|
const useRenderItems = (config) => {
|
|
1772
|
-
const { renderIcon, renderItem, renderContent, renderStatus, renderRight, onNodeClick, onNodeContextmenu } = config;
|
|
1773
1780
|
/** 生成展开图标 */
|
|
1774
1781
|
const generateExpandIcon = (item) => {
|
|
1775
1782
|
const el = document.createElement('div');
|
|
@@ -1797,8 +1804,6 @@ class VirtualTree {
|
|
|
1797
1804
|
};
|
|
1798
1805
|
/** 生成图标 */
|
|
1799
1806
|
const generateIcon = (data, item) => {
|
|
1800
|
-
if (renderIcon)
|
|
1801
|
-
return renderIcon(data, item);
|
|
1802
1807
|
const icon = useIcon(config, data);
|
|
1803
1808
|
if (!icon)
|
|
1804
1809
|
return;
|
|
@@ -1806,12 +1811,9 @@ class VirtualTree {
|
|
|
1806
1811
|
};
|
|
1807
1812
|
/** 生成内容 */
|
|
1808
1813
|
const generateContent = (data, item) => {
|
|
1809
|
-
|
|
1810
|
-
return renderContent(data, item);
|
|
1814
|
+
console.log("generateContent??", item);
|
|
1811
1815
|
const el = document.createElement('div');
|
|
1812
|
-
|
|
1813
|
-
el.innerHTML = item.label;
|
|
1814
|
-
}
|
|
1816
|
+
el.innerHTML = item.label || '';
|
|
1815
1817
|
return el;
|
|
1816
1818
|
};
|
|
1817
1819
|
/** 生成统计 */
|
|
@@ -1828,18 +1830,14 @@ class VirtualTree {
|
|
|
1828
1830
|
let statusSlot, rightSlot;
|
|
1829
1831
|
// 是否显示状态
|
|
1830
1832
|
if (this._props.showStatus) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
}
|
|
1835
|
-
// 业务状态
|
|
1836
|
-
else {
|
|
1837
|
-
statusSlot = useStatus(config, data);
|
|
1838
|
-
}
|
|
1833
|
+
statusSlot = customRender(config.renderStatus, item, {
|
|
1834
|
+
className: 'hy-tree-node__status',
|
|
1835
|
+
defaultFn: (data, node) => useStatus(config, data)
|
|
1836
|
+
});
|
|
1839
1837
|
}
|
|
1840
1838
|
// 右侧内容
|
|
1841
|
-
if (renderRight) {
|
|
1842
|
-
rightSlot = customRender(renderRight, item,
|
|
1839
|
+
if (config.renderRight) {
|
|
1840
|
+
rightSlot = customRender(config.renderRight, item, { className: 'hy-tree-node__right-content' });
|
|
1843
1841
|
}
|
|
1844
1842
|
if (!isElement(statusSlot) && !isElement(rightSlot))
|
|
1845
1843
|
return;
|
|
@@ -1904,7 +1902,7 @@ class VirtualTree {
|
|
|
1904
1902
|
? showSelect
|
|
1905
1903
|
: isFunction(showSelect) && showSelect(item.data, item)) && config.rowSelection.showSelectBox) {
|
|
1906
1904
|
if (type === 'checkbox') {
|
|
1907
|
-
|
|
1905
|
+
new Checkbox({
|
|
1908
1906
|
checked: isChecked(item),
|
|
1909
1907
|
disabled: getDisabled(config, item),
|
|
1910
1908
|
indeterminate: isIndeterminate(item),
|
|
@@ -1918,11 +1916,10 @@ class VirtualTree {
|
|
|
1918
1916
|
}
|
|
1919
1917
|
this.refresh();
|
|
1920
1918
|
}
|
|
1921
|
-
});
|
|
1922
|
-
checkbox.mount(content);
|
|
1919
|
+
}).mount(content);
|
|
1923
1920
|
}
|
|
1924
1921
|
else if (type === 'radio') {
|
|
1925
|
-
|
|
1922
|
+
new Radio({
|
|
1926
1923
|
checked: isChecked(item),
|
|
1927
1924
|
disabled: getDisabled(config, item),
|
|
1928
1925
|
onClick: () => {
|
|
@@ -1930,25 +1927,24 @@ class VirtualTree {
|
|
|
1930
1927
|
toggleCheckbox(item, checked, true, false);
|
|
1931
1928
|
this.refresh();
|
|
1932
1929
|
}
|
|
1933
|
-
});
|
|
1934
|
-
radio.mount(content);
|
|
1930
|
+
}).mount(content);
|
|
1935
1931
|
}
|
|
1936
1932
|
}
|
|
1937
|
-
//
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
}
|
|
1933
|
+
// 整个节点内容
|
|
1934
|
+
customRender(config.renderItem, item, {
|
|
1935
|
+
parent: content,
|
|
1936
|
+
className: 'hy-tree-node__node-content',
|
|
1937
|
+
defaultFn: (data, node) => {
|
|
1938
|
+
// 图标
|
|
1939
|
+
customRender(config.renderIcon, node, { parent: content, className: 'hy-tree-icon', defaultFn: generateIcon });
|
|
1940
|
+
// 内容
|
|
1941
|
+
customRender(config.renderContent, node, { parent: content, className: 'hy-tree-node__content', defaultFn: generateContent });
|
|
1942
|
+
// 统计
|
|
1943
|
+
customRender(generateStats, node, { parent: content });
|
|
1944
|
+
// 右侧内容
|
|
1945
|
+
customRender(generateRight, node, { parent: content });
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1952
1948
|
nodeContainer.appendChild(content);
|
|
1953
1949
|
let nodeClickTimer;
|
|
1954
1950
|
let nodeClickCount = 0;
|
|
@@ -1973,7 +1969,7 @@ class VirtualTree {
|
|
|
1973
1969
|
this._expandedHandle(item);
|
|
1974
1970
|
this._refreshVirtualScroll();
|
|
1975
1971
|
}
|
|
1976
|
-
onNodeClick && onNodeClick(item.data, item, e);
|
|
1972
|
+
config.onNodeClick && config.onNodeClick(item.data, item, e);
|
|
1977
1973
|
};
|
|
1978
1974
|
// 鼠标左键点击事件
|
|
1979
1975
|
nodeContainer.addEventListener('click', (e) => {
|
|
@@ -2011,8 +2007,8 @@ class VirtualTree {
|
|
|
2011
2007
|
});
|
|
2012
2008
|
// 鼠标右键点击事件
|
|
2013
2009
|
nodeContainer.addEventListener('contextmenu', (e) => {
|
|
2014
|
-
if (onNodeContextmenu) {
|
|
2015
|
-
onNodeContextmenu(item.data, item, e);
|
|
2010
|
+
if (config.onNodeContextmenu) {
|
|
2011
|
+
config.onNodeContextmenu(item.data, item, e);
|
|
2016
2012
|
e.preventDefault();
|
|
2017
2013
|
}
|
|
2018
2014
|
});
|