代码优化:1.将render类的addActiveNode函数名称改为addNodeToActiveList;2.将调用render类的setNodeActive方法的地方改为调用SET_NODE_ACTIVE命令
This commit is contained in:
parent
697e53ff7d
commit
9221c404ee
@ -412,14 +412,14 @@ class Render {
|
|||||||
// 清除当前激活的节点列表
|
// 清除当前激活的节点列表
|
||||||
clearActiveNodeList() {
|
clearActiveNodeList() {
|
||||||
this.activeNodeList.forEach(item => {
|
this.activeNodeList.forEach(item => {
|
||||||
this.setNodeActive(item, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', item, false)
|
||||||
})
|
})
|
||||||
this.activeNodeList = []
|
this.activeNodeList = []
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加节点到激活列表里
|
// 添加节点到激活列表里
|
||||||
addActiveNode(node) {
|
addNodeToActiveList(node) {
|
||||||
let index = this.findActiveNodeIndex(node)
|
const index = this.findActiveNodeIndex(node)
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
this.activeNodeList.push(node)
|
this.activeNodeList.push(node)
|
||||||
}
|
}
|
||||||
@ -449,7 +449,7 @@ class Render {
|
|||||||
node => {
|
node => {
|
||||||
if (!node.nodeData.data.isActive) {
|
if (!node.nodeData.data.isActive) {
|
||||||
node.nodeData.data.isActive = true
|
node.nodeData.data.isActive = true
|
||||||
this.addActiveNode(node)
|
this.addNodeToActiveList(node)
|
||||||
// 激活节点需要显示展开收起按钮
|
// 激活节点需要显示展开收起按钮
|
||||||
node.showExpandBtn()
|
node.showExpandBtn()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -1030,7 +1030,7 @@ class Render {
|
|||||||
// 激活被删除节点的兄弟节点或父节点
|
// 激活被删除节点的兄弟节点或父节点
|
||||||
if (needActiveNode) {
|
if (needActiveNode) {
|
||||||
this.activeNodeList.push(needActiveNode)
|
this.activeNodeList.push(needActiveNode)
|
||||||
this.setNodeActive(needActiveNode, true)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', needActiveNode, true)
|
||||||
needActiveNode = null
|
needActiveNode = null
|
||||||
}
|
}
|
||||||
this.mindMap.emit('node_active', null, [...this.activeNodeList])
|
this.mindMap.emit('node_active', null, [...this.activeNodeList])
|
||||||
|
|||||||
@ -438,7 +438,7 @@ class Node {
|
|||||||
this.renderer.activeNodeList
|
this.renderer.activeNodeList
|
||||||
)
|
)
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', this, !isActive)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this, !isActive)
|
||||||
this.mindMap.renderer[isActive ? 'removeActiveNode' : 'addActiveNode'](
|
this.mindMap.renderer[isActive ? 'removeActiveNode' : 'addNodeToActiveList'](
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
this.mindMap.emit('node_active', isActive ? null : this, [
|
this.mindMap.emit('node_active', isActive ? null : this, [
|
||||||
@ -517,7 +517,7 @@ class Node {
|
|||||||
this.mindMap.emit('before_node_active', this, this.renderer.activeNodeList)
|
this.mindMap.emit('before_node_active', this, this.renderer.activeNodeList)
|
||||||
this.renderer.clearActiveNodeList()
|
this.renderer.clearActiveNodeList()
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', this, true)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this, true)
|
||||||
this.renderer.addActiveNode(this)
|
this.renderer.addNodeToActiveList(this)
|
||||||
this.mindMap.emit('node_active', this, [...this.renderer.activeNodeList])
|
this.mindMap.emit('node_active', this, [...this.renderer.activeNodeList])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ function createGeneralizationNode() {
|
|||||||
this._generalizationNodeHeight = this._generalizationNode.height
|
this._generalizationNodeHeight = this._generalizationNode.height
|
||||||
this._generalizationNode.generalizationBelongNode = this
|
this._generalizationNode.generalizationBelongNode = this
|
||||||
if (this.nodeData.data.generalization.isActive) {
|
if (this.nodeData.data.generalization.isActive) {
|
||||||
this.renderer.addActiveNode(this._generalizationNode)
|
this.renderer.addNodeToActiveList(this._generalizationNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,7 +127,7 @@ class Base {
|
|||||||
// 数据关联实际节点
|
// 数据关联实际节点
|
||||||
data._node = newNode
|
data._node = newNode
|
||||||
if (data.data.isActive) {
|
if (data.data.isActive) {
|
||||||
this.renderer.addActiveNode(newNode)
|
this.renderer.addNodeToActiveList(newNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果当前节点在激活节点列表里,那么添加上激活的状态
|
// 如果当前节点在激活节点列表里,那么添加上激活的状态
|
||||||
|
|||||||
@ -365,7 +365,7 @@ class AssociativeLine {
|
|||||||
this.overlapNode = null
|
this.overlapNode = null
|
||||||
bfsWalk(this.mindMap.renderer.root, node => {
|
bfsWalk(this.mindMap.renderer.root, node => {
|
||||||
if (node.nodeData.data.isActive) {
|
if (node.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(node, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
||||||
}
|
}
|
||||||
if (node.uid === this.creatingStartNode.uid || this.overlapNode) {
|
if (node.uid === this.creatingStartNode.uid || this.overlapNode) {
|
||||||
return
|
return
|
||||||
@ -378,7 +378,7 @@ class AssociativeLine {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (this.overlapNode && !this.overlapNode.nodeData.data.isActive) {
|
if (this.overlapNode && !this.overlapNode.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(this.overlapNode, true)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +387,7 @@ class AssociativeLine {
|
|||||||
if (this.creatingStartNode.uid === node.uid) return
|
if (this.creatingStartNode.uid === node.uid) return
|
||||||
this.addLine(this.creatingStartNode, node)
|
this.addLine(this.creatingStartNode, node)
|
||||||
if (this.overlapNode && this.overlapNode.nodeData.data.isActive) {
|
if (this.overlapNode && this.overlapNode.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(this.overlapNode, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, false)
|
||||||
}
|
}
|
||||||
this.isCreatingLine = false
|
this.isCreatingLine = false
|
||||||
this.creatingStartNode = null
|
this.creatingStartNode = null
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class Drag extends Base {
|
|||||||
let nextNodeUid = this.nextNode ? this.nextNode.nodeData.data.uid : ''
|
let nextNodeUid = this.nextNode ? this.nextNode.nodeData.data.uid : ''
|
||||||
// 存在重叠子节点,则移动作为其子节点
|
// 存在重叠子节点,则移动作为其子节点
|
||||||
if (this.overlapNode) {
|
if (this.overlapNode) {
|
||||||
this.mindMap.renderer.setNodeActive(this.overlapNode, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, false)
|
||||||
this.mindMap.execCommand(
|
this.mindMap.execCommand(
|
||||||
'MOVE_NODE_TO',
|
'MOVE_NODE_TO',
|
||||||
this.beingDragNodeList,
|
this.beingDragNodeList,
|
||||||
@ -123,7 +123,7 @@ class Drag extends Base {
|
|||||||
)
|
)
|
||||||
} else if (this.prevNode) {
|
} else if (this.prevNode) {
|
||||||
// 存在前一个相邻节点,作为其下一个兄弟节点
|
// 存在前一个相邻节点,作为其下一个兄弟节点
|
||||||
this.mindMap.renderer.setNodeActive(this.prevNode, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.prevNode, false)
|
||||||
this.mindMap.execCommand(
|
this.mindMap.execCommand(
|
||||||
'INSERT_AFTER',
|
'INSERT_AFTER',
|
||||||
this.beingDragNodeList,
|
this.beingDragNodeList,
|
||||||
@ -131,7 +131,7 @@ class Drag extends Base {
|
|||||||
)
|
)
|
||||||
} else if (this.nextNode) {
|
} else if (this.nextNode) {
|
||||||
// 存在下一个相邻节点,作为其前一个兄弟节点
|
// 存在下一个相邻节点,作为其前一个兄弟节点
|
||||||
this.mindMap.renderer.setNodeActive(this.nextNode, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.nextNode, false)
|
||||||
this.mindMap.execCommand(
|
this.mindMap.execCommand(
|
||||||
'INSERT_BEFORE',
|
'INSERT_BEFORE',
|
||||||
this.beingDragNodeList,
|
this.beingDragNodeList,
|
||||||
@ -318,7 +318,7 @@ class Drag extends Base {
|
|||||||
this.placeholder.size(0, 0)
|
this.placeholder.size(0, 0)
|
||||||
this.nodeList.forEach(node => {
|
this.nodeList.forEach(node => {
|
||||||
if (node.nodeData.data.isActive) {
|
if (node.nodeData.data.isActive) {
|
||||||
this.mindMap.renderer.setNodeActive(node, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
||||||
}
|
}
|
||||||
if (this.overlapNode || (this.prevNode && this.nextNode)) {
|
if (this.overlapNode || (this.prevNode && this.nextNode)) {
|
||||||
return
|
return
|
||||||
@ -353,7 +353,7 @@ class Drag extends Base {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (this.overlapNode) {
|
if (this.overlapNode) {
|
||||||
this.mindMap.renderer.setNodeActive(this.overlapNode, true)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -221,13 +221,13 @@ class Select {
|
|||||||
if (node.nodeData.data.isActive) {
|
if (node.nodeData.data.isActive) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.renderer.setNodeActive(node, true)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', node, true)
|
||||||
this.mindMap.renderer.addActiveNode(node)
|
this.mindMap.renderer.addNodeToActiveList(node)
|
||||||
} else if (node.nodeData.data.isActive) {
|
} else if (node.nodeData.data.isActive) {
|
||||||
if (!node.nodeData.data.isActive) {
|
if (!node.nodeData.data.isActive) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.renderer.setNodeActive(node, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
||||||
this.mindMap.renderer.removeActiveNode(node)
|
this.mindMap.renderer.removeActiveNode(node)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user