代码优化:将调用clearAllActive方法的地方改为调用CLEAR_ACTIVE_NODE命令
This commit is contained in:
parent
caedfb46a9
commit
c68d629b7a
@ -234,7 +234,7 @@ class MindMap {
|
|||||||
|
|
||||||
// 设置主题
|
// 设置主题
|
||||||
setTheme(theme, notRender = false) {
|
setTheme(theme, notRender = false) {
|
||||||
this.renderer.clearAllActive()
|
this.execCommand('CLEAR_ACTIVE_NODE')
|
||||||
this.opt.theme = theme
|
this.opt.theme = theme
|
||||||
if (!notRender) {
|
if (!notRender) {
|
||||||
this.render(null, CONSTANTS.CHANGE_THEME)
|
this.render(null, CONSTANTS.CHANGE_THEME)
|
||||||
@ -381,7 +381,7 @@ class MindMap {
|
|||||||
this.opt.readonly = mode === CONSTANTS.MODE.READONLY
|
this.opt.readonly = mode === CONSTANTS.MODE.READONLY
|
||||||
if (this.opt.readonly) {
|
if (this.opt.readonly) {
|
||||||
// 取消当前激活的元素
|
// 取消当前激活的元素
|
||||||
this.renderer.clearAllActive()
|
this.execCommand('CLEAR_ACTIVE_NODE')
|
||||||
}
|
}
|
||||||
this.emit('mode_change', mode)
|
this.emit('mode_change', mode)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -202,8 +202,8 @@ class Render {
|
|||||||
this.setNodeActive = this.setNodeActive.bind(this)
|
this.setNodeActive = this.setNodeActive.bind(this)
|
||||||
this.mindMap.command.add('SET_NODE_ACTIVE', this.setNodeActive)
|
this.mindMap.command.add('SET_NODE_ACTIVE', this.setNodeActive)
|
||||||
// 清除所有激活节点
|
// 清除所有激活节点
|
||||||
this.clearAllActive = this.clearAllActive.bind(this)
|
this.clearActiveNode = this.clearActiveNode.bind(this)
|
||||||
this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearAllActive)
|
this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearActiveNode)
|
||||||
// 切换节点是否展开
|
// 切换节点是否展开
|
||||||
this.setNodeExpand = this.setNodeExpand.bind(this)
|
this.setNodeExpand = this.setNodeExpand.bind(this)
|
||||||
this.mindMap.command.add('SET_NODE_EXPAND', this.setNodeExpand)
|
this.mindMap.command.add('SET_NODE_EXPAND', this.setNodeExpand)
|
||||||
@ -400,6 +400,15 @@ class Render {
|
|||||||
this.mindMap.emit('node_active', null, [...this.activeNodeList])
|
this.mindMap.emit('node_active', null, [...this.activeNodeList])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清除当前所有激活节点,并会触发事件
|
||||||
|
clearActiveNode() {
|
||||||
|
if (this.activeNodeList.length <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.clearActive()
|
||||||
|
this.mindMap.emit('node_active', null, [])
|
||||||
|
}
|
||||||
|
|
||||||
// 清除当前激活的节点
|
// 清除当前激活的节点
|
||||||
clearActive() {
|
clearActive() {
|
||||||
this.activeNodeList.forEach(item => {
|
this.activeNodeList.forEach(item => {
|
||||||
@ -408,15 +417,6 @@ class Render {
|
|||||||
this.activeNodeList = []
|
this.activeNodeList = []
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除当前所有激活节点,并会触发事件
|
|
||||||
clearAllActive() {
|
|
||||||
if (this.activeNodeList.length <= 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.clearActive()
|
|
||||||
this.mindMap.emit('node_active', null, [])
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加节点到激活列表里
|
// 添加节点到激活列表里
|
||||||
addActiveNode(node) {
|
addActiveNode(node) {
|
||||||
let index = this.findActiveNodeIndex(node)
|
let index = this.findActiveNodeIndex(node)
|
||||||
@ -467,7 +467,7 @@ class Render {
|
|||||||
|
|
||||||
// 回退
|
// 回退
|
||||||
back(step) {
|
back(step) {
|
||||||
this.clearAllActive()
|
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
|
||||||
let data = this.mindMap.command.back(step)
|
let data = this.mindMap.command.back(step)
|
||||||
if (data) {
|
if (data) {
|
||||||
this.renderTree = data
|
this.renderTree = data
|
||||||
@ -477,7 +477,7 @@ class Render {
|
|||||||
|
|
||||||
// 前进
|
// 前进
|
||||||
forward(step) {
|
forward(step) {
|
||||||
this.clearAllActive()
|
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
|
||||||
let data = this.mindMap.command.forward(step)
|
let data = this.mindMap.command.forward(step)
|
||||||
if (data) {
|
if (data) {
|
||||||
this.renderTree = data
|
this.renderTree = data
|
||||||
|
|||||||
@ -222,7 +222,7 @@ class Drag extends Base {
|
|||||||
// 创建克隆节点
|
// 创建克隆节点
|
||||||
this.createCloneNode()
|
this.createCloneNode()
|
||||||
// 清除当前所有激活的节点
|
// 清除当前所有激活的节点
|
||||||
this.mindMap.renderer.clearAllActive()
|
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user