提交 | 用户 | 时间
|
ebc552
|
1 |
<template> |
L |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle" width="50%"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="120px" |
|
9 |
> |
|
10 |
<el-row> |
|
11 |
<el-col :span="12"> |
|
12 |
<el-form-item label="消息标题" prop="title"> |
|
13 |
<el-input v-model="formData.title" placeholder="请输入消息标题"/> |
|
14 |
</el-form-item> |
|
15 |
</el-col> |
|
16 |
<el-col :span="12"> |
|
17 |
<el-form-item label="监控对象" prop="alarmObj"> |
|
18 |
<el-input v-model="formData.alarmObj" placeholder="请输入监控对象"/> |
|
19 |
</el-form-item> |
|
20 |
</el-col> |
|
21 |
</el-row> |
|
22 |
<el-row> |
|
23 |
<el-col :span="12"> |
|
24 |
<el-form-item label="预测项" prop="itemId"> |
|
25 |
<el-select |
|
26 |
v-model="formData.itemId" |
|
27 |
filterable |
|
28 |
@change="handleChange(formData.itemId)" |
|
29 |
placeholder="请选择"> |
|
30 |
<el-option |
|
31 |
v-for="(item, index) in predictItemList" |
|
32 |
:key="index" |
|
33 |
:label="item.itemname" |
|
34 |
:value="item.id"/> |
|
35 |
</el-select> |
|
36 |
</el-form-item> |
|
37 |
</el-col> |
|
38 |
<el-col :span="12"> |
|
39 |
<el-form-item label="输出" prop="outId"> |
|
40 |
<el-select |
|
41 |
v-model="formData.outId" |
|
42 |
filterable |
|
43 |
placeholder="请选择"> |
|
44 |
<el-option |
|
45 |
v-for="(item, index) in outPutList" |
|
46 |
:key="index" |
|
47 |
:label="item.tagname" |
|
48 |
:value="item.id"/> |
|
49 |
</el-select> |
|
50 |
</el-form-item> |
|
51 |
</el-col> |
|
52 |
</el-row> |
|
53 |
<el-row> |
|
54 |
<el-col :span="12"> |
|
55 |
<el-form-item label="比较长度" prop="compLength"> |
|
56 |
<el-input-number v-model="formData.compLength" :min="1" clearable controls-position="right" style="width: 100%"/> |
|
57 |
</el-form-item> |
|
58 |
</el-col> |
|
59 |
<el-col :span="12"> |
|
60 |
<el-form-item label="单位" prop="unit"> |
|
61 |
<el-input v-model="formData.unit" placeholder="请输入单位"/> |
|
62 |
</el-form-item> |
|
63 |
</el-col> |
|
64 |
</el-row> |
|
65 |
<el-row> |
|
66 |
<el-col :span="12"> |
b4576d
|
67 |
<el-form-item label="预测上限" prop="upperLimit"> |
潘 |
68 |
<el-input-number v-model="formData.upperLimit" clearable controls-position="right" style="width: 100%"/> |
ebc552
|
69 |
</el-form-item> |
L |
70 |
</el-col> |
|
71 |
<el-col :span="12"> |
b4576d
|
72 |
<el-form-item label="预测下限" prop="lowerLimit"> |
潘 |
73 |
<el-input-number v-model="formData.lowerLimit" clearable controls-position="right" style="width: 100%"/> |
|
74 |
</el-form-item> |
|
75 |
</el-col> |
|
76 |
</el-row> |
|
77 |
<el-row> |
|
78 |
<el-col :span="12"> |
|
79 |
<el-form-item label="累计上限" prop="culUpper"> |
|
80 |
<el-input-number v-model="formData.culUpper" clearable controls-position="right" style="width: 100%"/> |
|
81 |
</el-form-item> |
|
82 |
</el-col> |
|
83 |
<el-col :span="12"> |
|
84 |
<el-form-item label="累计下限" prop="culLower"> |
|
85 |
<el-input-number v-model="formData.culLower" clearable controls-position="right" style="width: 100%"/> |
ebc552
|
86 |
</el-form-item> |
L |
87 |
</el-col> |
|
88 |
</el-row> |
|
89 |
<el-row> |
|
90 |
<el-col :span="12"> |
|
91 |
<el-form-item label="转换系数" prop="coefficient"> |
|
92 |
<el-input-number v-model="formData.coefficient" :min="1" clearable controls-position="right" style="width: 100%"/> |
|
93 |
</el-form-item> |
|
94 |
</el-col> |
|
95 |
<el-col :span="12"> |
|
96 |
<el-form-item label="调度方案" prop="scheduleId"> |
|
97 |
<el-input v-model="formData.scheduleId" placeholder="请输入调度方案"/> |
|
98 |
</el-form-item> |
|
99 |
</el-col> |
|
100 |
</el-row> |
|
101 |
<el-row> |
|
102 |
<el-col :span="12"> |
|
103 |
<el-form-item label="是否启用" prop="isEnable"> |
|
104 |
<el-select v-model="formData.isEnable" placeholder="请选择"> |
|
105 |
<el-option |
|
106 |
v-for="dict in getIntDictOptions(DICT_TYPE.COM_IS_INT)" |
|
107 |
:key="dict.value" |
|
108 |
:label="dict.label" |
|
109 |
:value="dict.value" |
|
110 |
/> |
|
111 |
</el-select> |
|
112 |
</el-form-item> |
|
113 |
</el-col> |
|
114 |
</el-row> |
|
115 |
</el-form> |
|
116 |
<template #footer> |
|
117 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
118 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
119 |
</template> |
|
120 |
</Dialog> |
|
121 |
</template> |
|
122 |
<script lang="ts" setup> |
|
123 |
import * as MmPredictAlarmConfig from '@/api/model/pre/alarm/config' |
|
124 |
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict"; |
|
125 |
import * as MmPredictItem from '@/api/model/pre/item' |
|
126 |
|
|
127 |
defineOptions({name: 'DataMmPredictAlarmConfigForm'}) |
|
128 |
|
|
129 |
const {t} = useI18n() // 国际化 |
|
130 |
const message = useMessage() // 消息弹窗 |
|
131 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
132 |
const dialogTitle = ref('') // 弹窗的标题 |
|
133 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
134 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
135 |
const predictItemList = ref([]) |
|
136 |
const outPutList = ref([]) |
|
137 |
const formData = ref({ |
|
138 |
id: undefined, |
|
139 |
title: undefined, |
|
140 |
alarmObj: undefined, |
|
141 |
itemId: undefined, |
|
142 |
itemName: undefined, |
|
143 |
outId: undefined, |
|
144 |
compLength: undefined, |
|
145 |
upperLimit: undefined, |
|
146 |
lowerLimit: undefined, |
b4576d
|
147 |
culUpper: undefined, |
潘 |
148 |
culLower: undefined, |
ebc552
|
149 |
unit: undefined, |
L |
150 |
coefficient: undefined, |
|
151 |
scheduleId: undefined, |
|
152 |
isEnable: undefined, |
|
153 |
}) |
|
154 |
const formRules = reactive({ |
|
155 |
title: [{required: true, message: '消息标题不能为空', trigger: 'blur'}], |
|
156 |
alarmObj: [{required: true, message: '监控对象不能为空', trigger: 'blur'}], |
|
157 |
itemId: [{required: true, message: '预测项ID不能为空', trigger: 'blur'}], |
|
158 |
outId: [{required: true, message: '输出ID不能为空', trigger: 'blur'}], |
|
159 |
}) |
|
160 |
const formRef = ref() // 表单 Ref |
|
161 |
|
|
162 |
/** 打开弹窗 */ |
|
163 |
const open = async (type: string, id?: number) => { |
|
164 |
dialogVisible.value = true |
|
165 |
dialogTitle.value = t('action.' + type) |
|
166 |
formType.value = type |
|
167 |
resetForm() |
|
168 |
|
|
169 |
// 获取normal列表 |
|
170 |
predictItemList.value = await MmPredictItem.getMmPredictItemList({ |
b4576d
|
171 |
status: 1 |
ebc552
|
172 |
}) |
L |
173 |
// 修改时,设置数据 |
|
174 |
if (id) { |
|
175 |
formLoading.value = true |
|
176 |
try { |
|
177 |
formData.value = await MmPredictAlarmConfig.getMmPredictAlarmConfig(id) |
|
178 |
await handleChange(formData.value.itemId) |
|
179 |
} finally { |
|
180 |
formLoading.value = false |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
} |
|
185 |
defineExpose({open}) // 提供 open 方法,用于打开弹窗 |
|
186 |
|
|
187 |
/** 提交表单 */ |
|
188 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
189 |
const submitForm = async () => { |
|
190 |
// 校验表单 |
|
191 |
if (!formRef) return |
|
192 |
const valid = await formRef.value.validate() |
|
193 |
if (!valid) return |
|
194 |
// 提交请求 |
|
195 |
formLoading.value = true |
|
196 |
try { |
|
197 |
const data = formData.value as unknown as MmPredictAlarmConfig.MmPredictAlarmConfigVO |
|
198 |
if (formType.value === 'create') { |
|
199 |
await MmPredictAlarmConfig.createMmPredictAlarmConfig(data) |
|
200 |
message.success(t('common.createSuccess')) |
|
201 |
} else { |
|
202 |
await MmPredictAlarmConfig.updateMmPredictAlarmConfig(data) |
|
203 |
message.success(t('common.updateSuccess')) |
|
204 |
} |
|
205 |
dialogVisible.value = false |
|
206 |
// 发送操作成功的事件 |
|
207 |
emit('success') |
|
208 |
} finally { |
|
209 |
formLoading.value = false |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
async function handleChange(itemid) { |
|
214 |
const queryParams = reactive({ |
|
215 |
itemid: itemid, |
|
216 |
}) |
|
217 |
outPutList.value = await MmPredictItem.getMmItemOutputList(queryParams) |
|
218 |
} |
|
219 |
/** 重置表单 */ |
|
220 |
const resetForm = () => { |
|
221 |
formData.value = { |
|
222 |
id: undefined, |
|
223 |
title: undefined, |
|
224 |
alarmObj: undefined, |
|
225 |
itemId: undefined, |
|
226 |
outId: undefined, |
|
227 |
compLength: 1, |
b4576d
|
228 |
upperLimit: undefined, |
潘 |
229 |
lowerLimit: undefined, |
|
230 |
culUpper: undefined, |
|
231 |
culLower: undefined, |
ebc552
|
232 |
unit: undefined, |
L |
233 |
coefficient: 1, |
|
234 |
scheduleId: undefined, |
|
235 |
isEnable: undefined, |
|
236 |
} |
|
237 |
formRef.value?.resetFields() |
|
238 |
} |
|
239 |
</script> |