mirror of https://github.com/veops/cmdb.git
fix(cmdb-ui):resource search common attrs (#397)
This commit is contained in:
parent
013b116eb5
commit
082da5fade
|
@ -206,7 +206,7 @@
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import SearchForm from '../../components/searchForm/SearchForm.vue'
|
import SearchForm from '../../components/searchForm/SearchForm.vue'
|
||||||
import { searchCI } from '../../api/ci'
|
import { searchCI } from '../../api/ci'
|
||||||
import { searchAttributes, getCITypeAttributesByTypeIds } from '../../api/CITypeAttr'
|
import { searchAttributes, getCITypeAttributesByTypeIds, getCITypeAttributesById } from '../../api/CITypeAttr'
|
||||||
import { getCITypes } from '../../api/CIType'
|
import { getCITypes } from '../../api/CIType'
|
||||||
import { getSubscribeAttributes } from '../../api/preference'
|
import { getSubscribeAttributes } from '../../api/preference'
|
||||||
import { getCITableColumns } from '../../utils/helper'
|
import { getCITableColumns } from '../../utils/helper'
|
||||||
|
@ -315,43 +315,44 @@ export default {
|
||||||
this.instanceList = []
|
this.instanceList = []
|
||||||
this.totalNumber = res['numfound']
|
this.totalNumber = res['numfound']
|
||||||
|
|
||||||
const oldData = res.result
|
const { attributes: resAllAttributes } = await getCITypeAttributesByTypeIds({
|
||||||
|
type_ids: Object.keys(res.counter).join(','),
|
||||||
function allKeys(data) {
|
})
|
||||||
const keys = {}
|
const _columnsGroup = Object.keys(res.counter).map((key) => {
|
||||||
const ignoreAttr = ['_id', '_type', 'ci_type', 'ci_type_alias', 'unique', 'unique_alias']
|
const _find = this.ciTypes.find((item) => item.name === key)
|
||||||
data.forEach((item) => {
|
return {
|
||||||
Object.keys(item).forEach((key) => {
|
id: `parent-${_find.id}`,
|
||||||
if (!ignoreAttr.includes(key)) {
|
value: key,
|
||||||
keys[key] = ''
|
label: _find?.alias || _find?.name,
|
||||||
|
isCiType: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
const ciTypeAttribute = {}
|
||||||
|
const promises = _columnsGroup.map((item) => {
|
||||||
|
return getCITypeAttributesById(item.id.split('-')[1]).then((res) => {
|
||||||
|
ciTypeAttribute[item.label] = res.attributes
|
||||||
|
})
|
||||||
|
})
|
||||||
|
await Promise.all(promises)
|
||||||
|
|
||||||
|
const outputKeys = {}
|
||||||
|
resAllAttributes.forEach((attr) => {
|
||||||
|
outputKeys[attr.name] = ''
|
||||||
})
|
})
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
function tidy(data) {
|
|
||||||
const outputKeys = allKeys(data)
|
|
||||||
const common = {}
|
const common = {}
|
||||||
data.forEach((item) => {
|
Object.keys(outputKeys).forEach((key) => {
|
||||||
const tmp = {}
|
Object.entries(ciTypeAttribute).forEach(([type, attrs]) => {
|
||||||
Object.keys(outputKeys).forEach((j) => {
|
if (attrs.find((a) => a.name === key)) {
|
||||||
if (j in item) {
|
if (key in common) {
|
||||||
tmp[j] = item[j]
|
common[key][type] = ''
|
||||||
// 提取common
|
|
||||||
{
|
|
||||||
const key = item['ci_type_alias']
|
|
||||||
if (j in common) {
|
|
||||||
common[j][[key]] = ''
|
|
||||||
} else {
|
} else {
|
||||||
common[j] = { [key]: '' }
|
common[key] = { [type]: '' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
tmp[j] = null
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const commonObject = {}
|
const commonObject = {}
|
||||||
const commonKeys = []
|
const commonKeys = []
|
||||||
// 整理common
|
// 整理common
|
||||||
|
@ -366,10 +367,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return { commonObject, commonKeys }
|
|
||||||
}
|
|
||||||
|
|
||||||
const { commonObject, commonKeys } = tidy(oldData)
|
|
||||||
const _commonColumnsGroup = Object.keys(commonObject).map((key) => {
|
const _commonColumnsGroup = Object.keys(commonObject).map((key) => {
|
||||||
return {
|
return {
|
||||||
id: `parent-${key}`,
|
id: `parent-${key}`,
|
||||||
|
@ -385,24 +383,14 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const _columnsGroup = Object.keys(res.counter).map((key) => {
|
const promises1 = _columnsGroup.map((item) => {
|
||||||
const _find = this.ciTypes.find((item) => item.name === key)
|
|
||||||
return {
|
|
||||||
id: `parent-${_find.id}`,
|
|
||||||
value: key,
|
|
||||||
label: _find?.alias || _find?.name,
|
|
||||||
isCiType: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const promises = _columnsGroup.map((item) => {
|
|
||||||
return getSubscribeAttributes(item.id.split('-')[1]).then((res1) => {
|
return getSubscribeAttributes(item.id.split('-')[1]).then((res1) => {
|
||||||
item.children = this.getColumns(res.result, res1.attributes).filter(
|
item.children = this.getColumns(res.result, res1.attributes).filter(
|
||||||
(col) => !commonKeys.includes(col.field)
|
(col) => !commonKeys.includes(col.field)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
await Promise.all(promises).then(() => {
|
await Promise.all(promises1).then(() => {
|
||||||
this.columnsGroup = [..._commonColumnsGroup, ..._columnsGroup]
|
this.columnsGroup = [..._commonColumnsGroup, ..._columnsGroup]
|
||||||
this.instanceList = res['result']
|
this.instanceList = res['result']
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue