Fix:优化性能模式的懒加载

This commit is contained in:
街角小林 2024-07-26 10:15:54 +08:00
parent 497c2606df
commit 95fdb35f7b
2 changed files with 39 additions and 17 deletions

View File

@ -155,9 +155,13 @@ class Render {
const onViewDataChange = throttle(() => { const onViewDataChange = throttle(() => {
if (this.root) { if (this.root) {
this.mindMap.emit('node_tree_render_start') this.mindMap.emit('node_tree_render_start')
this.root.render(() => { this.root.render(
this.mindMap.emit('node_tree_render_end') () => {
}) this.mindMap.emit('node_tree_render_end')
},
false,
true
)
} }
}, performanceConfig.time) }, performanceConfig.time)
let lastOpen = false let lastOpen = false

View File

@ -771,8 +771,10 @@ class Node {
} }
} }
// 递归渲染 // 递归渲染
render(callback = () => {}, forceRender = false) { // forceRender强制渲染无论是否处于画布可视区域
// async异步渲染
render(callback = () => {}, forceRender = false, async = false) {
// 节点 // 节点
// 重新渲染连线 // 重新渲染连线
this.renderLine() this.renderLine()
@ -806,7 +808,7 @@ class Node {
this.update(forceRender) this.update(forceRender)
} }
} else if (openPerformance && performanceConfig.removeNodeWhenOutCanvas) { } else if (openPerformance && performanceConfig.removeNodeWhenOutCanvas) {
this.remove(true) this.removeSelf()
} }
// 子节点 // 子节点
if ( if (
@ -816,12 +818,23 @@ class Node {
) { ) {
let index = 0 let index = 0
this.children.forEach(item => { this.children.forEach(item => {
item.render(() => { const renderChild = () => {
index++ item.render(
if (index >= this.children.length) { () => {
callback() index++
} if (index >= this.children.length) {
}, forceRender) callback()
}
},
forceRender,
async
)
}
if (async) {
setTimeout(renderChild, 0)
} else {
renderChild()
}
}) })
} else { } else {
callback() callback()
@ -836,14 +849,19 @@ class Node {
} }
} }
// 递归删除,只是从画布删除,节点容器还在,后续还可以重新插回画布 // 删除自身,只是从画布删除,节点容器还在,后续还可以重新插回画布
remove(keepLine = false) { removeSelf() {
if (!this.group) return if (!this.group) return
this.group.remove() this.group.remove()
this.removeGeneralization() this.removeGeneralization()
if (!keepLine) { }
this.removeLine()
} // 递归删除,只是从画布删除,节点容器还在,后续还可以重新插回画布
remove() {
if (!this.group) return
this.group.remove()
this.removeGeneralization()
this.removeLine()
// 子节点 // 子节点
if (this.children && this.children.length) { if (this.children && this.children.length) {
this.children.forEach(item => { this.children.forEach(item => {