dongyukun
7 天以前 23c8b8154fcf7c9251d07f028f3e14737ba4cecd
提交 | 用户 | 时间
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="键"
213           align="center">
6badb7 214           <template #default="scope">
22bece 215             <el-input v-model="scope.row.key" maxlength="20" clearable :disabled="true"
6badb7 216                       style="width:100%;hight:100%"/>
2f0aa4 217           </template>
218         </el-table-column>
219         <el-table-column
220           prop=""
221           label="名称"
222           align="center">
6badb7 223           <template #default="scope">
22bece 224             <el-input v-model="scope.row.name" maxlength="20" clearable :disabled="true"
6badb7 225                       style="width:100%;hight:100%"/>
2f0aa4 226           </template>
227         </el-table-column>
228         <el-table-column
229           prop=""
230           label="类型"
231           align="center">
6badb7 232           <template #default="scope">
22bece 233             <el-select v-model="scope.row.valuetype" placeholder="请选择" :disabled="true">
d3ee81 234               <el-option
235                 v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_METHOD_SETTING_VALUE_TYPE)"
236                 :key="dict.value"
237                 :label="dict.label"
238                 :value="dict.value"
239               />
240             </el-select>
2f0aa4 241           </template>
242         </el-table-column>
243         <el-table-column
244           prop=""
245           label="值"
246           align="center">
6badb7 247           <template #default="scope">
22bece 248             <el-input v-model="scope.row.value" maxlength="256" clearable  :disabled="scope.row.key === 'pyFile'"
6badb7 249                       style="width:100%;hight:100%"/>
2f0aa4 250           </template>
251         </el-table-column>
22bece 252 <!--        <el-table-column-->
D 253 <!--          prop=""-->
254 <!--          label="操作"-->
255 <!--          width="100"-->
256 <!--          align="center">-->
257 <!--          <template #default="scope">-->
258 <!--            <el-button-->
259 <!--              @click.prevent="addRow(scope.$index, formData.settingList)"-->
260 <!--              link-->
261 <!--              type="primary"-->
262 <!--              size="small">-->
263 <!--              添加-->
264 <!--            </el-button>-->
265 <!--            <el-button-->
266 <!--              @click.prevent="deleteRow(scope.$index, formData.settingList)"-->
267 <!--              link-->
268 <!--              type="primary"-->
269 <!--              size="small">-->
270 <!--              删除-->
271 <!--            </el-button>-->
272 <!--          </template>-->
273 <!--        </el-table-column>-->
2f0aa4 274       </el-table>
23c8b8 275       <el-divider content-position="left">模型下发配置</el-divider>
D 276       <el-row :gutter="20">
277         <el-col :span="4">
278           <el-button type="primary" size="small" @click="addRowOut()" >新增</el-button>
279         </el-col>
280       </el-row>
281       <el-table
282         :data="formData.modelOut"
283         border
284         style="width: 100%; margin-top: 5px;">
285         <el-table-column prop="resultKey`" label="输出key" align="center" min-width="100">
286           <template #default="scope">
287             <el-input size="mini" v-model="scope.row.resultKey" style="width:100%;height:100%"/>
288           </template>
289         </el-table-column>
290         <el-table-column prop="resultType`" label="数据类型" align="center" min-width="100">
291           <template #default="scope">
292             <el-input size="mini" v-model="scope.row.resultType" style="width:100%;height:100%"/>
293           </template>
294         </el-table-column>
295         <el-table-column prop="resultPort" label="角标1" align="center" min-width="100">
296           <template #default="scope">
297             <el-input-number :min="0" clearable controls-position="right" size="mini" v-model="scope.row.resultPort" style="width:100%;height:100%"/>
298           </template>
299         </el-table-column>
300         <el-table-column prop="resultIndex" label="角标2" align="center" min-width="100">
301           <template #default="scope">
302             <el-input-number :min="0" clearable controls-position="right" size="mini" v-model="scope.row.resultIndex" style="width:100%;height:100%"/>
303           </template>
304         </el-table-column>
305         <el-table-column prop="isWrite" label="是否下发" align="center" min-width="100">
306           <template #default="scope">
307             <el-switch size="small" v-model="scope.row.isWrite" :active-value="1"
308                        :inactive-value="0"/>
309           </template>
310         </el-table-column>
311         <el-table-column
312           prop=""
313           label="测点名称"
314           align="center" min-width="200">
315           <template #default="scope">
316             <el-select v-model="scope.row.pointNo"
317                        filterable
318                        placeholder="请选择">
319               <el-option
320                 v-for="(item, index) in modelparamListMap['DATAPOINT']"
321                 :key="index"
322                 :label="item.name"
323                 :value="item.itemNo"/>
324             </el-select>
325           </template>
326         </el-table-column>
327         <el-table-column prop="disturbancePointNo’" label="无扰切换点位" align="center" min-width="200">
328           <template #default="scope">
329             <el-select v-model="scope.row.disturbancePointNo"
330                        filterable
331                        placeholder="请选择">
332               <el-option
333                 v-for="(item, index) in modelparamListMap['DATAPOINT']"
334                 :key="index"
335                 :label="item.name"
336                 :value="item.itemNo"/>
337             </el-select>
338           </template>
339         </el-table-column>
340         <el-table-column label="操作" fixed="right" header-align="center" align="center" width="100">
341           <template #default="scope">
342             <el-button
343               @click="deleteModelOutRow(scope.$index)"
344               key="danger"
345               type="danger"
346               link
347             >删除
348             </el-button>
349           </template>
350         </el-table-column>
351       </el-table>
2f0aa4 352     </el-form>
353     <template #footer>
354       <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
355       <el-button @click="dialogVisible = false">取 消</el-button>
356     </template>
357   </Dialog>
358 </template>
359 <script lang="ts" setup>
8ea580 360   import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
2f0aa4 361   import * as ScheduleModelApi from '@/api/model/sche/model'
362   import { CommonStatusEnum } from '@/utils/constants'
22bece 363   import * as MpkApi from "@/api/model/mpk/mpk";
23c8b8 364   import {generateUUID} from "@/utils";
2f0aa4 365
366   defineOptions({ name: 'ScheduleModelForm' })
367
368   const { t } = useI18n() // 国际化
369   const message = useMessage() // 消息弹窗
370   const dialogVisible = ref(false) // 弹窗的是否展示
371   const dialogTitle = ref('') // 弹窗的标题
372   const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
373   const formType = ref('') // 表单的类型:create - 新增;update - 修改
374   const formData = ref({
375     id: undefined,
376     modelCode: undefined,
377     modelName: undefined,
378     modelType: undefined,
379     className: undefined,
380     methodName: undefined,
381     portLength: undefined,
382     paramStructure: undefined,
383     modelPath: undefined,
384     resultStrId: undefined,
385     invocation: undefined,
8ea580 386     status: CommonStatusEnum.ENABLE,
22bece 387     paramList: [],
23c8b8 388     settingList: [],
D 389     modelOut: []
2f0aa4 390   })
391   const formRules = reactive({
392     modelCode: [{ required: true, message: '模型编号不能为空', trigger: 'blur' }],
393     modelName: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
394     modelType: [{ required: true, message: '模型类型不能为空', trigger: 'blur' }]
395   })
396   const formRef = ref() // 表单 Ref
6badb7 397   const modelparamListMap = ref({})
22bece 398   // 调度模型列表
D 399   const scheduleModelList = ref([])
400   const model = ref()
401   const modelPopover = ref()
2f0aa4 402
403   const addRow = function (index, rows) {
404     let row = JSON.parse(JSON.stringify(rows[index]))
405     rows.splice(index, 0, row)
406     this.orderRow(rows)
407   }
408
22bece 409   const deleteRow = function (index, row, rows) {
D 410     if (!rows || rows.length === 1 || rows.filter(e => e.modelparamportorder === row.modelparamportorder).length === 1) {
411       message.error('不可删除!')
2f0aa4 412       return
413     }
414     rows.splice(index, 1)
415     this.orderRow(rows)
416   }
417
418   const orderRow = function (rows) {
419     let modelparamorder = 0
420     let modelparamportorder = 0
421     rows.forEach(function (value) {
422       if (value.modelparamportorder !== modelparamportorder) {
423         modelparamportorder = value.modelparamportorder
424         modelparamorder = 1
425       }
426       value.modelparamorder = modelparamorder
427       modelparamorder++
428     })
429   }
430
431   /** 打开弹窗 */
432   const open = async (type: string, id?: number) => {
433     dialogVisible.value = true
434     dialogTitle.value = t('action.' + type)
435     formType.value = type
436     resetForm()
437     // 修改时,设置数据
438     if (id) {
439       formLoading.value = true
440       try {
441         formData.value = await ScheduleModelApi.getScheduleModel(id)
442       } finally {
443         formLoading.value = false
444       }
445     }
d3ee81 446     // 加载参数列表
447     modelparamListMap.value = await ScheduleModelApi.getModelParamList()
22bece 448     // 加载调度模型列表
D 449     getScheduleModelList()
2f0aa4 450   }
451   defineExpose({ open }) // 提供 open 方法,用于打开弹窗
452
453   /** 提交表单 */
454   const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
455   const submitForm = async () => {
456     // 校验表单
457     if (!formRef) return
458     const valid = await formRef.value.validate()
459     if (!valid) return
460     // 提交请求
461     formLoading.value = true
462     try {
463       const data = formData.value as unknown as ScheduleModelApi.ScheduleModelVO
464       if (formType.value === 'create') {
465         await ScheduleModelApi.createScheduleModel(data)
466         message.success(t('common.createSuccess'))
467       } else {
468         await ScheduleModelApi.updateScheduleModel(data)
469         message.success(t('common.updateSuccess'))
470       }
471       dialogVisible.value = false
472       // 发送操作成功的事件
473       emit('success')
474     } finally {
475       formLoading.value = false
476     }
477   }
478
479   /** 重置表单 */
480   const resetForm = () => {
481     formData.value = {
482       id: undefined,
483       modelCode: undefined,
484       modelName: undefined,
485       modelType: undefined,
486       className: undefined,
487       methodName: undefined,
488       portLength: undefined,
489       paramStructure: undefined,
490       modelPath: undefined,
491       resultStrId: undefined,
492       invocation: undefined,
6badb7 493       status: CommonStatusEnum.ENABLE,
22bece 494       paramList: [],
23c8b8 495       settingList: [],
D 496       modelOut: []
2f0aa4 497     }
498     formRef.value?.resetFields()
499   }
22bece 500
D 501   const getScheduleModelList = async () => {
502     let list = await MpkApi.list({pyType: 'schedul'})
503     if (list && list.length > 0) {
504       scheduleModelList.value = list.map(e => {
505         return {
506           label: e.pyChineseName,
507           value: e,
508           children: e.modelMethods.map(m => {
509             return {
510               label: m.methodName,
511               value: m
512             }
513           })
514         }
515       })
516     }
517   }
518
519   // 选择调度模型
520   const changeModel = async () => {
521     // 校验
522     if (model.value && model.value.length > 0) {
523       const modelInfo = model.value[0]
524       const methodInfo = model.value[1]
525       formData.value.modelName = modelInfo.pyChineseName
526       formData.value.className = modelInfo.pkgName + '.impl.' + modelInfo.pyName + 'Impl';
527       formData.value.methodName = methodInfo.methodName
528       formData.value.portLength = methodInfo.dataLength
529       // 参数构造
530       let paramStructure = []
531       for (let i = 0; i < methodInfo.dataLength; i++) {
532         paramStructure.push('[[D')
533       }
534       if (methodInfo.model === 1) {
535         paramStructure.push('java.util.HashMap')
536       }
537       paramStructure.push('java.util.HashMap')
538       formData.value.paramStructure = paramStructure.join(',')
539       formData.value.modelPath = modelInfo.pyModule
540       // 输入参数
541       let paramList = []
542       for (let i = 0; i < methodInfo.dataLength; i++) {
543         paramList.push({
544           modelparamportorder: i+1 + '',
545           modelparamorder: '1',
546           modelparamtype: '',
547           modelparamid: '',
548           datalength: 0
549         })
550       }
551
552       formData.value.paramList = paramList
553       // 设置参数
554       let settingList = []
555       methodInfo.methodSettings.forEach(e => {
556         settingList.push({
557           key: e.settingKey,
558           value: e.value,
559           valuetype: e.valueType,
560           name: e.name
561         })
562       })
563       formData.value.settingList = settingList
564       modelPopover.value.hide()
565     }else {
566       message.error("请先选择模型")
567     }
568   }
569
570   function changeModelparamtype(row) {
571     row.modelparamid = ''
572   }
23c8b8 573   const addRowOut= function () {
D 574     if(formData.value.modelOut===undefined) {
575       formData.value.modelOut = []
576     }
577     formData.value.modelOut.push({
578       id: generateUUID(),
579       resultKey: undefined,
580       resultType: "double[][]",
581       port: 0,
582       index: 0,
583       isWrite: 1,
584       pointNo:undefined,
585       sort:undefined,
586       disturbancePointNo:undefined,
587     })
588   }
589   const deleteModelOutRow = function (index) {
590     formData.value.modelOut.splice(index, 1)
591   }
2f0aa4 592 </script>