mirror of https://github.com/veops/cmdb.git
fix:topo图相同节点出现两次的bug
This commit is contained in:
parent
9f5979c1b1
commit
9bb787d3f4
|
@ -20,6 +20,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
topoData: {},
|
topoData: {},
|
||||||
|
exsited_ci: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
inject: ['ci_types'],
|
inject: ['ci_types'],
|
||||||
|
@ -95,31 +96,33 @@ export default {
|
||||||
}
|
}
|
||||||
const ci_types_list = this.ci_types()
|
const ci_types_list = this.ci_types()
|
||||||
res.result.forEach((r) => {
|
res.result.forEach((r) => {
|
||||||
const _findCiType = ci_types_list.find((item) => item.id === r._type)
|
if (!this.exsited_ci.includes(r._id)) {
|
||||||
newNodes.push({
|
const _findCiType = ci_types_list.find((item) => item.id === r._type)
|
||||||
id: `${r._id}`,
|
newNodes.push({
|
||||||
Class: Node,
|
id: `${r._id}`,
|
||||||
title: r.ci_type_alias || r.ci_type,
|
Class: Node,
|
||||||
name: r.ci_type,
|
title: r.ci_type_alias || r.ci_type,
|
||||||
side: side,
|
name: r.ci_type,
|
||||||
unique_alias: r.unique_alias,
|
side: side,
|
||||||
unique_name: r.unique,
|
unique_alias: r.unique_alias,
|
||||||
unique_value: r[r.unique],
|
unique_name: r.unique,
|
||||||
children: [],
|
unique_value: r[r.unique],
|
||||||
icon: _findCiType?.icon || '',
|
children: [],
|
||||||
endpoints: [
|
icon: _findCiType?.icon || '',
|
||||||
{
|
endpoints: [
|
||||||
id: 'left',
|
{
|
||||||
orientation: [-1, 0],
|
id: 'left',
|
||||||
pos: [0, 0.5],
|
orientation: [-1, 0],
|
||||||
},
|
pos: [0, 0.5],
|
||||||
{
|
},
|
||||||
id: 'right',
|
{
|
||||||
orientation: [1, 0],
|
id: 'right',
|
||||||
pos: [0, 0.5],
|
orientation: [1, 0],
|
||||||
},
|
pos: [0, 0.5],
|
||||||
],
|
},
|
||||||
})
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
newEdges.push({
|
newEdges.push({
|
||||||
id: `${r._id}`,
|
id: `${r._id}`,
|
||||||
source: 'right',
|
source: 'right',
|
||||||
|
@ -135,11 +138,13 @@ export default {
|
||||||
this.canvas.removeEdges(edges)
|
this.canvas.removeEdges(edges)
|
||||||
|
|
||||||
const _topoData = _.cloneDeep(this.topoData)
|
const _topoData = _.cloneDeep(this.topoData)
|
||||||
|
_topoData.edges.push(...newEdges)
|
||||||
let result
|
let result
|
||||||
const getTreeItem = (data, id) => {
|
const getTreeItem = (data, id) => {
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
if (data[i].id === id) {
|
if (data[i].id === id) {
|
||||||
result = data[i] // 结果赋值
|
result = data[i] // 结果赋值
|
||||||
|
result.edges = _topoData.edges
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
if (data[i].children && data[i].children.length) {
|
if (data[i].children && data[i].children.length) {
|
||||||
|
@ -151,10 +156,10 @@ export default {
|
||||||
|
|
||||||
getTreeItem(_topoData.nodes.children, sourceNode)
|
getTreeItem(_topoData.nodes.children, sourceNode)
|
||||||
result.children.push(...newNodes)
|
result.children.push(...newNodes)
|
||||||
_topoData.edges.push(...newEdges)
|
|
||||||
|
|
||||||
this.topoData = _topoData
|
this.topoData = _topoData
|
||||||
this.canvas.draw(_topoData, {}, () => {})
|
this.canvas.draw(_topoData, {}, () => {})
|
||||||
|
this.exsited_ci = [...new Set([...this.exsited_ci, ...res.result.map((r) => r._id)])]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class BaseNode extends TreeNode {
|
||||||
container.append(titleContent)
|
container.append(titleContent)
|
||||||
container.append(uniqueDom)
|
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>`)
|
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)
|
container.append(addIcon)
|
||||||
addIcon.on('click', () => {
|
addIcon.on('click', () => {
|
||||||
|
|
Loading…
Reference in New Issue