优化代码:1.将render类的setNodeActive方法的部分逻辑移到node类;2.将node类的updateNodeActive方法名称改为updateNodeActiveClass
This commit is contained in:
parent
1caf2c7f15
commit
bc907f4b37
@ -1195,15 +1195,7 @@ class Render {
|
|||||||
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
||||||
isActive: active
|
isActive: active
|
||||||
})
|
})
|
||||||
if (node.group) {
|
node.updateNodeByActive(active)
|
||||||
// 切换激活状态,需要切换展开收起按钮的显隐
|
|
||||||
if (active) {
|
|
||||||
node.showExpandBtn()
|
|
||||||
} else {
|
|
||||||
node.hideExpandBtn()
|
|
||||||
}
|
|
||||||
node.updateNodeActive()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置节点是否展开
|
// 设置节点是否展开
|
||||||
|
|||||||
@ -524,7 +524,7 @@ class Node {
|
|||||||
if (!this.group) {
|
if (!this.group) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.updateNodeActive()
|
this.updateNodeActiveClass()
|
||||||
let { alwaysShowExpandBtn } = this.mindMap.opt
|
let { alwaysShowExpandBtn } = this.mindMap.opt
|
||||||
if (alwaysShowExpandBtn) {
|
if (alwaysShowExpandBtn) {
|
||||||
// 需要移除展开收缩按钮
|
// 需要移除展开收缩按钮
|
||||||
@ -600,12 +600,25 @@ class Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新节点激活状态
|
// 更新节点激活状态
|
||||||
updateNodeActive() {
|
updateNodeActiveClass() {
|
||||||
if (!this.group) return
|
if (!this.group) return
|
||||||
const isActive = this.getData('isActive')
|
const isActive = this.getData('isActive')
|
||||||
this.group[isActive ? 'addClass' : 'removeClass']('active')
|
this.group[isActive ? 'addClass' : 'removeClass']('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据是否激活更新节点
|
||||||
|
updateNodeByActive(active) {
|
||||||
|
if (this.group) {
|
||||||
|
// 切换激活状态,需要切换展开收起按钮的显隐
|
||||||
|
if (active) {
|
||||||
|
this.showExpandBtn()
|
||||||
|
} else {
|
||||||
|
this.hideExpandBtn()
|
||||||
|
}
|
||||||
|
this.updateNodeActiveClass()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 递归渲染
|
// 递归渲染
|
||||||
render(callback = () => {}) {
|
render(callback = () => {}) {
|
||||||
// 节点
|
// 节点
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user