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