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