dongyukun
7 天以前 4a92d33eb3157e8f31d4429eead1c7dfd3cacc13
提交 | 用户 | 时间
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">
f9b459 301             <el-input size="mini" 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)"
375               type="text"
7b1ce6 376               size="mini">
cd9f11 377               添加
L 378             </el-button>
379             <el-button
22bece 380               @click="deleteRow(scope.$index, scope.row, dataForm.mmModelParamList)"
cd9f11 381               type="text"
7b1ce6 382               size="mini">
cd9f11 383               删除
L 384             </el-button>
385           </template>
386         </el-table-column>
387       </el-table>
388       <el-divider content-position="left" v-if="dataForm.itemtypename === 'MergeItem'">表达式
389       </el-divider>
390       <el-table
2caade 391         v-if="dataForm.itemtypename === 'MergeItem'"
cd9f11 392         :data="expressionList"
L 393         border
394         style="width: 100%; margin-top: 5px;">
395         <el-table-column
396           prop=""
5c475d 397           label="预测项(NormalItem)"
cd9f11 398           align="center">
L 399           <template #default="scope">
400             <el-select
401               v-model="scope.row.point"
5c475d 402               placeholder="请选择"
cd9f11 403               filterable
f5e3a1 404               :no-data-text="'无数据(预测长度:' + dataForm.mmPredictItem.predictlength + ';管网:' + moduleList.find(e => e.id === dataForm.dmModuleItem.moduleid)?.modulename + ')'"
fcd59a 405               @change="changeNormalItemSelect"
5c475d 406               style="width: 100%">
D 407               <el-option-group
f5e3a1 408                 v-for="group in modelparamListMap['NormalItem'].filter(e => e.predictlength == dataForm.mmPredictItem.predictlength && e.moduleid === dataForm.dmModuleItem.moduleid)"
5c475d 409                 :key="group.value"
D 410                 :label="group.label"
411               >
412                 <el-option
413                   v-for="item in group.children"
414                   :key="item.value"
415                   :label="item.label"
416                   :value="item.value"
417                 />
418               </el-option-group>
cd9f11 419             </el-select>
L 420           </template>
421         </el-table-column>
422         <el-table-column
423           prop="point"
424           label="编号"
425           align="center"/>
426         <el-table-column
427           prop=""
428           label="运算符"
429           align="center">
430           <template #default="scope">
7b1ce6 431             <el-select v-model="scope.row.operator" placeholder="请选择" clearable>
cd9f11 432               <el-option
L 433                 v-for="item in operatorList"
434                 :key="item"
435                 :label="item"
436                 :value="item"/>
437             </el-select>
438           </template>
439         </el-table-column>
440         <el-table-column
441           prop=""
442           label="操作"
2caade 443           width="140"
cd9f11 444           align="center">
L 445           <template #default="scope">
446             <el-button
447               @click="addExpressionRow(scope.$index, expressionList)"
448               type="text"
449               size="small">
450               添加
451             </el-button>
452             <el-button
453               @click="deleteExpressionRow(scope.$index, expressionList)"
454               type="text"
455               size="small">
456               删除
457             </el-button>
458           </template>
459         </el-table-column>
460       </el-table>
7462da 461     </el-form>
L 462     <template #footer>
463       <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
464       <el-button @click="dialogVisible = false">取 消</el-button>
465     </template>
466   </Dialog>
467 </template>
468 <script lang="ts" setup>
d3ee81 469 import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'
7b1ce6 470 import * as MmPredictItem from '@/api/model/pre/item'
471 import * as MmItemType from '@/api/model/pre/type'
cd9f11 472 import * as DmModule from '@/api/model/pre/dm'
be4298 473 import * as ProjectApi from '@/api/model/mpk/project'
cd9f11 474 import * as DaPoint from '@/api/data/da/point'
7b1ce6 475 import {useUpload} from '@/api/model/pre/item'
e1ff2d 476 import * as ScheduleModelApi from '@/api/model/sche/model'
d3ee81 477
478 const {uploadUrl, httpRequest} = useUpload()
7462da 479
L 480 defineOptions({name: 'DataMmPredictItemForm'})
481
482 const {t} = useI18n() // 国际化
483 const message = useMessage() // 消息弹窗
484 const dialogVisible = ref(false) // 弹窗的是否展示
485 const dialogTitle = ref('') // 弹窗的标题
486 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
487 const formType = ref('') // 表单的类型:create - 新增;update - 修改
cd9f11 488 const itemTypeList = ref([])
L 489 const itemTypeMap = ref({})
490 const moduleList = ref([])
be4298 491 const mpkProjectList = ref([])
2caade 492 const pointNoList = ref([])
cd9f11 493 const pointList = ref([])
L 494 const pointMap = ref({})
d3ee81 495 const modelparamListMap = ref({})
cd9f11 496 const modelparamMap = ref({})
L 497 const expressionList = ref([])
498 const fileList = ref([])
499 const operatorList = ['+', '-']
d3ee81 500 const replaceModelOnly = ref(false)
cd9f11 501 const queryParams = reactive({
L 502   pageNo: 1,
503   pageSize: 10,
504   pointNo: undefined,
505   pointName: undefined,
506 })
507 const dataForm = ref({
2caade 508   id: undefined,
e1ff2d 509   itemtypename: 'NormalItem',
cd9f11 510   mmPredictItem: {
2caade 511     id: undefined,
L 512     itemno: undefined,
513     itemname: undefined,
514     caltypeid: undefined,
515     itemtypeid: undefined,
516     predictlength: undefined,
d3ee81 517     granularity: 60,
2caade 518     status: undefined,
L 519     isfuse: undefined,
520     predictphase: undefined,
d3ee81 521     workchecked: 0,
2caade 522     unittransfactor: undefined,
L 523     saveindex: undefined
cd9f11 524   },
L 525   dmModuleItem: {
2caade 526     id: undefined,
L 527     moduleid: undefined,
528     itemid: undefined,
d3ee81 529     itemorder: 1,
2caade 530     status: undefined,
L 531     categoryid: undefined
cd9f11 532   },
d8e4be 533   mmItemOutputList: [],
cd9f11 534   mmPredictModel: {
2caade 535     id: undefined,
L 536     modelno: undefined,
537     modelname: undefined,
538     itemid: undefined,
539     arithid: undefined,
540     trainsamplength: undefined,
541     predictsamplength: undefined,
542     isonlinetrain: undefined,
543     modelpath: undefined,
544     isnormal: undefined,
545     normalmax: undefined,
546     normalmin: undefined,
547     status: undefined,
548     classname: undefined,
549     methodname: undefined,
550     modelparamstructure: undefined,
551     resultstrid: undefined,
be4298 552     settingmap: undefined,
D 553     mpkprojectid: undefined
cd9f11 554   },
L 555   mmPredictMergeItem: {
2caade 556     id: undefined,
L 557     itemid: undefined,
558     expression: undefined,
559     num: undefined
cd9f11 560   },
L 561   mmModelArithSettingsList: [],
36885d 562   mmModelParamList: [],
D 563   pointId: undefined
7462da 564 })
L 565 const formRules = reactive({
d3ee81 566   'mmPredictItem.itemname': [{required: true, message: '预测项名不能为空', trigger: 'blur'}],
567   'mmPredictItem.itemtypeid': [{required: true, message: '类型不能为空', trigger: 'blur'}],
e1ff2d 568   'mmPredictItem.granularity': [{
d3ee81 569     required: true,
570     message: '粒度不能为空',
571     trigger: 'blur'
572   }],
e1ff2d 573   'mmPredictItem.workchecked': [{
d3ee81 574     required: true,
575     message: '是否检查不能为空',
576     trigger: 'blur'
577   }],
e1ff2d 578   'mmPredictItem.status': [{required: true, message: '是否启用不能为空', trigger: 'blur'}],
579   'dmModuleItem.moduleid': [{required: true, message: '管网不能为空', trigger: 'blur'}],
580   'dmModuleItem.itemorder': [{required: true, message: '排序不能为空', trigger: 'blur'}],
fcd59a 581   'mmPredictItem.predictlength': [{required: true, message: '预测长度不能为空', trigger: 'blur'}],
22bece 582   'mmPredictModel.mpkprojectid': [{required: true, message: '关联项目不能为空', trigger: 'blur'}],
d3ee81 583
7462da 584 })
L 585 const formRef = ref() // 表单 Ref
586
587 /** 打开弹窗 */
2caade 588 const open = async (type: string, id?: number, itemtypename?: string) => {
e1ff2d 589   formType.value = type
7462da 590   dialogVisible.value = true
L 591   dialogTitle.value = t('action.' + type)
2caade 592   dataForm.value.itemtypename = itemtypename || 'NormalItem'
e1ff2d 593   resetForm()
2caade 594   resetFields(dataForm.value)
83f63a 595   setDefaultFields()
e1ff2d 596
597   // 加载参数列表
5c475d 598   modelparamListMap.value = await ScheduleModelApi.getModelParamList(id)
e1ff2d 599
600   // 获取预测项类型列表
601   itemTypeList.value = await MmItemType.getItemTypeList()
602   itemTypeList.value.forEach(function (value) {
603     itemTypeMap[value.id] = value.itemtypename
604   })
605   if (!dataForm.value.id) {
606     dataForm.value.mmPredictItem.itemtypeid = itemTypeList.value[0].id
607   }
608
609   // 获取管网列表
610   moduleList.value = await DmModule.getModuleList()
611
be4298 612   // 获取mpk项目列表
D 613   mpkProjectList.value = await ProjectApi.list()
7b1ce6 614
e1ff2d 615   // 获取数据点列表
616   pointNoList.value = await DaPoint.getPointList(queryParams)
617   if (pointNoList.value.length > 0) {
d8e4be 618     pointList.value = []
e1ff2d 619     pointNoList.value.forEach(function (value) {
620       pointList.value.push(value)
d8e4be 621       pointMap[value.id] = value.pointName
e1ff2d 622     })
623   }
624
7b1ce6 625   // 修改时,设置数据
626   if (id) {
627     formLoading.value = true
628     try {
629       getInfo(id)
630     } finally {
d8e4be 631       formLoading.value = false
7b1ce6 632     }
633   }
e1ff2d 634   formLoading.value = false
7462da 635 }
L 636 defineExpose({open}) // 提供 open 方法,用于打开弹窗
637
638 /** 提交表单 */
639 const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
640 const submitForm = async () => {
641   // 校验表单
642   if (!formRef) return
643   const valid = await formRef.value.validate()
644   if (!valid) return
d8e4be 645   //校验模型输出
fcd59a 646   if (dataForm.value.itemtypename === 'NormalItem') {
5c475d 647     if (dataForm.value.mmItemOutputList == undefined || dataForm.value.mmItemOutputList.length <= 0) {
D 648       message.error("模型输出不为空")
649       return
650     }
651
652     let flag = false
653     dataForm.value.mmItemOutputList.forEach(e => {
7db73a 654       if (e.resultstr == undefined || e.resultstr === '' || e.resultType == undefined || e.resultType === '' || (e.resultType === 2 && (e.resultIndex == undefined || e.resultIndex === ''))) {
5c475d 655         message.error("模型输出数据异常")
fcd59a 656         flag = true
D 657         return
658       }
659     })
660     if (flag) return
661   }
662   if (dataForm.value.itemtypename === 'MergeItem') {
663     if (expressionList.value == undefined || expressionList.value.length <= 1) {
664       message.error("表达式长度低于2")
665       return
666     }
667
668     let flag = false
669     expressionList.value.forEach((e,index) => {
670       if (e.point == undefined || e.point === '' || e.operator == undefined || (e.operator === '' && index != expressionList.value.length - 1)) {
671         message.error("表达式数据异常")
5c475d 672         flag = true
D 673         return
674       }
675     })
676     if (flag) return
d8e4be 677   }
D 678
679
7462da 680   // 提交请求
L 681   formLoading.value = true
682   try {
cd9f11 683     const data = dataForm.value as unknown as MmPredictItem.MmPredictItemVO
b39d0b 684     if (expressionList.value && expressionList.value.length > 0) {
L 685       let expression = ''
686       for (let i = 0; i < expressionList.value.length; i++) {
687         let value = expressionList.value[i]
688         expression = expression + value.point + (i === (expressionList.value.length - 1) ? '' : value.operator)
689       }
690       dataForm.value.mmPredictMergeItem.expression = expression
691     } else {
692       dataForm.value.mmPredictMergeItem.expression = ''
693     }
694     if (dataForm.value.mmModelArithSettingsList) {
695       for (let item of dataForm.value.mmModelArithSettingsList) {
9b24e4 696         if (item.key === 'predictLength') {
b39d0b 697           dataForm.value.mmPredictItem.predictlength = item.value
L 698         }
699       }
700     }
7462da 701     if (formType.value === 'create') {
L 702       await MmPredictItem.createMmPredictItem(data)
703       message.success(t('common.createSuccess'))
704     } else {
705       await MmPredictItem.updateMmPredictItem(data)
706       message.success(t('common.updateSuccess'))
707     }
708     dialogVisible.value = false
709     // 发送操作成功的事件
710     emit('success')
711   } finally {
712     formLoading.value = false
713   }
714 }
83f63a 715
2caade 716 const resetFields = (obj) => {
L 717   for (let key in obj) {
718     if (key === 'itemtypename') {
719       continue
720     }
721     if (obj[key] instanceof Array) {
722       obj[key] = []
723     } else if (obj[key] instanceof Object) {
724       resetFields(obj[key])
725     } else {
726       obj[key] = ''
727     }
728   }
729 }
730
731 const getInfo = async (id) => {
732   dataForm.value = await MmPredictItem.getMmPredictItem(id)
7b1ce6 733   dataForm.value.itemtypename = itemTypeMap[dataForm.value.mmPredictItem.itemtypeid]
83f63a 734   expressionList.value = []
2caade 735   if (dataForm.value.mmPredictMergeItem && dataForm.value.mmPredictMergeItem.expression) {
L 736     let expression = dataForm.value.mmPredictMergeItem.expression
83f63a 737     do {
L 738       let indexPlus = expression.indexOf('+')
739       let indexSub = expression.indexOf('-')
740       if (indexPlus !== -1 || indexSub !== -1) {
741         let endIndex = (indexSub == -1 || (indexPlus < indexSub && indexPlus !== -1)) ? indexPlus : indexSub
742         expressionList.value.push({
743           point: expression.substring(0, endIndex),
5c475d 744           operator: expression.substring(endIndex, endIndex + 1)
83f63a 745         })
L 746         expression = expression.substring(endIndex + 1)
747       } else {
748         expressionList.value.push({
749           point: expression,
750           operator: ''
751         })
752         expression = ''
753       }
754     } while (expression && expression.length > 0)
755   }
756 }
757
758 function setReplaceModelOnly(value) {
cd9f11 759   replaceModelOnly.value = value
L 760 }
83f63a 761
L 762 function beforeUpload(file) {
cd9f11 763   let fileName = file.name
L 764   let first = fileName.lastIndexOf('.')
765   let nameLength = fileName.length
766   let fileSuffix = fileName.substring(first + 1, nameLength)
767   if (fileSuffix !== 'miail') {
768     message.error('只能上传miail类型文件')
769     return
770   }
771 }
83f63a 772
L 773 function uploadModelSuccess(response, file, fileList) {
cd9f11 774   if (response.code === 0) {
L 775     message.success(t('上传成功'))
776     dataForm.value.mmModelArithSettingsList = []
d3ee81 777     if (!replaceModelOnly.value) {
cd9f11 778       dataForm.value.mmModelParamList = []
L 779     }
780     dataForm.value.mmPredictModel.modelpath = ''
781     dataForm.value.mmPredictModel.modelparamstructure = ''
782     if (response.data.loadFieldSetList && response.data.loadFieldSetList[0].propertyList) {
83f63a 783       response.data.loadFieldSetList[0].propertyList.forEach(function (value) {
5c475d 784         //匹配  data数字
D 785         if (!/^data\d+$/.test(value.key)) {
cd9f11 786           dataForm.value.mmModelArithSettingsList.push({
L 787             key: value.key,
788             name: value.name,
789             valuetype: value.valueType,
790             value: value.value
791           })
792         }
2caade 793       })
cd9f11 794     }
d3ee81 795     dataForm.value.mmPredictModel.modelname = response.data.originalFilename
cd9f11 796     dataForm.value.mmPredictModel.classname = response.data.className
L 797     dataForm.value.mmPredictModel.methodname = response.data.methodName
798     if (response.data.paramPathList) {
799       dataForm.value.mmPredictModel.modelpath = response.data.paramPathList[0]
800     }
801     if (response.data.paramsArray) {
802       dataForm.value.mmPredictModel.modelparamstructure = response.data.paramsArray.join(',')
803     }
d3ee81 804     if (response.data.paramsCount && !replaceModelOnly.value) {
cd9f11 805       for (let i = 0; i < response.data.paramsCount; i++) {
L 806         dataForm.value.mmModelParamList.push({
807           modelparamportorder: (i + 1),
808           modelparamorder: (i + 1),
809           modelparamtype: '',
810           modelparamid: '',
811           modelparamname: '',
812           datalength: 0
813         })
814       }
815     }
816     if (response.data.settingConfigMap && response.data.settingConfigMap.settingMap) {
817       dataForm.value.mmPredictModel.settingmap = JSON.stringify(response.data.settingConfigMap.settingMap)
818     }
819   } else {
820     message.error('上传失败!' + response.msg)
821     return
822   }
823   fileList = []
824 }
83f63a 825
L 826 function uploadModelError(file, err, fileList) {
cd9f11 827 }
83f63a 828
L 829 function changeModelparam(row) {
cd9f11 830   row.modelparamname = modelparamMap[row.modelparamid]
L 831 }
83f63a 832
L 833 function changeItemtype(value) {
cd9f11 834   dataForm.value.itemtypename = itemTypeMap[value]
L 835 }
83f63a 836
61c379 837 function changeModelparamtype(row) {
cd9f11 838   row.modelparamid = ''
L 839 }
83f63a 840
61c379 841 function changeOutputPoint(value, row) {
d8e4be 842   row.tagname = pointMap[value]
cd9f11 843 }
83f63a 844
L 845 function deleteExpressionRow(index, rows) {
cd9f11 846   rows.splice(index, 1)
L 847 }
83f63a 848
L 849 function addExpressionRow(index, rows) {
cd9f11 850   let row = JSON.parse(JSON.stringify(rows[index]))
L 851   rows.splice(index, 0, row)
852 }
83f63a 853
22bece 854 function deleteRow(index, row, rows) {
D 855   if (!rows || rows.length === 1 || rows.filter(e => e.modelparamportorder === row.modelparamportorder).length === 1) {
856     message.error('不可删除!')
cd9f11 857     return
L 858   }
859   rows.splice(index, 1)
860   orderRow(rows)
861 }
83f63a 862
L 863 function addRow(index: string, rows) {
cd9f11 864   let row = JSON.parse(JSON.stringify(rows[index]))
L 865   rows.splice(index, 0, row)
866   orderRow(rows)
d8e4be 867 }
61c379 868
fcd59a 869 function addItemOutput() {
D 870   if (!dataForm.value.mmItemOutputList) {
871     dataForm.value.mmItemOutputList = []
872   }
873   dataForm.value.mmItemOutputList.push({})
874   orderItemOutput(dataForm.value.mmItemOutputList)
d8e4be 875 }
61c379 876
d8e4be 877 function deleteItemOutput(index: string, rows) {
D 878   if (!rows || rows.length === 1) {
879     message.error('不能全部删除!')
880     return
881   }
882   rows.splice(index, 1)
883   orderItemOutput(rows)
884 }
61c379 885
d8e4be 886 function orderItemOutput(list) {
D 887   list.sort((a, b) => a.outputorder - b.outputorder);
888   let outputorder = 1
889   list.forEach(function (value) {
890     value.outputorder = outputorder
891     outputorder++
892   })
893 }
894
895 function resultTypeChange(value, row) {
896   if (value === 1) {
897     row.resultIndex = undefined
61c379 898   } else if (value === 2) {
d8e4be 899     row.resultIndex = 0
D 900   }
cd9f11 901 }
7462da 902
83f63a 903 function orderRow(rows) {
cd9f11 904   let modelparamorder = 0
L 905   let modelparamportorder = 0
906   rows.forEach(function (value) {
907     if (value.modelparamportorder !== modelparamportorder) {
908       modelparamportorder = value.modelparamportorder
909       modelparamorder = 1
910     }
911     value.modelparamorder = modelparamorder
912     modelparamorder++
913   })
914 }
83f63a 915
2caade 916 const setDefaultFields = () => {
83f63a 917   dataForm.value.mmPredictItem.workchecked = 0
L 918   dataForm.value.mmPredictItem.status = 1
919   dataForm.value.mmPredictItem.isfuse = 0
920   dataForm.value.mmPredictItem.predictphase = 0
921   dataForm.value.mmPredictItem.unittransfactor = 1
922   dataForm.value.mmPredictItem.saveindex = '2'
923   dataForm.value.dmModuleItem.status = 1
924   dataForm.value.mmPredictModel.trainsamplength = 60
925   dataForm.value.mmPredictModel.isonlinetrain = 0
926   dataForm.value.mmPredictModel.status = 1
d8e4be 927   dataForm.value.mmItemOutputList = []
83f63a 928   expressionList.value = [{
L 929     point: '',
930     operator: ''
931   }]
932   fileList.value = []
933 }
934
f5e3a1 935 const clearExpressionList = (value) => {
fcd59a 936   expressionList.value = [{
D 937     point: '',
938     operator: ''
939   }]
940 }
941
7462da 942 /** 重置表单 */
d3ee81 943 const resetForm = () => {
cd9f11 944   dataForm.value = {
L 945     mmModelArithSettingsList: [],
946     mmModelParamList: [],
947     id: '',
e1ff2d 948     itemtypename: 'NormalItem',
cd9f11 949     mmPredictItem: {
L 950       id: '',
951       itemno: '',
952       itemname: '',
953       caltypeid: '',
954       itemtypeid: '',
955       predictlength: '',
d3ee81 956       granularity: 60,
cd9f11 957       status: '',
L 958       isfuse: '',
959       predictphase: '',
d3ee81 960       workchecked: 0,
cd9f11 961       unittransfactor: '',
L 962       saveindex: ''
963     },
964     dmModuleItem: {
965       id: '',
966       moduleid: '',
967       itemid: '',
d3ee81 968       itemorder: 1,
cd9f11 969       status: 1,
L 970       categoryid: ''
971     },
d8e4be 972     mmItemOutputList: [],
cd9f11 973     mmPredictModel: {
L 974       id: '',
975       modelno: '',
976       modelname: '',
977       itemid: '',
978       arithid: '',
979       trainsamplength: '',
980       predictsamplength: '',
981       isonlinetrain: '',
982       modelpath: '',
983       isnormal: '',
984       normalmax: '',
985       normalmin: '',
986       status: 1,
987       classname: '',
988       methodname: '',
989       modelparamstructure: '',
990       resultstrid: '',
991       settingmap: ''
992     },
993     mmPredictMergeItem: {
994       id: '',
995       itemid: '',
996       expression: '',
997       num: ''
998     }
7462da 999   }
L 1000   formRef.value?.resetFields()
d3ee81 1001 }
cd9f11 1002
L 1003 onMounted(() => {
1004   init()
1005 })
1006
83f63a 1007 function init() {
cd9f11 1008 }
7462da 1009 </script>