潘志宝
2024-10-28 e370f07f4b785f50e3820eecb0a440520562fe94
提交 | 用户 | 时间
7462da 1 <template>
L 2   <Dialog v-model="dialogVisible" :title="dialogTitle" width="50%">
3     <el-form
4       ref="formRef"
5       v-loading="formLoading"
cd9f11 6       :model="dataForm"
7462da 7       :rules="formRules"
be4298 8       label-width="100px"
7462da 9     >
cd9f11 10       <el-divider content-position="left">基本信息</el-divider>
7462da 11       <el-row>
L 12         <el-col :span="12">
d3ee81 13           <el-form-item label="预测项名" prop="mmPredictItem.itemname">
14             <el-input v-model="dataForm.mmPredictItem.itemname" placeholder="预测项名"
15                       maxlength="50"/>
7462da 16           </el-form-item>
L 17         </el-col>
e1ff2d 18         <el-col :span="12">
d3ee81 19           <el-form-item label="编号" prop="mmPredictItem.itemno">
e1ff2d 20             <el-input v-model="dataForm.mmPredictItem.itemno" placeholder="编号" maxlength="50" readonly/>
7462da 21           </el-form-item>
L 22         </el-col>
23       </el-row>
24       <el-row>
25         <el-col :span="12">
d3ee81 26           <el-form-item label="类型" prop="mmPredictItem.itemtypeid">
2caade 27             <el-select
L 28               v-model="dataForm.mmPredictItem.itemtypeid" @change="changeItemtype"
29               placeholder="请选择">
cd9f11 30               <el-option
L 31                 v-for="item in itemTypeList"
32                 :key="item.id"
33                 :label="item.itemtypename"
34                 :value="item.id"/>
35             </el-select>
7462da 36           </el-form-item>
L 37         </el-col>
38         <el-col :span="12">
e1ff2d 39           <el-form-item label="粒度" prop="mmPredictItem.granularity">
d3ee81 40             <el-select v-model="dataForm.mmPredictItem.granularity" placeholder="请选择">
41               <el-option
e1ff2d 42                 v-for="dict in getIntDictOptions(DICT_TYPE.TIME_GRANULARITY)"
d3ee81 43                 :key="dict.value"
44                 :label="dict.label"
45                 :value="dict.value"
46               />
47             </el-select>
7462da 48           </el-form-item>
L 49         </el-col>
50       </el-row>
51       <el-row>
52         <el-col :span="12">
e1ff2d 53           <el-form-item label="是否检查" prop="mmPredictItem.workchecked">
cd9f11 54             <el-select v-model="dataForm.mmPredictItem.workchecked" placeholder="请选择">
L 55               <el-option
d3ee81 56                 v-for="dict in getIntDictOptions(DICT_TYPE.COM_IS_INT)"
57                 :key="dict.value"
58                 :label="dict.label"
59                 :value="dict.value"
60               />
cd9f11 61             </el-select>
7462da 62           </el-form-item>
L 63         </el-col>
64         <el-col :span="12">
e1ff2d 65           <el-form-item label="是否启用" prop="mmPredictItem.status">
d3ee81 66             <el-select v-model="dataForm.mmPredictItem.status" placeholder="请选择">
cd9f11 67               <el-option
d3ee81 68                 v-for="dict in getIntDictOptions(DICT_TYPE.COM_IS_INT)"
69                 :key="dict.value"
70                 :label="dict.label"
71                 :value="dict.value"
72               />
cd9f11 73             </el-select>
7462da 74           </el-form-item>
L 75         </el-col>
76       </el-row>
77       <el-row>
78         <el-col :span="12">
e1ff2d 79           <el-form-item label="管网" prop="dmModuleItem.moduleid">
cd9f11 80             <el-select v-model="dataForm.dmModuleItem.moduleid" placeholder="请选择">
L 81               <el-option
82                 v-for="item in moduleList"
83                 :key="item.id"
84                 :label="item.modulename"
85                 :value="item.id"/>
86             </el-select>
7462da 87           </el-form-item>
L 88         </el-col>
89         <el-col :span="12">
2caade 90           <el-form-item label="类别">
83f63a 91             <el-input v-model="dataForm.dmModuleItem.categoryid" placeholder="类别" maxlength="64"/>
7462da 92           </el-form-item>
L 93         </el-col>
94       </el-row>
95       <el-row>
96         <el-col :span="12">
e1ff2d 97           <el-form-item label="排序" prop="dmModuleItem.itemorder">
d3ee81 98             <el-input-number v-model="dataForm.dmModuleItem.itemorder" :min="1" clearable
99                              controls-position="right"/>
7462da 100           </el-form-item>
L 101         </el-col>
102         <el-col :span="12">
e1ff2d 103           <el-form-item label="数据点" prop="mmItemOutput.pointid">
cd9f11 104             <el-select
L 105               v-model="dataForm.mmItemOutput.pointid"
106               filterable
107               @change="changeOutputPoint"
108               placeholder="请选择">
109               <el-option
110                 v-for="item in pointList"
111                 :key="item.id"
d3ee81 112                 :label="item.pointName"
cd9f11 113                 :value="item.id"/>
L 114             </el-select>
7462da 115           </el-form-item>
L 116         </el-col>
117       </el-row>
cd9f11 118       <el-row v-if="dataForm.itemtypename === 'MergeItem'">
7462da 119         <el-col :span="12">
2caade 120           <el-form-item label="预测长度">
L 121             <el-input
122               v-model="dataForm.mmPredictItem.predictlength" placeholder="预测长度"
123               maxlength="5"/>
7462da 124           </el-form-item>
L 125         </el-col>
126       </el-row>
cd9f11 127       <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型信息
L 128       </el-divider>
d3ee81 129       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
130         <el-col :span="12">
2caade 131           <el-form-item label="模型名称">
L 132             <el-input
133               v-model="dataForm.mmPredictModel.modelname" placeholder="模型名称"
134               maxlength="50"/>
cd9f11 135           </el-form-item>
L 136         </el-col>
7462da 137         <el-col :span="12">
d3ee81 138           <el-upload
139             class="upload-demo"
140             :limit="1"
141             :file-list="fileList"
142             :before-upload="beforeUpload"
143             :on-success="uploadModelSuccess"
144             :on-error="uploadModelError"
145             :action="uploadUrl"
146             :http-request="httpRequest">
147             <el-button type="primary" @click="setReplaceModelOnly(false)">
148               <Icon icon="ep:upload"/>
149               上传模型
150             </el-button>
151             <el-button
152               size="small" type="primary" @click="setReplaceModelOnly(true)"
e1ff2d 153               v-if="formType.value === 'update'">
d3ee81 154               <Icon icon="ep:upload"/>
155               更新模型
156             </el-button>
157           </el-upload>
7462da 158         </el-col>
L 159       </el-row>
be4298 160       <el-row v-if="dataForm.itemtypename === 'NormalItem'">
D 161         <el-col :span="8">
2caade 162           <el-form-item label="结果">
cd9f11 163             <el-select v-model="dataForm.mmPredictModel.resultstrid" placeholder="请选择">
L 164               <el-option
165                 v-for="item in resultstridList"
166                 :key="item.id"
167                 :label="item.resultstr"
168                 :value="item.id"/>
169             </el-select>
170           </el-form-item>
171         </el-col>
be4298 172         <el-col :span="8">
D 173           <el-form-item label="关联模型">
174             <el-select v-model="dataForm.mmPredictModel.mpkprojectid" placeholder="请选择">
175               <el-option
176                 v-for="item in mpkProjectList"
177                 :key="item.id"
178                 :label="item.projectName"
179                 :value="item.id"/>
180             </el-select>
181           </el-form-item>
182         </el-col>
183         <el-col :span="8">
e1ff2d 184           <el-form-item label="编号">
d3ee81 185             <el-input
e1ff2d 186               v-model="dataForm.mmPredictModel.modelno" placeholder="编号" maxlength="30" readonly
d3ee81 187               disabled/>
188           </el-form-item>
189         </el-col>
cd9f11 190       </el-row>
d3ee81 191       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
cd9f11 192         <el-col :span="24">
2caade 193           <el-form-item label="路径">
L 194             <el-input
195               v-model="dataForm.mmPredictModel.modelpath" placeholder="路径" maxlength="32"
196               disabled/>
cd9f11 197           </el-form-item>
L 198         </el-col>
199       </el-row>
d3ee81 200       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
cd9f11 201         <el-col :span="24">
2caade 202           <el-form-item label="类名">
L 203             <el-input
204               v-model="dataForm.mmPredictModel.classname" placeholder="类名" maxlength="32"
205               disabled/>
cd9f11 206           </el-form-item>
L 207         </el-col>
208       </el-row>
d3ee81 209       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
cd9f11 210         <el-col :span="12">
2caade 211           <el-form-item label="方法名">
L 212             <el-input
213               v-model="dataForm.mmPredictModel.methodname" placeholder="方法名"
214               maxlength="32" disabled/>
cd9f11 215           </el-form-item>
L 216         </el-col>
217         <el-col :span="12">
2caade 218           <el-form-item label="参数">
L 219             <el-input
220               v-model="dataForm.mmPredictModel.modelparamstructure" placeholder="参数"
221               maxlength="32" disabled/>
cd9f11 222           </el-form-item>
L 223         </el-col>
224       </el-row>
225       <el-table
226         v-if="dataForm.itemtypename === 'NormalItem'"
227         :data="dataForm.mmModelArithSettingsList"
228         border
229         style="width: 100%; margin-top: 5px;">
230         <el-table-column prop="key" label="键" align="center"/>
231         <el-table-column prop="name" label="名称" align="center"/>
232         <el-table-column prop="valuetype" label="类型" align="center"/>
d3ee81 233         <el-table-column prop="" label="值" align="center" min-width="150">
cd9f11 234           <template #default="scope">
d3ee81 235             <el-input size="mini" v-model="scope.row.value" maxlength="256"
236                       style="width:100%;height:100%"/>
cd9f11 237           </template>
L 238         </el-table-column>
239       </el-table>
240       <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">输入参数
241       </el-divider>
242       <el-table
2caade 243         v-if="dataForm.itemtypename === 'NormalItem'"
cd9f11 244         :data="dataForm.mmModelParamList"
L 245         border
246         style="width: 100%; margin-top: 5px;">
247         <el-table-column prop="modelparamportorder" label="端口" width="60" align="center"/>
248         <el-table-column prop="modelparamorder" label="序号" width="60" align="center"/>
249         <el-table-column prop="" label="类型" width="200" align="center">
250           <template #default="scope">
d3ee81 251             <el-select v-model="scope.row.modelparamtype" placeholder="请选择">
cd9f11 252               <el-option
d3ee81 253                 v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_PARAM_TYPE)"
254                 :key="dict.value"
255                 :label="dict.label"
256                 :value="dict.value"
257               />
cd9f11 258             </el-select>
L 259           </template>
260         </el-table-column>
261         <el-table-column prop="" label="参数名称" align="center">
262           <template #default="scope">
263             <el-select
264               v-model="scope.row.modelparamid"
265               filterable
266               @change="changeModelparam(scope.row)"
267               placeholder="请选择">
268               <el-option
269                 v-for="(item, index) in modelparamListMap[scope.row.modelparamtype]"
270                 :key="index"
271                 :label="item.name"
272                 :value="item.id"/>
273             </el-select>
274           </template>
275         </el-table-column>
276         <el-table-column prop="" label="参数长度" width="120" align="center">
277           <template #default="scope">
e1ff2d 278             <el-input-number v-model="scope.row.datalength" :min="0" clearable
279                              controls-position="right"
280                              style="width:100%;hight:100%"/>
cd9f11 281           </template>
L 282         </el-table-column>
2caade 283         <el-table-column prop="" label="操作" width="140" align="center">
cd9f11 284           <template #default="scope">
L 285             <el-button
286               @click="addRow(scope.$index, dataForm.mmModelParamList)"
287               type="text"
288               size="small">
289               添加
290             </el-button>
291             <el-button
292               @click="deleteRow(scope.$index, dataForm.mmModelParamList)"
293               type="text"
294               size="small">
295               删除
296             </el-button>
297           </template>
298         </el-table-column>
299       </el-table>
300       <el-divider content-position="left" v-if="dataForm.itemtypename === 'MergeItem'">表达式
301       </el-divider>
302       <el-table
2caade 303         v-if="dataForm.itemtypename === 'MergeItem'"
cd9f11 304         :data="expressionList"
L 305         border
306         style="width: 100%; margin-top: 5px;">
307         <el-table-column
308           prop=""
309           label="预测项"
310           align="center">
311           <template #default="scope">
312             <el-select
313               v-model="scope.row.point"
314               filterable
315               placeholder="请选择">
316               <el-option
317                 v-for="(item, index) in predictItemList"
318                 :key="index"
319                 :label="item.name"
320                 :value="item.code"/>
321             </el-select>
322           </template>
323         </el-table-column>
324         <el-table-column
325           prop="point"
326           label="编号"
327           align="center"/>
328         <el-table-column
329           prop=""
330           label="运算符"
331           align="center">
332           <template #default="scope">
333             <el-select v-model="scope.row.operator" placeholder="请选择">
334               <el-option
335                 v-for="item in operatorList"
336                 :key="item"
337                 :label="item"
338                 :value="item"/>
339             </el-select>
340           </template>
341         </el-table-column>
342         <el-table-column
343           prop=""
344           label="操作"
2caade 345           width="140"
cd9f11 346           align="center">
L 347           <template #default="scope">
348             <el-button
349               @click="addExpressionRow(scope.$index, expressionList)"
350               type="text"
351               size="small">
352               添加
353             </el-button>
354             <el-button
355               @click="deleteExpressionRow(scope.$index, expressionList)"
356               type="text"
357               size="small">
358               删除
359             </el-button>
360           </template>
361         </el-table-column>
362       </el-table>
7462da 363     </el-form>
L 364     <template #footer>
365       <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
366       <el-button @click="dialogVisible = false">取 消</el-button>
367     </template>
368   </Dialog>
369 </template>
370 <script lang="ts" setup>
d3ee81 371 import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'
7462da 372 import * as MmPredictItem from '@/api/model/pre/predict'
cd9f11 373 import * as MmItemType from '@/api/model/pre/item'
L 374 import * as DmModule from '@/api/model/pre/dm'
375 import * as MmResultTable from '@/api/model/pre/result'
be4298 376 import * as ProjectApi from '@/api/model/mpk/project'
cd9f11 377 import * as DaPoint from '@/api/data/da/point'
d3ee81 378 import {useUpload} from '@/api/model/pre/predict'
e1ff2d 379 import * as ScheduleModelApi from '@/api/model/sche/model'
d3ee81 380
381 const {uploadUrl, httpRequest} = useUpload()
7462da 382
L 383 defineOptions({name: 'DataMmPredictItemForm'})
384
385 const {t} = useI18n() // 国际化
386 const message = useMessage() // 消息弹窗
387 const dialogVisible = ref(false) // 弹窗的是否展示
388 const dialogTitle = ref('') // 弹窗的标题
389 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
390 const formType = ref('') // 表单的类型:create - 新增;update - 修改
cd9f11 391 const itemTypeList = ref([])
L 392 const itemTypeMap = ref({})
393 const moduleList = ref([])
394 const resultstridList = ref([])
be4298 395 const mpkProjectList = ref([])
2caade 396 const pointNoList = ref([])
cd9f11 397 const pointList = ref([])
L 398 const pointMap = ref({})
399 const predictItemList = ref([])
d3ee81 400 const modelparamListMap = ref({})
cd9f11 401 const modelparamMap = ref({})
L 402 const expressionList = ref([])
403 const fileList = ref([])
404 const operatorList = ['+', '-']
d3ee81 405 const replaceModelOnly = ref(false)
cd9f11 406 const queryParams = reactive({
L 407   pageNo: 1,
408   pageSize: 10,
409   pointNo: undefined,
410   pointName: undefined,
411 })
412 const dataForm = ref({
2caade 413   id: undefined,
e1ff2d 414   itemtypename: 'NormalItem',
cd9f11 415   mmPredictItem: {
2caade 416     id: undefined,
L 417     itemno: undefined,
418     itemname: undefined,
419     caltypeid: undefined,
420     itemtypeid: undefined,
421     predictlength: undefined,
d3ee81 422     granularity: 60,
2caade 423     status: undefined,
L 424     isfuse: undefined,
425     predictphase: undefined,
d3ee81 426     workchecked: 0,
2caade 427     unittransfactor: undefined,
L 428     saveindex: undefined
cd9f11 429   },
L 430   dmModuleItem: {
2caade 431     id: undefined,
L 432     moduleid: undefined,
433     itemid: undefined,
d3ee81 434     itemorder: 1,
2caade 435     status: undefined,
L 436     categoryid: undefined
cd9f11 437   },
L 438   mmItemOutput: {
2caade 439     id: undefined,
L 440     itemid: undefined,
441     pointid: undefined,
442     resulttableid: undefined,
443     tagname: undefined,
444     outputorder: undefined
cd9f11 445   },
L 446   mmPredictModel: {
2caade 447     id: undefined,
L 448     modelno: undefined,
449     modelname: undefined,
450     itemid: undefined,
451     arithid: undefined,
452     trainsamplength: undefined,
453     predictsamplength: undefined,
454     isonlinetrain: undefined,
455     modelpath: undefined,
456     isnormal: undefined,
457     normalmax: undefined,
458     normalmin: undefined,
459     status: undefined,
460     classname: undefined,
461     methodname: undefined,
462     modelparamstructure: undefined,
463     resultstrid: undefined,
be4298 464     settingmap: undefined,
D 465     mpkprojectid: undefined
cd9f11 466   },
L 467   mmPredictMergeItem: {
2caade 468     id: undefined,
L 469     itemid: undefined,
470     expression: undefined,
471     num: undefined
cd9f11 472   },
L 473   mmModelArithSettingsList: [],
474   mmModelParamList: []
7462da 475 })
L 476 const formRules = reactive({
d3ee81 477   'mmPredictItem.itemname': [{required: true, message: '预测项名不能为空', trigger: 'blur'}],
478   'mmPredictItem.itemtypeid': [{required: true, message: '类型不能为空', trigger: 'blur'}],
e1ff2d 479   'mmPredictItem.granularity': [{
d3ee81 480     required: true,
481     message: '粒度不能为空',
482     trigger: 'blur'
483   }],
e1ff2d 484   'mmPredictItem.workchecked': [{
d3ee81 485     required: true,
486     message: '是否检查不能为空',
487     trigger: 'blur'
488   }],
e1ff2d 489   'mmPredictItem.status': [{required: true, message: '是否启用不能为空', trigger: 'blur'}],
490   'dmModuleItem.moduleid': [{required: true, message: '管网不能为空', trigger: 'blur'}],
491   'dmModuleItem.itemorder': [{required: true, message: '排序不能为空', trigger: 'blur'}],
492   'mmItemOutput.pointid': [{required: true, message: '数据点不能为空', trigger: 'blur'}],
d3ee81 493
7462da 494 })
L 495 const formRef = ref() // 表单 Ref
496
497 /** 打开弹窗 */
2caade 498 const open = async (type: string, id?: number, itemtypename?: string) => {
e1ff2d 499   formType.value = type
7462da 500   dialogVisible.value = true
L 501   dialogTitle.value = t('action.' + type)
2caade 502   dataForm.value.itemtypename = itemtypename || 'NormalItem'
e1ff2d 503   resetForm()
2caade 504   resetFields(dataForm.value)
83f63a 505   setDefaultFields()
7462da 506   // 修改时,设置数据
L 507   if (id) {
508     formLoading.value = true
509     try {
83f63a 510       getInfo(id)
7462da 511     } finally {
e1ff2d 512       /*formLoading.value = false*/
7462da 513     }
L 514   }
e1ff2d 515
516   // 加载参数列表
517   modelparamListMap.value = await ScheduleModelApi.getModelParamList()
518
519   // 获取预测项类型列表
520   itemTypeList.value = await MmItemType.getItemTypeList()
521   itemTypeList.value.forEach(function (value) {
522     itemTypeMap[value.id] = value.itemtypename
523   })
524   if (!dataForm.value.id) {
525     dataForm.value.mmPredictItem.itemtypeid = itemTypeList.value[0].id
526   }
527   dataForm.value.itemtypename = itemTypeMap[dataForm.value.mmPredictItem.itemtypeid]
528
529   // 获取管网列表
530   moduleList.value = await DmModule.getModuleList()
531
532   // 获取结果字符串列表
533   resultstridList.value = await MmResultTable.getResultstridList()
534
be4298 535   // 获取mpk项目列表
D 536   mpkProjectList.value = await ProjectApi.list()
537
e1ff2d 538   // 获取数据点列表
539   pointNoList.value = await DaPoint.getPointList(queryParams)
540   if (pointNoList.value.length > 0) {
541     pointNoList.value.forEach(function (value) {
542       pointList.value.push(value)
543       pointMap[value.id] = value.pointname
544     })
545   }
546
547   formLoading.value = false
7462da 548 }
L 549 defineExpose({open}) // 提供 open 方法,用于打开弹窗
550
551 /** 提交表单 */
552 const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
553 const submitForm = async () => {
554   // 校验表单
555   if (!formRef) return
556   const valid = await formRef.value.validate()
557   if (!valid) return
558   // 提交请求
559   formLoading.value = true
560   try {
cd9f11 561     const data = dataForm.value as unknown as MmPredictItem.MmPredictItemVO
b39d0b 562     if (expressionList.value && expressionList.value.length > 0) {
L 563       let expression = ''
564       for (let i = 0; i < expressionList.value.length; i++) {
565         let value = expressionList.value[i]
566         expression = expression + value.point + (i === (expressionList.value.length - 1) ? '' : value.operator)
567       }
568       dataForm.value.mmPredictMergeItem.expression = expression
569     } else {
570       dataForm.value.mmPredictMergeItem.expression = ''
571     }
572     if (dataForm.value.mmModelArithSettingsList) {
573       for (let item of dataForm.value.mmModelArithSettingsList) {
574         if (item.key === 'lenpredict') {
575           dataForm.value.mmPredictItem.predictlength = item.value
576         }
577       }
578     }
7462da 579     if (formType.value === 'create') {
L 580       await MmPredictItem.createMmPredictItem(data)
581       message.success(t('common.createSuccess'))
582     } else {
583       await MmPredictItem.updateMmPredictItem(data)
584       message.success(t('common.updateSuccess'))
585     }
586     dialogVisible.value = false
587     // 发送操作成功的事件
588     emit('success')
589   } finally {
590     formLoading.value = false
591   }
592 }
83f63a 593
2caade 594 const resetFields = (obj) => {
L 595   for (let key in obj) {
596     if (key === 'itemtypename') {
597       continue
598     }
599     if (obj[key] instanceof Array) {
600       obj[key] = []
601     } else if (obj[key] instanceof Object) {
602       resetFields(obj[key])
603     } else {
604       obj[key] = ''
605     }
606   }
607 }
608
609 const getInfo = async (id) => {
610   dataForm.value = await MmPredictItem.getMmPredictItem(id)
83f63a 611   expressionList.value = []
2caade 612   if (dataForm.value.mmPredictMergeItem && dataForm.value.mmPredictMergeItem.expression) {
L 613     let expression = dataForm.value.mmPredictMergeItem.expression
83f63a 614     do {
L 615       let indexPlus = expression.indexOf('+')
616       let indexSub = expression.indexOf('-')
617       if (indexPlus !== -1 || indexSub !== -1) {
618         let endIndex = (indexSub == -1 || (indexPlus < indexSub && indexPlus !== -1)) ? indexPlus : indexSub
619         expressionList.value.push({
620           point: expression.substring(0, endIndex),
2caade 621           operator: expression.substring(endIndex, 1)
83f63a 622         })
L 623         expression = expression.substring(endIndex + 1)
624       } else {
625         expressionList.value.push({
626           point: expression,
627           operator: ''
628         })
629         expression = ''
630       }
631     } while (expression && expression.length > 0)
632   }
633 }
634
635 function setReplaceModelOnly(value) {
cd9f11 636   replaceModelOnly.value = value
L 637 }
83f63a 638
L 639 function beforeUpload(file) {
cd9f11 640   let fileName = file.name
L 641   let first = fileName.lastIndexOf('.')
642   let nameLength = fileName.length
643   let fileSuffix = fileName.substring(first + 1, nameLength)
644   if (fileSuffix !== 'miail') {
645     message.error('只能上传miail类型文件')
646     return
647   }
648 }
83f63a 649
L 650 function uploadModelSuccess(response, file, fileList) {
cd9f11 651   if (response.code === 0) {
L 652     message.success(t('上传成功'))
653     dataForm.value.mmModelArithSettingsList = []
d3ee81 654     if (!replaceModelOnly.value) {
cd9f11 655       dataForm.value.mmModelParamList = []
L 656     }
657     dataForm.value.mmPredictModel.modelpath = ''
658     dataForm.value.mmPredictModel.modelparamstructure = ''
659     if (response.data.loadFieldSetList && response.data.loadFieldSetList[0].propertyList) {
83f63a 660       response.data.loadFieldSetList[0].propertyList.forEach(function (value) {
cd9f11 661         if (value.key !== 'data1') {
L 662           dataForm.value.mmModelArithSettingsList.push({
663             key: value.key,
664             name: value.name,
665             valuetype: value.valueType,
666             value: value.value
667           })
668         }
2caade 669       })
cd9f11 670     }
d3ee81 671     dataForm.value.mmPredictModel.modelname = response.data.originalFilename
cd9f11 672     dataForm.value.mmPredictModel.classname = response.data.className
L 673     dataForm.value.mmPredictModel.methodname = response.data.methodName
674     if (response.data.paramPathList) {
675       dataForm.value.mmPredictModel.modelpath = response.data.paramPathList[0]
676     }
677     if (response.data.paramsArray) {
678       dataForm.value.mmPredictModel.modelparamstructure = response.data.paramsArray.join(',')
679     }
d3ee81 680     if (response.data.paramsCount && !replaceModelOnly.value) {
cd9f11 681       for (let i = 0; i < response.data.paramsCount; i++) {
L 682         dataForm.value.mmModelParamList.push({
683           modelparamportorder: (i + 1),
684           modelparamorder: (i + 1),
685           modelparamtype: '',
686           modelparamid: '',
687           modelparamname: '',
688           datalength: 0
689         })
690       }
691     }
692     if (response.data.settingConfigMap && response.data.settingConfigMap.settingMap) {
693       dataForm.value.mmPredictModel.settingmap = JSON.stringify(response.data.settingConfigMap.settingMap)
694     }
695   } else {
696     message.error('上传失败!' + response.msg)
697     return
698   }
699   fileList = []
700 }
83f63a 701
L 702 function uploadModelError(file, err, fileList) {
cd9f11 703 }
83f63a 704
L 705 function changeModelparam(row) {
cd9f11 706   row.modelparamname = modelparamMap[row.modelparamid]
L 707 }
83f63a 708
L 709 function changeItemtype(value) {
cd9f11 710   dataForm.value.itemtypename = itemTypeMap[value]
L 711 }
83f63a 712
L 713 function changeModelparamtype(value, row) {
cd9f11 714   row.modelparamid = ''
L 715 }
83f63a 716
L 717 function changeOutputPoint(value) {
cd9f11 718   dataForm.value.mmItemOutput.tagname = pointMap[value]
L 719 }
83f63a 720
L 721 function deleteExpressionRow(index, rows) {
cd9f11 722   rows.splice(index, 1)
L 723 }
83f63a 724
L 725 function addExpressionRow(index, rows) {
cd9f11 726   let row = JSON.parse(JSON.stringify(rows[index]))
L 727   rows.splice(index, 0, row)
728 }
83f63a 729
L 730 function deleteRow(index: string, rows) {
cd9f11 731   if (!rows || rows.length === 1) {
L 732     message.error('不能全部删除!')
733     return
734   }
735   rows.splice(index, 1)
736   orderRow(rows)
737 }
83f63a 738
L 739 function addRow(index: string, rows) {
cd9f11 740   let row = JSON.parse(JSON.stringify(rows[index]))
L 741   rows.splice(index, 0, row)
742   orderRow(rows)
743 }
7462da 744
83f63a 745 function orderRow(rows) {
cd9f11 746   let modelparamorder = 0
L 747   let modelparamportorder = 0
748   rows.forEach(function (value) {
749     if (value.modelparamportorder !== modelparamportorder) {
750       modelparamportorder = value.modelparamportorder
751       modelparamorder = 1
752     }
753     value.modelparamorder = modelparamorder
754     modelparamorder++
755   })
756 }
83f63a 757
2caade 758 const setDefaultFields = () => {
83f63a 759   dataForm.value.mmPredictItem.workchecked = 0
L 760   dataForm.value.mmPredictItem.status = 1
761   dataForm.value.mmPredictItem.isfuse = 0
762   dataForm.value.mmPredictItem.predictphase = 0
763   dataForm.value.mmPredictItem.unittransfactor = 1
764   dataForm.value.mmPredictItem.saveindex = '2'
765   dataForm.value.dmModuleItem.status = 1
766   dataForm.value.mmPredictModel.trainsamplength = 60
767   dataForm.value.mmPredictModel.isonlinetrain = 0
768   dataForm.value.mmPredictModel.status = 1
769   dataForm.value.mmItemOutput.outputorder = 1
770   dataForm.value.mmItemOutput.resulttableid = '3cc2b483-3a01-40f7-a419-0c260210d8eb'
771   expressionList.value = [{
772     point: '',
773     operator: ''
774   }]
775   fileList.value = []
776 }
777
7462da 778 /** 重置表单 */
d3ee81 779 const resetForm = () => {
cd9f11 780   dataForm.value = {
L 781     mmModelArithSettingsList: [],
782     mmModelParamList: [],
783     id: '',
e1ff2d 784     itemtypename: 'NormalItem',
cd9f11 785     mmPredictItem: {
L 786       id: '',
787       itemno: '',
788       itemname: '',
789       caltypeid: '',
790       itemtypeid: '',
791       predictlength: '',
d3ee81 792       granularity: 60,
cd9f11 793       status: '',
L 794       isfuse: '',
795       predictphase: '',
d3ee81 796       workchecked: 0,
cd9f11 797       unittransfactor: '',
L 798       saveindex: ''
799     },
800     dmModuleItem: {
801       id: '',
802       moduleid: '',
803       itemid: '',
d3ee81 804       itemorder: 1,
cd9f11 805       status: 1,
L 806       categoryid: ''
807     },
808     mmItemOutput: {
809       id: '',
810       itemid: '',
811       pointid: '',
812       resulttableid: '3cc2b483-3a01-40f7-a419-0c260210d8eb',
813       tagname: '',
814       outputorder: 1
815     },
816     mmPredictModel: {
817       id: '',
818       modelno: '',
819       modelname: '',
820       itemid: '',
821       arithid: '',
822       trainsamplength: '',
823       predictsamplength: '',
824       isonlinetrain: '',
825       modelpath: '',
826       isnormal: '',
827       normalmax: '',
828       normalmin: '',
829       status: 1,
830       classname: '',
831       methodname: '',
832       modelparamstructure: '',
833       resultstrid: '',
834       settingmap: ''
835     },
836     mmPredictMergeItem: {
837       id: '',
838       itemid: '',
839       expression: '',
840       num: ''
841     }
7462da 842   }
L 843   formRef.value?.resetFields()
d3ee81 844 }
cd9f11 845
L 846 onMounted(() => {
847   init()
848 })
849
83f63a 850 function init() {
cd9f11 851 }
7462da 852 </script>