潘志宝
3 天以前 221918bba28d2384d03c596a68256d7832e4a0e0
提交 | 用户 | 时间
2f0aa4 1 <template>
6badb7 2   <Dialog v-model="dialogVisible" :title="dialogTitle" width="60%">
2f0aa4 3     <el-form
4       ref="formRef"
5       v-loading="formLoading"
6       :model="formData"
7       :rules="formRules"
8       label-width="120px"
9     >
22bece 10       <el-divider content-position="left">基本信息</el-divider>
2f0aa4 11       <el-row>
12         <el-col :span="12">
13           <el-form-item label="模型编号" prop="modelCode">
14             <el-input v-model="formData.modelCode" placeholder="请输入模型编号" />
15           </el-form-item>
16         </el-col>
17       </el-row>
18       <el-row>
19         <el-col :span="12">
20           <el-form-item label="模型类型" prop="modelType">
6badb7 21             <el-select v-model="formData.modelType" placeholder="请选择">
22               <el-option
8ea580 23                 v-for="dict in getStrDictOptions(DICT_TYPE.SCHE_MODEL_TYPE)"
6badb7 24                 :key="dict.value"
25                 :label="dict.label"
26                 :value="dict.value"
27               />
28             </el-select>
2f0aa4 29           </el-form-item>
30         </el-col>
31         <el-col :span="12">
32           <el-form-item label="调用方式" prop="invocation">
6badb7 33             <el-select v-model="formData.invocation" placeholder="请选择">
34               <el-option
8ea580 35                 v-for="dict in getStrDictOptions(DICT_TYPE.SCHE_MODEL_INVOCATION)"
6badb7 36                 :key="dict.value"
37                 :label="dict.label"
38                 :value="dict.value"
39               />
40             </el-select>
2f0aa4 41           </el-form-item>
42         </el-col>
43       </el-row>
22bece 44       <el-divider content-position="left">模型信息</el-divider>
D 45       <div style="width: 120px;text-align: right;margin-bottom: 8px">
e4de9b 46         <el-popover placement="right" :width="300" trigger="click" ref="modelPopover" @before-enter="model = undefined">
22bece 47           <template #reference>
D 48             <span style="color: #409eff;cursor: pointer">关联模型信息</span>
49           </template>
50           <template #default>
51             <div style="display:flex;flex-direction: row;align-items: center;">
52               <el-cascader style="width: 100%" v-model="model" placeholder="选择模型" :teleported="false" @change="changeModel" :options="scheduleModelList"/>
53             </div>
54           </template>
55         </el-popover>
56       </div>
2f0aa4 57       <el-row>
22bece 58         <el-col :span="12">
D 59           <el-form-item label="模型名称" prop="modelName">
091c7e 60             <el-input v-model="formData.modelName" placeholder="请输入模型名称"/>
22bece 61           </el-form-item>
D 62         </el-col>
63         <el-col :span="12">
2f0aa4 64           <el-form-item label="类名" prop="className">
22bece 65             <el-input v-model="formData.className" placeholder="请输入类名" :disabled="true" />
2f0aa4 66           </el-form-item>
67         </el-col>
68       </el-row>
69       <el-row>
70         <el-col :span="12">
71           <el-form-item label="方法名" prop="methodName">
22bece 72             <el-input v-model="formData.methodName" placeholder="请输入方法名" :disabled="true" />
2f0aa4 73           </el-form-item>
74         </el-col>
75         <el-col :span="12">
76           <el-form-item label="参数数量" prop="portLength">
22bece 77             <el-input-number v-model="formData.portLength" :min="0" controls-position="right" :disabled="true" />
2f0aa4 78           </el-form-item>
79         </el-col>
80       </el-row>
81       <el-row>
82         <el-col :span="24">
83           <el-form-item label="参数构造" prop="paramStructure">
22bece 84             <el-input v-model="formData.paramStructure" placeholder="请输入参数构造" :disabled="true" />
2f0aa4 85           </el-form-item>
86         </el-col>
87       </el-row>
88       <el-row>
89         <el-col :span="24">
90           <el-form-item label="模型路径" prop="modelPath">
22bece 91             <el-input v-model="formData.modelPath" placeholder="模型路径" :disabled="true" />
2f0aa4 92           </el-form-item>
93         </el-col>
94       </el-row>
95       <el-divider content-position="left">输入参数</el-divider>
96       <el-table
97         :data="formData.paramList"
98         border
99         style="width: 100%; margin-top: 5px;">
100         <el-table-column
101           prop=""
102           label="端口"
103           width="100"
104           align="center">
6badb7 105           <template #default="scope">
22bece 106             <el-input v-model="scope.row.modelparamportorder" maxlength="5" clearable :disabled="true"
6badb7 107                       style="width:100%; hight:100%"/>
2f0aa4 108           </template>
109         </el-table-column>
110         <el-table-column
111           prop=""
112           label="序号"
113           width="100"
114           align="center">
6badb7 115           <template #default="scope">
22bece 116             <el-input v-model="scope.row.modelparamorder" maxlength="5" clearable
6badb7 117                       style="width:100%;hight:100%"/>
2f0aa4 118           </template>
119         </el-table-column>
120         <el-table-column
121           prop=""
122           label="类型"
123           width="150"
124           align="center">
6badb7 125           <template #default="scope">
22bece 126             <el-select v-model="scope.row.modelparamtype" placeholder="请选择" @change="changeModelparamtype(scope.row)">
2f0aa4 127               <el-option
8ea580 128                 v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_PARAM_TYPE)"
2f0aa4 129                 :key="dict.value"
130                 :label="dict.label"
131                 :value="dict.value"
132               />
133             </el-select>
134           </template>
135         </el-table-column>
8ea580 136         <el-table-column
2f0aa4 137           prop=""
138           label="参数名称"
139           align="center">
6badb7 140           <template #default="scope">
22bece 141             <el-select v-if="scope.row.modelparamtype === 'NormalItem'"
D 142               v-model="scope.row.modelparamid"
143               placeholder="请选择"
144               filterable
145               style="width: 100%">
146               <el-option-group
147                 v-for="group in modelparamListMap['NormalItem']"
148                 :key="group.value"
149                 :label="group.label"
150               >
151                 <el-option
152                   v-for="item in group.children"
153                   :key="item.value"
154                   :label="item.label"
155                   :value="item.value"
156                 />
157               </el-option-group>
158             </el-select>
159             <el-select v-else
2f0aa4 160               v-model="scope.row.modelparamid"
161               filterable
162               placeholder="请选择">
163               <el-option
d3ee81 164                 v-for="(item, index) in modelparamListMap[scope.row.modelparamtype]"
2f0aa4 165                 :key="index"
166                 :label="item.name"
d3ee81 167                 :value="item.id"/>
2f0aa4 168             </el-select>
169           </template>
8ea580 170         </el-table-column>
2f0aa4 171         <el-table-column
172           prop=""
173           label="参数长度"
d3ee81 174           width="160"
2f0aa4 175           align="center">
6badb7 176           <template #default="scope">
d3ee81 177             <el-input-number v-model="scope.row.datalength" :min="0" clearable controls-position="right"
178                              style="width:100%;hight:100%"/>
2f0aa4 179           </template>
180         </el-table-column>
181         <el-table-column
182           prop=""
183           label="操作"
184           width="100"
185           align="center">
6badb7 186           <template #default="scope">
2f0aa4 187             <el-button
6badb7 188               link
189               @click.prevent="addRow(scope.$index, formData.paramList)"
190               type="primary"
2f0aa4 191               size="small">
192               添加
193             </el-button>
194             <el-button
6badb7 195               link
22bece 196               @click.prevent="deleteRow(scope.$index, scope.row, formData.paramList)"
6badb7 197               type="primary"
2f0aa4 198               size="small">
199               删除
200             </el-button>
201           </template>
202         </el-table-column>
203       </el-table>
204
205       <el-divider content-position="left">设置参数</el-divider>
206       <el-table
6badb7 207         :data="formData.settingList"
2f0aa4 208         border
209         style="width: 100%; margin-top: 5px;">
210         <el-table-column
211           prop=""
212           label="键"
5e26f4 213           min-width="150"
2f0aa4 214           align="center">
6badb7 215           <template #default="scope">
22bece 216             <el-input v-model="scope.row.key" maxlength="20" clearable :disabled="true"
6badb7 217                       style="width:100%;hight:100%"/>
2f0aa4 218           </template>
219         </el-table-column>
220         <el-table-column
221           prop=""
222           label="名称"
5e26f4 223           min-width="150"
2f0aa4 224           align="center">
6badb7 225           <template #default="scope">
22bece 226             <el-input v-model="scope.row.name" maxlength="20" clearable :disabled="true"
6badb7 227                       style="width:100%;hight:100%"/>
2f0aa4 228           </template>
229         </el-table-column>
230         <el-table-column
231           prop=""
232           label="类型"
5e26f4 233           min-width="100"
2f0aa4 234           align="center">
6badb7 235           <template #default="scope">
22bece 236             <el-select v-model="scope.row.valuetype" placeholder="请选择" :disabled="true">
d3ee81 237               <el-option
238                 v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_METHOD_SETTING_VALUE_TYPE)"
239                 :key="dict.value"
240                 :label="dict.label"
241                 :value="dict.value"
242               />
243             </el-select>
2f0aa4 244           </template>
245         </el-table-column>
246         <el-table-column
247           prop=""
248           label="值"
5e26f4 249           min-width="300"
2f0aa4 250           align="center">
6badb7 251           <template #default="scope">
5e26f4 252             <el-input v-model="scope.row.value" maxlength="256" clearable
253                       :disabled="scope.row.key === 'pyFile_BAK'"
6badb7 254                       style="width:100%;hight:100%"/>
2f0aa4 255           </template>
256         </el-table-column>
257       </el-table>
23c8b8 258       <el-divider content-position="left">模型下发配置</el-divider>
D 259       <el-row :gutter="20">
260         <el-col :span="4">
261           <el-button type="primary" size="small" @click="addRowOut()" >新增</el-button>
262         </el-col>
263       </el-row>
264       <el-table
265         :data="formData.modelOut"
266         border
267         style="width: 100%; margin-top: 5px;">
fa3d25 268         <el-table-column prop="resultKey" label="输出key" align="center" min-width="100">
23c8b8 269           <template #default="scope">
D 270             <el-input size="mini" v-model="scope.row.resultKey" style="width:100%;height:100%"/>
271           </template>
272         </el-table-column>
fa3d25 273         <el-table-column prop="resultType" label="数据类型" align="center" min-width="150">
23c8b8 274           <template #default="scope">
fa3d25 275             <el-select v-model="scope.row.resultType" placeholder="请选择">
D 276               <el-option
277                 v-for="dict in getStrDictOptions(DICT_TYPE.RESULT_TYPE)"
278                 :key="dict.value"
279                 :label="dict.label"
280                 :value="dict.value"
281               />
282             </el-select>
23c8b8 283           </template>
D 284         </el-table-column>
285         <el-table-column prop="resultPort" label="角标1" align="center" min-width="100">
286           <template #default="scope">
287             <el-input-number :min="0" clearable controls-position="right" size="mini" v-model="scope.row.resultPort" style="width:100%;height:100%"/>
288           </template>
289         </el-table-column>
290         <el-table-column prop="resultIndex" label="角标2" align="center" min-width="100">
291           <template #default="scope">
292             <el-input-number :min="0" clearable controls-position="right" size="mini" v-model="scope.row.resultIndex" style="width:100%;height:100%"/>
293           </template>
294         </el-table-column>
295         <el-table-column prop="isWrite" label="是否下发" align="center" min-width="100">
296           <template #default="scope">
297             <el-switch size="small" v-model="scope.row.isWrite" :active-value="1"
298                        :inactive-value="0"/>
299           </template>
300         </el-table-column>
301         <el-table-column
302           prop=""
303           label="测点名称"
304           align="center" min-width="200">
305           <template #default="scope">
306             <el-select v-model="scope.row.pointNo"
307                        filterable
308                        placeholder="请选择">
309               <el-option
310                 v-for="(item, index) in modelparamListMap['DATAPOINT']"
311                 :key="index"
312                 :label="item.name"
313                 :value="item.itemNo"/>
314             </el-select>
315           </template>
316         </el-table-column>
317         <el-table-column prop="disturbancePointNo’" label="无扰切换点位" align="center" min-width="200">
318           <template #default="scope">
319             <el-select v-model="scope.row.disturbancePointNo"
4d3aa7 320                        clearable
23c8b8 321                        filterable
D 322                        placeholder="请选择">
323               <el-option
324                 v-for="(item, index) in modelparamListMap['DATAPOINT']"
325                 :key="index"
326                 :label="item.name"
327                 :value="item.itemNo"/>
328             </el-select>
329           </template>
330         </el-table-column>
331         <el-table-column label="操作" fixed="right" header-align="center" align="center" width="100">
332           <template #default="scope">
333             <el-button
334               @click="deleteModelOutRow(scope.$index)"
335               key="danger"
336               type="danger"
337               link
338             >删除
339             </el-button>
340           </template>
341         </el-table-column>
342       </el-table>
2f0aa4 343     </el-form>
344     <template #footer>
345       <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
346       <el-button @click="dialogVisible = false">取 消</el-button>
347     </template>
348   </Dialog>
349 </template>
350 <script lang="ts" setup>
8ea580 351   import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
2f0aa4 352   import * as ScheduleModelApi from '@/api/model/sche/model'
353   import { CommonStatusEnum } from '@/utils/constants'
22bece 354   import * as MpkApi from "@/api/model/mpk/mpk";
23c8b8 355   import {generateUUID} from "@/utils";
2f0aa4 356
357   defineOptions({ name: 'ScheduleModelForm' })
358
359   const { t } = useI18n() // 国际化
360   const message = useMessage() // 消息弹窗
361   const dialogVisible = ref(false) // 弹窗的是否展示
362   const dialogTitle = ref('') // 弹窗的标题
363   const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
364   const formType = ref('') // 表单的类型:create - 新增;update - 修改
365   const formData = ref({
366     id: undefined,
367     modelCode: undefined,
368     modelName: undefined,
369     modelType: undefined,
370     className: undefined,
371     methodName: undefined,
372     portLength: undefined,
373     paramStructure: undefined,
374     modelPath: undefined,
375     resultStrId: undefined,
376     invocation: undefined,
8ea580 377     status: CommonStatusEnum.ENABLE,
22bece 378     paramList: [],
23c8b8 379     settingList: [],
D 380     modelOut: []
2f0aa4 381   })
382   const formRules = reactive({
383     modelCode: [{ required: true, message: '模型编号不能为空', trigger: 'blur' }],
384     modelName: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
385     modelType: [{ required: true, message: '模型类型不能为空', trigger: 'blur' }]
386   })
387   const formRef = ref() // 表单 Ref
6badb7 388   const modelparamListMap = ref({})
22bece 389   // 调度模型列表
D 390   const scheduleModelList = ref([])
391   const model = ref()
392   const modelPopover = ref()
2f0aa4 393
394   const addRow = function (index, rows) {
395     let row = JSON.parse(JSON.stringify(rows[index]))
396     rows.splice(index, 0, row)
397     this.orderRow(rows)
398   }
399
22bece 400   const deleteRow = function (index, row, rows) {
D 401     if (!rows || rows.length === 1 || rows.filter(e => e.modelparamportorder === row.modelparamportorder).length === 1) {
402       message.error('不可删除!')
2f0aa4 403       return
404     }
405     rows.splice(index, 1)
406     this.orderRow(rows)
407   }
408
409   const orderRow = function (rows) {
410     let modelparamorder = 0
411     let modelparamportorder = 0
412     rows.forEach(function (value) {
413       if (value.modelparamportorder !== modelparamportorder) {
414         modelparamportorder = value.modelparamportorder
415         modelparamorder = 1
416       }
417       value.modelparamorder = modelparamorder
418       modelparamorder++
419     })
420   }
421
422   /** 打开弹窗 */
423   const open = async (type: string, id?: number) => {
424     dialogVisible.value = true
425     dialogTitle.value = t('action.' + type)
426     formType.value = type
427     resetForm()
428     // 修改时,设置数据
429     if (id) {
430       formLoading.value = true
431       try {
432         formData.value = await ScheduleModelApi.getScheduleModel(id)
433       } finally {
434         formLoading.value = false
435       }
436     }
d3ee81 437     // 加载参数列表
438     modelparamListMap.value = await ScheduleModelApi.getModelParamList()
22bece 439     // 加载调度模型列表
D 440     getScheduleModelList()
2f0aa4 441   }
442   defineExpose({ open }) // 提供 open 方法,用于打开弹窗
443
444   /** 提交表单 */
445   const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
446   const submitForm = async () => {
447     // 校验表单
448     if (!formRef) return
449     const valid = await formRef.value.validate()
450     if (!valid) return
451     // 提交请求
452     formLoading.value = true
453     try {
454       const data = formData.value as unknown as ScheduleModelApi.ScheduleModelVO
455       if (formType.value === 'create') {
456         await ScheduleModelApi.createScheduleModel(data)
457         message.success(t('common.createSuccess'))
458       } else {
459         await ScheduleModelApi.updateScheduleModel(data)
460         message.success(t('common.updateSuccess'))
461       }
462       dialogVisible.value = false
463       // 发送操作成功的事件
464       emit('success')
465     } finally {
466       formLoading.value = false
467     }
468   }
469
470   /** 重置表单 */
471   const resetForm = () => {
472     formData.value = {
473       id: undefined,
474       modelCode: undefined,
475       modelName: undefined,
476       modelType: undefined,
477       className: undefined,
478       methodName: undefined,
479       portLength: undefined,
480       paramStructure: undefined,
481       modelPath: undefined,
482       resultStrId: undefined,
483       invocation: undefined,
6badb7 484       status: CommonStatusEnum.ENABLE,
22bece 485       paramList: [],
23c8b8 486       settingList: [],
D 487       modelOut: []
2f0aa4 488     }
489     formRef.value?.resetFields()
490   }
22bece 491
D 492   const getScheduleModelList = async () => {
493     let list = await MpkApi.list({pyType: 'schedul'})
494     if (list && list.length > 0) {
495       scheduleModelList.value = list.map(e => {
496         return {
497           label: e.pyChineseName,
498           value: e,
499           children: e.modelMethods.map(m => {
500             return {
501               label: m.methodName,
502               value: m
503             }
504           })
505         }
506       })
507     }
508   }
509
510   // 选择调度模型
511   const changeModel = async () => {
512     // 校验
513     if (model.value && model.value.length > 0) {
514       const modelInfo = model.value[0]
515       const methodInfo = model.value[1]
516       formData.value.modelName = modelInfo.pyChineseName
517       formData.value.className = modelInfo.pkgName + '.impl.' + modelInfo.pyName + 'Impl';
518       formData.value.methodName = methodInfo.methodName
519       formData.value.portLength = methodInfo.dataLength
520       // 参数构造
521       let paramStructure = []
522       for (let i = 0; i < methodInfo.dataLength; i++) {
523         paramStructure.push('[[D')
524       }
525       if (methodInfo.model === 1) {
526         paramStructure.push('java.util.HashMap')
527       }
528       paramStructure.push('java.util.HashMap')
529       formData.value.paramStructure = paramStructure.join(',')
530       formData.value.modelPath = modelInfo.pyModule
531       // 输入参数
532       let paramList = []
533       for (let i = 0; i < methodInfo.dataLength; i++) {
534         paramList.push({
535           modelparamportorder: i+1 + '',
536           modelparamorder: '1',
537           modelparamtype: '',
538           modelparamid: '',
539           datalength: 0
540         })
541       }
542
543       formData.value.paramList = paramList
544       // 设置参数
545       let settingList = []
546       methodInfo.methodSettings.forEach(e => {
547         settingList.push({
548           key: e.settingKey,
549           value: e.value,
550           valuetype: e.valueType,
551           name: e.name
552         })
553       })
554       formData.value.settingList = settingList
555       modelPopover.value.hide()
556     }else {
557       message.error("请先选择模型")
558     }
559   }
560
561   function changeModelparamtype(row) {
562     row.modelparamid = ''
563   }
23c8b8 564   const addRowOut= function () {
D 565     if(formData.value.modelOut===undefined) {
566       formData.value.modelOut = []
567     }
568     formData.value.modelOut.push({
569       id: generateUUID(),
570       resultKey: undefined,
571       resultType: "double[][]",
572       port: 0,
573       index: 0,
574       isWrite: 1,
575       pointNo:undefined,
576       sort:undefined,
577       disturbancePointNo:undefined,
578     })
579   }
580   const deleteModelOutRow = function (index) {
581     formData.value.modelOut.splice(index, 1)
582   }
2f0aa4 583 </script>