feat(ui): add trigger test send

This commit is contained in:
songlh 2024-12-05 14:33:23 +08:00
parent 191ce95717
commit b7c3cce83b
4 changed files with 40 additions and 3 deletions
cmdb-ui/src/modules/cmdb

View File

@ -207,6 +207,13 @@ export function deleteTrigger(type_id, id) {
})
}
export function testTrigger(type_id, id) {
return axios({
url: `/v0.1/ci_types/${type_id}/triggers/${id}/test_notify`,
method: 'post',
})
}
// CMDB的模型和实例的授权接口
export function grantCiType(type_id, rid, data) {
return axios({

View File

@ -186,6 +186,9 @@ const cmdb_en = {
botSelect: 'Please select a robot',
refAttributeTips: 'The title and content can reference the attribute value of the CIType. The reference method is: {{ attr_name }}',
webhookRefAttributeTips: 'Request parameters can reference the attribute value of the model. The reference method is: {{ attr_name }}',
testSend: 'Test Send',
testSendTip: 'Please save the trigger first',
testSendSuccess: 'Send Success',
newTrigger: 'Add trigger',
editTriggerTitle: 'Edit trigger {name}',
newTriggerTitle: 'Add trigger {name}',

View File

@ -186,6 +186,9 @@ const cmdb_zh = {
botSelect: '请选择机器人',
refAttributeTips: '标题、内容可以引用该模型的属性值,引用方法为: {{ attr_name }}',
webhookRefAttributeTips: '请求参数可以引用该模型的属性值,引用方法为: {{ attr_name }}',
testSend: '测试发送',
testSendTip: '请先保存触发器',
testSendSuccess: '发送成功',
newTrigger: '新增触发器',
editTriggerTitle: '编辑触发器 {name}',
newTriggerTitle: '新增触发器 {name}',

View File

@ -242,6 +242,18 @@
</a-col>
</a-row>
</a-checkbox-group>
<a-row v-if="category === 2">
<a-button
@click="clickTestSend"
:disabled="!dateForm.attr_id"
type="primary"
ghost
class="ops-button-ghost"
>
{{ $t('cmdb.ciType.testSend') }}
</a-button>
</a-row>
</a-form-model-item>
</a-form-model>
<div class="auto-complete-wrapper" v-if="triggerAction === '3'">
@ -273,7 +285,7 @@
<script>
import _ from 'lodash'
import { addTrigger, updateTrigger, deleteTrigger } from '../../api/CIType'
import { addTrigger, updateTrigger, deleteTrigger, testTrigger } from '../../api/CIType'
import FilterComp from '@/components/CMDBFilterComp'
import EmployeeTreeSelect from '@/views/setting/components/employeeTreeSelect.vue'
import Webhook from '../../components/webhook'
@ -569,10 +581,13 @@ export default {
}
if (this.triggerId) {
await updateTrigger(this.CITypeId, this.triggerId, params)
this.$message.success(this.$t('editSuccess'))
} else {
await addTrigger(this.CITypeId, params)
const res = await addTrigger(this.CITypeId, params)
this.triggerId = res.id
this.$message.success(this.$t('createSuccess'))
}
this.handleCancel()
if (this.refresh) {
this.refresh()
}
@ -614,6 +629,15 @@ export default {
this.searchValue = item.label
this.dag_id = item.id
},
async clickTestSend() {
if (!this.triggerId) {
this.$message.warning(this.$t('cmdb.ciType.testSendTip'))
return
}
await testTrigger(this.CITypeId, this.triggerId)
this.$message.success(this.$t('cmdb.ciType.testSendSuccess'))
}
},
}
</script>