<template>
|
<Dialog v-model="dialogVisible" :title="dialogTitle" width="50%">
|
<el-form
|
ref="formRef"
|
v-loading="formLoading"
|
:model="formData"
|
:rules="formRules"
|
label-width="120px"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="消息标题" prop="title">
|
<el-input v-model="formData.title" placeholder="请输入消息标题"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="监控对象" prop="alarmObj">
|
<el-input v-model="formData.alarmObj" placeholder="请输入监控对象"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="预测项" prop="itemId">
|
<el-select
|
v-model="formData.itemId"
|
filterable
|
@change="handleChange(formData.itemId)"
|
placeholder="请选择">
|
<el-option
|
v-for="(item, index) in predictItemList"
|
:key="index"
|
:label="item.itemname"
|
:value="item.id"/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="输出" prop="outId">
|
<el-select
|
v-model="formData.outId"
|
filterable
|
placeholder="请选择">
|
<el-option
|
v-for="(item, index) in outPutList"
|
:key="index"
|
:label="item.tagname"
|
:value="item.id"/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="比较长度" prop="compLength">
|
<el-input-number v-model="formData.compLength" :min="1" clearable controls-position="right" style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="单位" prop="unit">
|
<el-input v-model="formData.unit" placeholder="请输入单位"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="预测上限" prop="upperLimit">
|
<el-input-number v-model="formData.upperLimit" clearable controls-position="right" style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="预测下限" prop="lowerLimit">
|
<el-input-number v-model="formData.lowerLimit" clearable controls-position="right" style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="累计上限" prop="culUpper">
|
<el-input-number v-model="formData.culUpper" clearable controls-position="right" style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="累计下限" prop="culLower">
|
<el-input-number v-model="formData.culLower" clearable controls-position="right" style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="转换系数" prop="coefficient">
|
<el-input-number v-model="formData.coefficient" :min="1" clearable controls-position="right" style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="调度方案" prop="scheduleId">
|
<el-input v-model="formData.scheduleId" placeholder="请输入调度方案"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="是否启用" prop="isEnable">
|
<el-select v-model="formData.isEnable" placeholder="请选择">
|
<el-option
|
v-for="dict in getIntDictOptions(DICT_TYPE.COM_IS_INT)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
</template>
|
</Dialog>
|
</template>
|
<script lang="ts" setup>
|
import * as MmPredictAlarmConfig from '@/api/model/pre/alarm/config'
|
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
|
import * as MmPredictItem from '@/api/model/pre/item'
|
|
defineOptions({name: 'DataMmPredictAlarmConfigForm'})
|
|
const {t} = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogTitle = ref('') // 弹窗的标题
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
const predictItemList = ref([])
|
const outPutList = ref([])
|
const formData = ref({
|
id: undefined,
|
title: undefined,
|
alarmObj: undefined,
|
itemId: undefined,
|
itemName: undefined,
|
outId: undefined,
|
compLength: undefined,
|
upperLimit: undefined,
|
lowerLimit: undefined,
|
culUpper: undefined,
|
culLower: undefined,
|
unit: undefined,
|
coefficient: undefined,
|
scheduleId: undefined,
|
isEnable: undefined,
|
})
|
const formRules = reactive({
|
title: [{required: true, message: '消息标题不能为空', trigger: 'blur'}],
|
alarmObj: [{required: true, message: '监控对象不能为空', trigger: 'blur'}],
|
itemId: [{required: true, message: '预测项ID不能为空', trigger: 'blur'}],
|
outId: [{required: true, message: '输出ID不能为空', trigger: 'blur'}],
|
})
|
const formRef = ref() // 表单 Ref
|
|
/** 打开弹窗 */
|
const open = async (type: string, id?: number) => {
|
dialogVisible.value = true
|
dialogTitle.value = t('action.' + type)
|
formType.value = type
|
resetForm()
|
|
// 获取normal列表
|
predictItemList.value = await MmPredictItem.getMmPredictItemList({
|
status: 1
|
})
|
// 修改时,设置数据
|
if (id) {
|
formLoading.value = true
|
try {
|
formData.value = await MmPredictAlarmConfig.getMmPredictAlarmConfig(id)
|
await handleChange(formData.value.itemId)
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
}
|
defineExpose({open}) // 提供 open 方法,用于打开弹窗
|
|
/** 提交表单 */
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
const submitForm = async () => {
|
// 校验表单
|
if (!formRef) return
|
const valid = await formRef.value.validate()
|
if (!valid) return
|
// 提交请求
|
formLoading.value = true
|
try {
|
const data = formData.value as unknown as MmPredictAlarmConfig.MmPredictAlarmConfigVO
|
if (formType.value === 'create') {
|
await MmPredictAlarmConfig.createMmPredictAlarmConfig(data)
|
message.success(t('common.createSuccess'))
|
} else {
|
await MmPredictAlarmConfig.updateMmPredictAlarmConfig(data)
|
message.success(t('common.updateSuccess'))
|
}
|
dialogVisible.value = false
|
// 发送操作成功的事件
|
emit('success')
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
async function handleChange(itemid) {
|
const queryParams = reactive({
|
itemid: itemid,
|
})
|
outPutList.value = await MmPredictItem.getMmItemOutputList(queryParams)
|
}
|
/** 重置表单 */
|
const resetForm = () => {
|
formData.value = {
|
id: undefined,
|
title: undefined,
|
alarmObj: undefined,
|
itemId: undefined,
|
outId: undefined,
|
compLength: 1,
|
upperLimit: undefined,
|
lowerLimit: undefined,
|
culUpper: undefined,
|
culLower: undefined,
|
unit: undefined,
|
coefficient: 1,
|
scheduleId: undefined,
|
isEnable: undefined,
|
}
|
formRef.value?.resetFields()
|
}
|
</script>
|