CN-1540 fix: 提取Tag展示逻辑公共部分

This commit is contained in:
刘洪洪
2024-01-04 16:39:39 +08:00
parent 8b81181ae2
commit 80027fbd46
6 changed files with 100 additions and 159 deletions

View File

@@ -2,7 +2,8 @@ import _ from 'lodash'
import i18n from '@/i18n'
import axios from 'axios'
import { api } from '@/utils/api'
import { entityDefaultColor, entityDetailTags, tagValueLabelMapping } from '@/utils/constants'
import { entityDefaultColor } from '@/utils/constants'
import { formatTags } from '@/utils/tools'
export default class Node {
/*
@@ -80,28 +81,7 @@ export default class Node {
const tags = await this.queryTags(entityType, entityName)
let _tags = []
Object.keys(tags).forEach(k => {
if (k !== 'userDefinedTags' && tags[k]) {
// 此处是vpnLearningDomain/Ip/App的tag
if (_.isArray(tags[k])) {
tags[k].forEach(k3 => {
const find = entityDetailTags[entityType].find(t => t.name === k3.pluginName)
if (find) {
_tags.push({ key: 'pluginName', value: this.tagValueHandler('', '', k3.pluginName), type: find.type })
} else {
_tags.push({ key: 'pluginName', value: this.tagValueHandler('', '', k3.pluginName), color: k3.knowledgeBase ? (k3.knowledgeBase.color || entityDefaultColor) : entityDefaultColor })
}
})
} else {
Object.keys(tags[k]).forEach(k2 => {
const find = entityDetailTags[entityType].find(t => t.name === k2)
if (find) {
_tags.push({ key: k2, value: this.tagValueHandler(k, k2, tags[k][k2]), type: find.type })
}
})
}
}
})
formatTags(tags, entityType, _tags)
if (_.isArray(tags.userDefinedTags)) {
_tags = _.concat(_tags, tags.userDefinedTags.map(tag => ({ value: tag.tagValue, color: tag.knowledgeBase ? tag.knowledgeBase.color : entityDefaultColor })))
}
@@ -153,18 +133,6 @@ export default class Node {
throw response
}
}
tagValueHandler (k, k2, value) {
if (k === 'psiphon3Ip') {
if (k2 === 'type') {
const find = tagValueLabelMapping.find(t => t.value === value)
if (find) {
return find.name
}
}
}
return value
}
}
export const nodeType = {
rootNode: 'rootNode',

View File

@@ -202,9 +202,9 @@ import relatedServer from '@/mixins/relatedServer'
import Loading from '@/components/common/Loading'
import axios from 'axios'
import { api } from '@/utils/api'
import { entityDefaultColor, entityDetailTags, tagValueLabelMapping } from '@/utils/constants'
import { entityDefaultColor } from '@/utils/constants'
import _ from 'lodash'
import { getTagColor } from '@/utils/tools'
import { getTagColor, formatTags } from '@/utils/tools'
export default {
name: 'Row',
@@ -303,28 +303,7 @@ export default {
axios.get(`${url}?resource=${this.entity.entityValue}`).then(responese => {
const res = responese.data
if (responese.status === 200) {
Object.keys(res.data).forEach(k => {
if (k !== 'userDefinedTags' && res.data[k]) {
// 此处是vpnLearningDomain/Ip/App的tag
if (_.isArray(res.data[k])) {
res.data[k].forEach(k3 => {
const find = entityDetailTags[this.entity.entityType].find(t => t.name === k3.pluginName)
if (find) {
this.levelTwoTags.push({ key: 'pluginName', value: this.tagValueHandler(k3.pluginName), type: find.type })
} else {
this.levelTwoTags.push({ key: 'pluginName', value: this.tagValueHandler(k3.pluginName), color: k3.knowledgeBase ? (k3.knowledgeBase.color || entityDefaultColor) : entityDefaultColor })
}
})
} else {
Object.keys(res.data[k]).forEach(k2 => {
const find = entityDetailTags[this.entity.entityType].find(t => t.name === k2)
if (find) {
this.levelTwoTags.push({ key: k2, value: this.tagValueHandler(res.data[k][k2]), type: find.type })
}
})
}
}
})
formatTags(res.data, this.entity.entityType, this.levelTwoTags)
if (_.isArray(res.data.userDefinedTags)) {
this.levelTwoTags = _.concat(this.levelTwoTags, res.data.userDefinedTags.map(tag => ({ value: tag.tagValue, color: tag.knowledgeBase ? tag.knowledgeBase.color : entityDefaultColor })))
}
@@ -332,10 +311,6 @@ export default {
}
})
},
tagValueHandler (value) {
const find = tagValueLabelMapping.find(t => t.value === value)
return find ? find.name : value
},
/* 切换折叠状态 */
switchCollapse () {
this.isCollapse = !this.isCollapse