Demo:修复同时选中多个节点添加图标时,所有节点图标都会统一为第一个节点的图标的问题

This commit is contained in:
wanglin2
2023-11-20 16:46:00 +08:00
parent 879de57b49
commit bc2a5b214f

View File

@@ -101,9 +101,14 @@ export default {
handleNodeActive(...args) {
this.activeNodes = [...args[1]]
if (this.activeNodes.length > 0) {
let firstNode = this.activeNodes[0]
this.nodeImage = firstNode.getData('image') || ''
this.iconList = firstNode.getData('icon') || [] // 回显图标
if (this.activeNodes.length === 1) {
let firstNode = this.activeNodes[0]
this.nodeImage = firstNode.getData('image') || ''
this.iconList = firstNode.getData('icon') || [] // 回显图标
} else {
this.nodeImage = []
this.iconList = []
}
} else {
this.iconList = []
this.nodeImage = ''
@@ -121,27 +126,31 @@ export default {
// 设置icon
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 => {
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
}
})
},