feat: add http attr mapping

This commit is contained in:
songlh 2024-07-03 18:47:55 +08:00
parent 39145989c3
commit 3e9ae3e73a
3 changed files with 67 additions and 20 deletions

View File

@ -52,6 +52,16 @@ export function getSnmpAttributes(type, name) {
}) })
} }
export function getHttpAttrMapping(name, resource) {
return axios({
url: `/v0.1/adr/http/${name}/mapping`,
method: 'GET',
params: {
resource
}
})
}
export function getCITypeDiscovery(type_id) { export function getCITypeDiscovery(type_id) {
return axios({ return axios({
url: `/v0.1/adt/ci_types/${type_id}`, url: `/v0.1/adt/ci_types/${type_id}`,

View File

@ -29,7 +29,8 @@
</template> </template>
<script> <script>
import { getHttpCategories, getHttpAttributes, getSnmpAttributes } from '../../api/discovery' import _ from 'lodash'
import { getHttpCategories, getHttpAttributes, getSnmpAttributes, getHttpAttrMapping } from '../../api/discovery'
import AttrMapTable from '@/modules/cmdb/components/attrMapTable/index.vue' import AttrMapTable from '@/modules/cmdb/components/attrMapTable/index.vue'
import ADPreviewTable from './adPreviewTable.vue' import ADPreviewTable from './adPreviewTable.vue'
import HttpADCategory from './httpADCategory.vue' import HttpADCategory from './httpADCategory.vue'
@ -77,6 +78,7 @@ export default {
categoriesSelect: [], categoriesSelect: [],
currentCate: '', currentCate: '',
tableData: [], tableData: [],
httpAttrMap: {}
} }
}, },
computed: { computed: {
@ -103,13 +105,7 @@ export default {
immediate: true, immediate: true,
handler(newVal) { handler(newVal) {
if (newVal) { if (newVal) {
getHttpAttributes(this.ruleName, { resource: newVal }).then((res) => { this.getHttpAttr(newVal)
if (this.isEdit) {
this.formatTableData(res)
} else {
this.tableData = res
}
})
} }
}, },
}, },
@ -158,28 +154,49 @@ export default {
}, },
formatTableData(list) { formatTableData(list) {
const _findADT = this.adCITypeList.find((item) => Number(item.adr_id) === Number(this.currentTab)) const _findADT = this.adCITypeList.find((item) => Number(item.adr_id) === Number(this.currentTab))
this.tableData = (list || []).map((item) => { this.tableData = (list || []).map((val) => {
if (_findADT.attributes) { const item = _.cloneDeep(val)
return {
...item, if (_findADT?.attributes?.[item.name]) {
attr: _findADT.attributes[`${item.name}`], item.attr = _findADT.attributes[item.name]
}
} else { } else {
const _find = this.ciTypeAttributes.find((ele) => ele.name === item.name) const _find = this.ciTypeAttributes.find((ele) => ele.name === item.name)
if (_find) { if (_find) {
return { item.attr = _find.name
...item,
attr: _find.name,
} }
} }
if (
this.isEdit &&
!item.attr &&
this.httpAttrMap?.[item.name]
) {
item.attr = this.httpAttrMap[item.name]
}
return item return item
}
}) })
}, },
getTableData() { getTableData() {
const $table = this.$refs.attrMapTable const $table = this.$refs.attrMapTable
const { fullData } = $table.getTableData() const { fullData } = $table.getTableData()
return fullData || [] return fullData || []
},
async getHttpAttr(val) {
await this.getHttpAttrMapping(this.ruleName, val)
getHttpAttributes(this.ruleName, { resource: val }).then((res) => {
if (this.isEdit) {
this.formatTableData(res)
} else {
this.tableData = res
}
})
},
async getHttpAttrMapping(name, resource) {
const res = await getHttpAttrMapping(name, resource)
this.httpAttrMap = res || {}
} }
}, },
} }

View File

@ -179,7 +179,10 @@
:data="instanceList" :data="instanceList"
@checkbox-change="onSelectChange" @checkbox-change="onSelectChange"
@checkbox-all="onSelectChange" @checkbox-all="onSelectChange"
:checkbox-config="{ reserve: true, trigger: 'cell' }" @checkbox-range-start="checkboxRangeStart"
@checkbox-range-change="checkboxRangeChange"
@checkbox-range-end="checkboxRangeEnd"
:checkbox-config="{ reserve: true, range: true }"
@edit-closed="handleEditClose" @edit-closed="handleEditClose"
@edit-actived="handleEditActived" @edit-actived="handleEditActived"
:edit-config="{ trigger: 'dblclick', mode: 'row', showIcon: false }" :edit-config="{ trigger: 'dblclick', mode: 'row', showIcon: false }"
@ -528,6 +531,8 @@ export default {
isFullSearch: false, isFullSearch: false,
fullTreeData: [], fullTreeData: [],
filterFullTreeData: [], filterFullTreeData: [],
lastSelected: [], // checkbox range 记录
} }
}, },
computed: { computed: {
@ -1165,6 +1170,21 @@ export default {
onSelectChange({ records, reserves }) { onSelectChange({ records, reserves }) {
this.selectedRowKeys = [...records, ...reserves] this.selectedRowKeys = [...records, ...reserves]
}, },
checkboxRangeStart(e) {
const xTable = this.$refs.xTable
const lastSelected = xTable.getCheckboxRecords()
const selectedReserve = xTable.getCheckboxReserveRecords()
this.lastSelected = [...lastSelected, ...selectedReserve]
},
checkboxRangeChange(e) {
const xTable = this.$refs.xTable
xTable.setCheckboxRow(this.lastSelected, true)
},
checkboxRangeEnd(e) {
const xTable = this.$refs.xTable
this.lastSelected = []
this.selectedRowKeys = [...xTable.getCheckboxRecords(), ...xTable.getCheckboxReserveRecords()]
},
batchDeleteCIRelation() { batchDeleteCIRelation() {
const currentShowType = this.showTypes.find((item) => item.id === Number(this.currentTypeId[0])) const currentShowType = this.showTypes.find((item) => item.id === Number(this.currentTypeId[0]))
const that = this const that = this