pref(cmdb-ui):change adt key & add adt alias (#314)

This commit is contained in:
wang-liang0615 2023-12-18 16:07:52 +08:00 committed by GitHub
parent 092a8b9b92
commit 6e9ce08e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 22 deletions

View File

@ -53,8 +53,8 @@ export default {
return postCITypeDiscovery(this.CITypeId, { adr_id: id, interval: type === 'agent' ? 300 : 3600 })
})
await Promise.all(promises)
.then(() => {
this.getCITypeDiscovery(this.selectedIds[0].id)
.then((res) => {
this.getCITypeDiscovery(res[0].id)
this.$message.success('添加成功')
})
.catch(() => {

View File

@ -2,20 +2,22 @@
<div class="attr-ad" :style="{ height: `${windowHeight - 104}px` }">
<div v-if="adCITypeList && adCITypeList.length">
<a-tabs size="small" v-model="currentTab">
<a-tab-pane v-for="item in adCITypeList" :key="item.adr_id">
<a-tab-pane v-for="item in adCITypeList" :key="item.id">
<a-space slot="tab">
<span>{{ getADCITypeParam(item.adr_id) }}</span>
<span v-if="item.extra_option && item.extra_option.alias">{{ item.extra_option.alias }}</span>
<span v-else>{{ getADCITypeParam(item.adr_id) }}</span>
<a-icon type="close-circle" @click="(e) => deleteADT(e, item)" />
</a-space>
<AttrADTabpane
:ref="`attrAdTabpane_${item.adr_id}`"
:currentTab="item.adr_id"
:ref="`attrAdTabpane_${item.id}`"
:adr_id="item.adr_id"
:adrList="adrList"
:adCITypeList="adCITypeList"
:currentAdt="item"
:ciTypeAttributes="ciTypeAttributes"
:currentAdr="getADCITypeParam(item.adr_id, undefined, true)"
@openEditDrawer="(data, type, adType) => openEditDrawer(data, type, adType)"
@handleSave="getCITypeDiscovery"
/>
</a-tab-pane>
<a-space
@ -135,7 +137,7 @@ export default {
await getCITypeDiscovery(this.CITypeId).then((res) => {
this.adCITypeList = res.filter((item) => item.adr_id)
if (res && res.length && !this.currentTab) {
this.currentTab = res[0].adr_id
this.currentTab = res[0].id
}
if (currentTab) {
this.currentTab = currentTab
@ -156,7 +158,7 @@ export default {
e.stopPropagation()
const that = this
this.$confirm({
title: `确认删除 ${this.getADCITypeParam(item.adr_id)}`,
title: `确认删除 ${item?.extra_option?.alias || this.getADCITypeParam(item.adr_id)}`,
content: (h) => (
<div>
<a-checkbox v-model={that.deletePlugin}>删除插件</a-checkbox>
@ -164,18 +166,22 @@ export default {
),
onOk() {
deleteCITypeDiscovery(item.id).then(async () => {
if (that.currentTab === item.adr_id) {
if (that.currentTab === item.id) {
that.currentTab = ''
}
that.deletePlugin = false
that.$message.success('删除成功!')
that.getCITypeDiscovery()
if (that.deletePlugin) {
await deleteDiscovery(item.adr_id)
await deleteDiscovery(item.adr_id).finally(() => {
that.deletePlugin = false
})
}
that.deletePlugin = false
})
},
onCancel() {},
onCancel() {
that.deletePlugin = false
},
})
},
openEditDrawer(data, type, adType) {
@ -183,12 +189,12 @@ export default {
},
async updateNotInner(adr) {
const _idx = this.adCITypeList.findIndex((item) => item.adr_id === adr.id)
let res
if (_idx < 0) {
await postCITypeDiscovery(this.CITypeId, { adr_id: adr.id, interval: 300 })
res = await postCITypeDiscovery(this.CITypeId, { adr_id: adr.id, interval: 300 })
}
await this.getDiscovery()
await this.getCITypeDiscovery()
this.currentTab = adr.id
await this.getCITypeDiscovery(res?.id ?? undefined)
this.$nextTick(() => {
this.$refs[`attrAdTabpane_${this.currentTab}`][0].init()
})

View File

@ -14,6 +14,7 @@
<span>编辑</span>
</a-space>
</a>
<div>别名<a-input v-model="alias" style="width:200px;" /></div>
<div class="attr-ad-header">字段映射</div>
<vxe-table
v-if="adrType === 'agent'"
@ -56,7 +57,7 @@
:ruleName="adrName"
:ciTypeAttributes="ciTypeAttributes"
:adCITypeList="adCITypeList"
:currentTab="currentTab"
:currentTab="adr_id"
:style="{ marginBottom: '20px' }"
/>
<a-form-model
@ -133,7 +134,7 @@ export default {
name: 'AttrADTabpane',
components: { Vcrontab, HttpSnmpAD, CMDBExprDrawer, MonitorNodeSetting },
props: {
currentTab: {
adr_id: {
type: Number,
default: 0,
},
@ -187,6 +188,7 @@ export default {
},
],
form3: this.$form.createForm(this, { name: 'snmp_form' }),
alias: '',
}
},
computed: {
@ -205,7 +207,7 @@ export default {
},
agentTypeRadioList() {
const { permissions = [] } = this.userRoles
if (permissions.includes('cmdb_admin') || permissions.includes('admin')) {
if ((permissions.includes('cmdb_admin') || permissions.includes('admin')) && this.adrType !== 'http') {
return [
{ value: 'all', label: '所有节点' },
{ value: 'agent_id', label: '指定节点' },
@ -221,8 +223,9 @@ export default {
mounted() {},
methods: {
init() {
const _find = this.adrList.find((item) => Number(item.id) === Number(this.currentTab))
const _findADT = this.adCITypeList.find((item) => Number(item.adr_id) === Number(this.currentTab))
const _find = this.adrList.find((item) => Number(item.id) === Number(this.adr_id))
const _findADT = this.adCITypeList.find((item) => Number(item.id) === Number(this.currentAdt.id))
this.alias = _findADT?.extra_option?.alias ?? ''
if (this.adrType === 'http') {
const { category = undefined, key = '', secret = '' } = _findADT?.extra_option ?? {}
this.form2 = {
@ -294,7 +297,7 @@ export default {
this.cron = cron
},
handleSave() {
const { currentAdt } = this
const { currentAdt, alias } = this
let params
if (this.adrType === 'http') {
params = {
@ -360,9 +363,15 @@ export default {
return
}
}
if (params.extra_option) {
params.extra_option.alias = alias
} else {
params.extra_option = {}
params.extra_option.alias = alias
}
putCITypeDiscovery(currentAdt.id, params).then((res) => {
this.$message.success('保存成功')
this.$emit('handleSave')
})
},
handleOpenCmdb() {