We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
数据量测试:在开启拖拽的情况下,当展开的节点超过300项左右,快速拖拽会发生卡顿。该卡顿并非直接受到treeData数据量的影响,例如treeData节点数处于1w左右,但其中展开的节点少于300,拖拽基本流畅。
初步排查:是因为在快速拖拽时,由于dragPosition快速变化,而导致多次渲染,因而发生卡顿。
() => { const [selected, setSelected] = useState(new Set()); const [selectedThroughParent, setSelectedThroughParent] = useState(new Set()); function generateData(x = 5, y = 4, z = 3, gData = []) { // x:每一级下的节点总数。y:每级节点里有y个节点、存在子节点。z:树的level层级数(0表示一级) function _loop(_level, _preKey, _tns) { const preKey = _preKey || '0'; const tns = _tns || gData; const children = []; for (let i = 0; i < x; i++) { const key = `${preKey}-${i}`; tns.push({ label: `${key}-标签`, key: `${key}-key`, value: `${key}-value` }); if (i < y) { children.push(key); } } if (_level < 0) { return tns; } const __level = _level - 1; children.forEach((key, index) => { tns[index].children = []; return _loop(__level, key, tns[index].children); }); return null; } _loop(z); function calcTotal(x, y, z) { const rec = n => (n >= 0 ? x * y ** n-- + rec(n) : 0); return rec(z + 1); } return { gData, total: calcTotal(x, y, z) }; } const [treeData, setTreeData] = useState(generateData().gData); const onDrop = (info) => { const { dropToGap, node, dragNode } = info; const dropKey = node.key; const dragKey = dragNode.key; const dropPos = node.pos.split('-'); const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); const data = [...treeData]; const loop = (data, key, callback) => { data.forEach((item, ind, arr) => { if (item.key === key) return callback(item, ind, arr); if (item.children) return loop(item.children, key, callback); }); }; let dragObj; loop(data, dragKey, (item, ind, arr) => { arr.splice(ind, 1); dragObj = item; }); if (!dropToGap) { loop(data, dropKey, (item, ind, arr) => { item.children = item.children || []; item.children.push(dragObj); }); } else if (dropPosition === 1 && node.children && node.expanded) { loop(data, dropKey, item => { item.children = item.children || []; item.children.unshift(dragObj); }); } else { let dropNodeInd; let dropNodePosArr; loop(data, dropKey, (item, ind, arr) => { dropNodePosArr = arr; dropNodeInd = ind; }); if (dropPosition === -1) { dropNodePosArr.splice(dropNodeInd, 0, dragObj); } else { dropNodePosArr.splice(dropNodeInd + 1, 0, dragObj); } } setTreeData(data); }; const findDescendantKeys = (node) => { const res = [node.key]; const findChild = item => { if (!item) return; const { children } = item; if (children && children.length) { children.forEach(child => { res.push(child.key); findChild(child); }); } }; findChild(node); return res; }; const handleSelect = (key, bool, node) => { setSelected(new Set([key])); const descendantKeys = findDescendantKeys(node); setSelectedThroughParent(new Set(descendantKeys)); }; const renderLabel = ({ className, data, onClick, expandIcon }) => { const { label, icon, key } = data; const isLeaf = !(data.children && data.children.length); const style = { backgroundColor: selected.has(key) ? 'rgba(var(--semi-blue-0), 1)' : selectedThroughParent.has(key) ? 'rgba(var(--semi-blue-0), .5)' : 'transparent' }; return ( <li className={className} role="treeitem" onClick={onClick} style={style} > {isLeaf ? <span style={{ width: 24 }}></span> : expandIcon} {icon} <span>{label}</span> </li> ); }; const treeStyle = { width: 260, height: 420, border: '1px solid var(--semi-color-border)' }; return <Tree treeData={treeData} draggable onDrop={onDrop} // renderFullLabel={renderLabel} onSelect={handleSelect} style={treeStyle} defaultExpandAll />; };
The text was updated successfully, but these errors were encountered:
boomboomchen
No branches or pull requests
Which Component 出现bug的组件
semi-ui version
Expected result 期望的结果是什么
Actual result 实际的结果是什么
Steps to reproduce 问题描述
数据量测试:在开启拖拽的情况下,当展开的节点超过300项左右,快速拖拽会发生卡顿。该卡顿并非直接受到treeData数据量的影响,例如treeData节点数处于1w左右,但其中展开的节点少于300,拖拽基本流畅。
初步排查:是因为在快速拖拽时,由于dragPosition快速变化,而导致多次渲染,因而发生卡顿。
Reproducible code 复现代码
Additional information 补充说明
The text was updated successfully, but these errors were encountered: