fix: 修复关系图有时无法拓展的问题

This commit is contained in:
chenjinsong
2023-07-17 10:48:13 +08:00
parent 766b777bc6
commit f915c51254

View File

@@ -708,7 +708,7 @@ export default {
const domainNode = this.generatePrimaryNode({ const domainNode = this.generatePrimaryNode({
id: 'domain-1', id: 'domain-1',
parentId: rootNode.id, parentId: rootNode.id,
label: this.$t('entity.graph.resolvedDomain'), label: this.$t('entity.graph.resolveDomain'),
x: 260, x: 260,
y: -150, y: -150,
data: { data: {
@@ -1140,7 +1140,7 @@ export default {
} }
case 'domain': { case 'domain': {
iconClass = 'cn-icon cn-icon-subdomain' iconClass = 'cn-icon cn-icon-subdomain'
title = _this.$t('entity.graph.resolvedDomain') title = _this.$t('entity.graph.resolveDomain')
break break
} }
case 'app': { case 'app': {
@@ -1246,12 +1246,13 @@ export default {
}, },
async expandDetailList (expandType, currentName) { async expandDetailList (expandType, currentName) {
const currentNode = this.graphData.nodes.find(n => n.id === currentName) const currentNode = this.graphData.nodes.find(n => n.id === currentName)
console.info(currentNode)
// 如果存在primary node直接拓展 // 如果存在primary node直接拓展
const _primaryNode = currentNode.data.childNodes ? currentNode.data.childNodes.find(n => n.data.type === expandType) : null const _primaryNode = currentNode.data.childNodes ? currentNode.data.childNodes.find(n => n.data.type === expandType) : null
if (_primaryNode) { if (_primaryNode) {
await this.expandList(currentName, _primaryNode.id) await this.expandList(currentName, _primaryNode.id)
} else { } else {
// 如果temp node删掉新增primary node再拓展 // 如果存在temp node删掉新增primary node再拓展
const tempNode = this.graphData.nodes.find(n => n.nodeType === 'temp' && n.data.sourceName === currentName && n.data.type === expandType) const tempNode = this.graphData.nodes.find(n => n.nodeType === 'temp' && n.data.sourceName === currentName && n.data.type === expandType)
if (tempNode) { if (tempNode) {
// 先清除此temp node和temp edge // 先清除此temp node和temp edge
@@ -1261,16 +1262,42 @@ export default {
this.graphData.edges = this.graphData.edges.filter(e => { this.graphData.edges = this.graphData.edges.filter(e => {
return e.target !== tempNode.id return e.target !== tempNode.id
}) })
}
let label = ''
let isSubdomain = false
let count = 0
switch (expandType) {
case 'ip': {
count = _.get(currentNode.data, 'relatedEntityCount.ip.total', 0)
label = `${this.$t('entities.graph.resolveIp')}(${count})`
break
}
case 'domain': {
if (currentNode.data.type === 'domain') {
count = _.get(currentNode.data, 'relatedEntityCount.subdomain.total', 0)
label = `${this.$t('entities.subdomain')}(${count})`
isSubdomain = true
} else {
count = _.get(currentNode.data, 'relatedEntityCount.domain.total', 0)
label = `${this.$t('entity.graph.resolveDomain')}(${count})`
}
break
}
case 'app': {
count = _.get(currentNode.data, 'relatedEntityCount.app.total', 0)
label = `${this.$t('entities.tab.relatedApp')}(${count})`
break
}
}
const primaryNode = this.generatePrimaryNode({ const primaryNode = this.generatePrimaryNode({
id: `${tempNode.data.type}-${tempNode.data.sourceName}`, id: `${expandType}-${currentNode.id}`,
label: tempNode.label + `(${tempNode.data.count})`, label: label,
data: { data: {
sourceName: tempNode.data.sourceName, sourceName: currentNode.id,
sourceType: tempNode.data.sourceType, sourceType: currentNode.data.type,
type: tempNode.data.type, type: expandType,
isSubdomain: tempNode.data.isSubdomain || false, isSubdomain: isSubdomain,
count: tempNode.data.count count: count
} }
}) })
// 新node放入source node的childNodes中 // 新node放入source node的childNodes中
@@ -1301,7 +1328,6 @@ export default {
this.graph.changeData(this.graphData) this.graph.changeData(this.graphData)
} }
} }
}
}, },
async mounted () { async mounted () {
if (this.entity.entityType && this.entity.entityName) { if (this.entity.entityType && this.entity.entityName) {