mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Demo:修复同时选中多个节点添加图标时,所有节点图标都会统一为第一个节点的图标的问题
This commit is contained in:
parent
879de57b49
commit
bc2a5b214f
@ -101,9 +101,14 @@ export default {
|
|||||||
handleNodeActive(...args) {
|
handleNodeActive(...args) {
|
||||||
this.activeNodes = [...args[1]]
|
this.activeNodes = [...args[1]]
|
||||||
if (this.activeNodes.length > 0) {
|
if (this.activeNodes.length > 0) {
|
||||||
let firstNode = this.activeNodes[0]
|
if (this.activeNodes.length === 1) {
|
||||||
this.nodeImage = firstNode.getData('image') || ''
|
let firstNode = this.activeNodes[0]
|
||||||
this.iconList = firstNode.getData('icon') || [] // 回显图标
|
this.nodeImage = firstNode.getData('image') || ''
|
||||||
|
this.iconList = firstNode.getData('icon') || [] // 回显图标
|
||||||
|
} else {
|
||||||
|
this.nodeImage = []
|
||||||
|
this.iconList = []
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.iconList = []
|
this.iconList = []
|
||||||
this.nodeImage = ''
|
this.nodeImage = ''
|
||||||
@ -121,27 +126,31 @@ export default {
|
|||||||
|
|
||||||
// 设置icon
|
// 设置icon
|
||||||
setIcon(type, name) {
|
setIcon(type, name) {
|
||||||
let key = type + '_' + name
|
|
||||||
let index = this.iconList.findIndex(item => {
|
|
||||||
return item === key
|
|
||||||
})
|
|
||||||
// 删除icon
|
|
||||||
if (index !== -1) {
|
|
||||||
this.iconList.splice(index, 1)
|
|
||||||
} else {
|
|
||||||
let typeIndex = this.iconList.findIndex(item => {
|
|
||||||
return item.split('_')[0] === type
|
|
||||||
})
|
|
||||||
// 替换icon
|
|
||||||
if (typeIndex !== -1) {
|
|
||||||
this.iconList.splice(typeIndex, 1, key)
|
|
||||||
} else {
|
|
||||||
// 增加icon
|
|
||||||
this.iconList.push(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.activeNodes.forEach(node => {
|
this.activeNodes.forEach(node => {
|
||||||
node.setIcon([...this.iconList])
|
const iconList = [...(node.getData('icon') || [])]
|
||||||
|
let key = type + '_' + name
|
||||||
|
let index = iconList.findIndex(item => {
|
||||||
|
return item === key
|
||||||
|
})
|
||||||
|
// 删除icon
|
||||||
|
if (index !== -1) {
|
||||||
|
iconList.splice(index, 1)
|
||||||
|
} else {
|
||||||
|
let typeIndex = iconList.findIndex(item => {
|
||||||
|
return item.split('_')[0] === type
|
||||||
|
})
|
||||||
|
// 替换icon
|
||||||
|
if (typeIndex !== -1) {
|
||||||
|
iconList.splice(typeIndex, 1, key)
|
||||||
|
} else {
|
||||||
|
// 增加icon
|
||||||
|
iconList.push(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.setIcon(iconList)
|
||||||
|
if (this.activeNodes.length === 1) {
|
||||||
|
this.iconList = iconList
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user