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) { handleNodeActive(...args) {
this.activeNodes = [...args[1]] this.activeNodes = [...args[1]]
if (this.activeNodes.length > 0) { if (this.activeNodes.length > 0) {
if (this.activeNodes.length === 1) {
let firstNode = this.activeNodes[0] let firstNode = this.activeNodes[0]
this.nodeImage = firstNode.getData('image') || '' this.nodeImage = firstNode.getData('image') || ''
this.iconList = firstNode.getData('icon') || [] // 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) {
this.activeNodes.forEach(node => {
const iconList = [...(node.getData('icon') || [])]
let key = type + '_' + name let key = type + '_' + name
let index = this.iconList.findIndex(item => { let index = iconList.findIndex(item => {
return item === key return item === key
}) })
// icon // icon
if (index !== -1) { if (index !== -1) {
this.iconList.splice(index, 1) iconList.splice(index, 1)
} else { } else {
let typeIndex = this.iconList.findIndex(item => { let typeIndex = iconList.findIndex(item => {
return item.split('_')[0] === type return item.split('_')[0] === type
}) })
// icon // icon
if (typeIndex !== -1) { if (typeIndex !== -1) {
this.iconList.splice(typeIndex, 1, key) iconList.splice(typeIndex, 1, key)
} else { } else {
// icon // icon
this.iconList.push(key) iconList.push(key)
} }
} }
this.activeNodes.forEach(node => { node.setIcon(iconList)
node.setIcon([...this.iconList]) if (this.activeNodes.length === 1) {
this.iconList = iconList
}
}) })
}, },