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