fix:topo图相同节点出现两次的bug

This commit is contained in:
wang-liang0615 2023-09-26 20:13:12 +08:00
parent 9f5979c1b1
commit 9bb787d3f4
2 changed files with 224 additions and 219 deletions

View File

@ -20,6 +20,7 @@ export default {
data() {
return {
topoData: {},
exsited_ci: [],
}
},
inject: ['ci_types'],
@ -95,6 +96,7 @@ export default {
}
const ci_types_list = this.ci_types()
res.result.forEach((r) => {
if (!this.exsited_ci.includes(r._id)) {
const _findCiType = ci_types_list.find((item) => item.id === r._type)
newNodes.push({
id: `${r._id}`,
@ -120,6 +122,7 @@ export default {
},
],
})
}
newEdges.push({
id: `${r._id}`,
source: 'right',
@ -135,11 +138,13 @@ export default {
this.canvas.removeEdges(edges)
const _topoData = _.cloneDeep(this.topoData)
_topoData.edges.push(...newEdges)
let result
const getTreeItem = (data, id) => {
for (let i = 0; i < data.length; i++) {
if (data[i].id === id) {
result = data[i] // 结果赋值
result.edges = _topoData.edges
break
} else {
if (data[i].children && data[i].children.length) {
@ -151,10 +156,10 @@ export default {
getTreeItem(_topoData.nodes.children, sourceNode)
result.children.push(...newNodes)
_topoData.edges.push(...newEdges)
this.topoData = _topoData
this.canvas.draw(_topoData, {}, () => {})
this.exsited_ci = [...new Set([...this.exsited_ci, ...res.result.map((r) => r._id)])]
},
},
}

View File

@ -30,7 +30,7 @@ class BaseNode extends TreeNode {
container.append(titleContent)
container.append(uniqueDom)
if (opts.options.side && !opts.options.children.length) {
if (opts.options.side && (!opts.options.children.length && !(opts.options.edges && opts.options.edges.length && opts.options.edges.find(e => e.source === opts.options.side && e.sourceNode === opts.options.id)))) {
const addIcon = $(`<i aria-label="图标: plus-square" class="anticon anticon-plus-square add-icon-${opts.options.side}"><svg viewBox="64 64 896 896" data-icon="plus-square" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M328 544h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8z"></path><path d="M880 112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V144c0-17.7-14.3-32-32-32zm-40 728H184V184h656v656z"></path></svg></i>`)
container.append(addIcon)
addIcon.on('click', () => {