提交 | 用户 | 时间
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
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
22bece 366               @click="deleteRow(scope.$index, scope.row, dataForm.mmModelParamList)"
cd9f11 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'}],
22bece 567   'mmPredictModel.mpkprojectid': [{required: true, message: '关联项目不能为空', trigger: 'blur'}],
d3ee81 568
7462da 569 })
L 570 const formRef = ref() // 表单 Ref
571
572 /** 打开弹窗 */
2caade 573 const open = async (type: string, id?: number, itemtypename?: string) => {
e1ff2d 574   formType.value = type
7462da 575   dialogVisible.value = true
L 576   dialogTitle.value = t('action.' + type)
2caade 577   dataForm.value.itemtypename = itemtypename || 'NormalItem'
e1ff2d 578   resetForm()
2caade 579   resetFields(dataForm.value)
83f63a 580   setDefaultFields()
e1ff2d 581
582   // 加载参数列表
5c475d 583   modelparamListMap.value = await ScheduleModelApi.getModelParamList(id)
e1ff2d 584
585   // 获取预测项类型列表
586   itemTypeList.value = await MmItemType.getItemTypeList()
587   itemTypeList.value.forEach(function (value) {
588     itemTypeMap[value.id] = value.itemtypename
589   })
590   if (!dataForm.value.id) {
591     dataForm.value.mmPredictItem.itemtypeid = itemTypeList.value[0].id
592   }
593
594   // 获取管网列表
595   moduleList.value = await DmModule.getModuleList()
596
be4298 597   // 获取mpk项目列表
D 598   mpkProjectList.value = await ProjectApi.list()
7b1ce6 599
e1ff2d 600   // 获取数据点列表
601   pointNoList.value = await DaPoint.getPointList(queryParams)
602   if (pointNoList.value.length > 0) {
d8e4be 603     pointList.value = []
e1ff2d 604     pointNoList.value.forEach(function (value) {
605       pointList.value.push(value)
d8e4be 606       pointMap[value.id] = value.pointName
e1ff2d 607     })
608   }
609
7b1ce6 610   // 修改时,设置数据
611   if (id) {
612     formLoading.value = true
613     try {
614       getInfo(id)
615     } finally {
d8e4be 616       formLoading.value = false
7b1ce6 617     }
618   }
e1ff2d 619   formLoading.value = false
7462da 620 }
L 621 defineExpose({open}) // 提供 open 方法,用于打开弹窗
622
623 /** 提交表单 */
624 const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
625 const submitForm = async () => {
626   // 校验表单
627   if (!formRef) return
628   const valid = await formRef.value.validate()
629   if (!valid) return
d8e4be 630   //校验模型输出
fcd59a 631   if (dataForm.value.itemtypename === 'NormalItem') {
5c475d 632     if (dataForm.value.mmItemOutputList == undefined || dataForm.value.mmItemOutputList.length <= 0) {
D 633       message.error("模型输出不为空")
634       return
635     }
636
637     let flag = false
638     dataForm.value.mmItemOutputList.forEach(e => {
7db73a 639       if (e.resultstr == undefined || e.resultstr === '' || e.resultType == undefined || e.resultType === '' || (e.resultType === 2 && (e.resultIndex == undefined || e.resultIndex === ''))) {
5c475d 640         message.error("模型输出数据异常")
fcd59a 641         flag = true
D 642         return
643       }
644     })
645     if (flag) return
646   }
647   if (dataForm.value.itemtypename === 'MergeItem') {
648     if (expressionList.value == undefined || expressionList.value.length <= 1) {
649       message.error("表达式长度低于2")
650       return
651     }
652
653     let flag = false
654     expressionList.value.forEach((e,index) => {
655       if (e.point == undefined || e.point === '' || e.operator == undefined || (e.operator === '' && index != expressionList.value.length - 1)) {
656         message.error("表达式数据异常")
5c475d 657         flag = true
D 658         return
659       }
660     })
661     if (flag) return
d8e4be 662   }
D 663
664
7462da 665   // 提交请求
L 666   formLoading.value = true
667   try {
cd9f11 668     const data = dataForm.value as unknown as MmPredictItem.MmPredictItemVO
b39d0b 669     if (expressionList.value && expressionList.value.length > 0) {
L 670       let expression = ''
671       for (let i = 0; i < expressionList.value.length; i++) {
672         let value = expressionList.value[i]
673         expression = expression + value.point + (i === (expressionList.value.length - 1) ? '' : value.operator)
674       }
675       dataForm.value.mmPredictMergeItem.expression = expression
676     } else {
677       dataForm.value.mmPredictMergeItem.expression = ''
678     }
679     if (dataForm.value.mmModelArithSettingsList) {
680       for (let item of dataForm.value.mmModelArithSettingsList) {
9b24e4 681         if (item.key === 'predictLength') {
b39d0b 682           dataForm.value.mmPredictItem.predictlength = item.value
L 683         }
684       }
685     }
7462da 686     if (formType.value === 'create') {
L 687       await MmPredictItem.createMmPredictItem(data)
688       message.success(t('common.createSuccess'))
689     } else {
690       await MmPredictItem.updateMmPredictItem(data)
691       message.success(t('common.updateSuccess'))
692     }
693     dialogVisible.value = false
694     // 发送操作成功的事件
695     emit('success')
696   } finally {
697     formLoading.value = false
698   }
699 }
83f63a 700
2caade 701 const resetFields = (obj) => {
L 702   for (let key in obj) {
703     if (key === 'itemtypename') {
704       continue
705     }
706     if (obj[key] instanceof Array) {
707       obj[key] = []
708     } else if (obj[key] instanceof Object) {
709       resetFields(obj[key])
710     } else {
711       obj[key] = ''
712     }
713   }
714 }
715
716 const getInfo = async (id) => {
717   dataForm.value = await MmPredictItem.getMmPredictItem(id)
7b1ce6 718   dataForm.value.itemtypename = itemTypeMap[dataForm.value.mmPredictItem.itemtypeid]
83f63a 719   expressionList.value = []
2caade 720   if (dataForm.value.mmPredictMergeItem && dataForm.value.mmPredictMergeItem.expression) {
L 721     let expression = dataForm.value.mmPredictMergeItem.expression
83f63a 722     do {
L 723       let indexPlus = expression.indexOf('+')
724       let indexSub = expression.indexOf('-')
725       if (indexPlus !== -1 || indexSub !== -1) {
726         let endIndex = (indexSub == -1 || (indexPlus < indexSub && indexPlus !== -1)) ? indexPlus : indexSub
727         expressionList.value.push({
728           point: expression.substring(0, endIndex),
5c475d 729           operator: expression.substring(endIndex, endIndex + 1)
83f63a 730         })
L 731         expression = expression.substring(endIndex + 1)
732       } else {
733         expressionList.value.push({
734           point: expression,
735           operator: ''
736         })
737         expression = ''
738       }
739     } while (expression && expression.length > 0)
740   }
741 }
742
743 function setReplaceModelOnly(value) {
cd9f11 744   replaceModelOnly.value = value
L 745 }
83f63a 746
L 747 function beforeUpload(file) {
cd9f11 748   let fileName = file.name
L 749   let first = fileName.lastIndexOf('.')
750   let nameLength = fileName.length
751   let fileSuffix = fileName.substring(first + 1, nameLength)
752   if (fileSuffix !== 'miail') {
753     message.error('只能上传miail类型文件')
754     return
755   }
756 }
83f63a 757
L 758 function uploadModelSuccess(response, file, fileList) {
cd9f11 759   if (response.code === 0) {
L 760     message.success(t('上传成功'))
761     dataForm.value.mmModelArithSettingsList = []
d3ee81 762     if (!replaceModelOnly.value) {
cd9f11 763       dataForm.value.mmModelParamList = []
L 764     }
765     dataForm.value.mmPredictModel.modelpath = ''
766     dataForm.value.mmPredictModel.modelparamstructure = ''
767     if (response.data.loadFieldSetList && response.data.loadFieldSetList[0].propertyList) {
83f63a 768       response.data.loadFieldSetList[0].propertyList.forEach(function (value) {
5c475d 769         //匹配  data数字
D 770         if (!/^data\d+$/.test(value.key)) {
cd9f11 771           dataForm.value.mmModelArithSettingsList.push({
L 772             key: value.key,
773             name: value.name,
774             valuetype: value.valueType,
775             value: value.value
776           })
777         }
2caade 778       })
cd9f11 779     }
d3ee81 780     dataForm.value.mmPredictModel.modelname = response.data.originalFilename
cd9f11 781     dataForm.value.mmPredictModel.classname = response.data.className
L 782     dataForm.value.mmPredictModel.methodname = response.data.methodName
783     if (response.data.paramPathList) {
784       dataForm.value.mmPredictModel.modelpath = response.data.paramPathList[0]
785     }
786     if (response.data.paramsArray) {
787       dataForm.value.mmPredictModel.modelparamstructure = response.data.paramsArray.join(',')
788     }
d3ee81 789     if (response.data.paramsCount && !replaceModelOnly.value) {
cd9f11 790       for (let i = 0; i < response.data.paramsCount; i++) {
L 791         dataForm.value.mmModelParamList.push({
792           modelparamportorder: (i + 1),
793           modelparamorder: (i + 1),
794           modelparamtype: '',
795           modelparamid: '',
796           modelparamname: '',
797           datalength: 0
798         })
799       }
800     }
801     if (response.data.settingConfigMap && response.data.settingConfigMap.settingMap) {
802       dataForm.value.mmPredictModel.settingmap = JSON.stringify(response.data.settingConfigMap.settingMap)
803     }
804   } else {
805     message.error('上传失败!' + response.msg)
806     return
807   }
808   fileList = []
809 }
83f63a 810
L 811 function uploadModelError(file, err, fileList) {
cd9f11 812 }
83f63a 813
L 814 function changeModelparam(row) {
cd9f11 815   row.modelparamname = modelparamMap[row.modelparamid]
L 816 }
83f63a 817
L 818 function changeItemtype(value) {
cd9f11 819   dataForm.value.itemtypename = itemTypeMap[value]
L 820 }
83f63a 821
61c379 822 function changeModelparamtype(row) {
cd9f11 823   row.modelparamid = ''
L 824 }
83f63a 825
61c379 826 function changeOutputPoint(value, row) {
d8e4be 827   row.tagname = pointMap[value]
cd9f11 828 }
83f63a 829
L 830 function deleteExpressionRow(index, rows) {
cd9f11 831   rows.splice(index, 1)
L 832 }
83f63a 833
L 834 function addExpressionRow(index, rows) {
cd9f11 835   let row = JSON.parse(JSON.stringify(rows[index]))
L 836   rows.splice(index, 0, row)
837 }
83f63a 838
22bece 839 function deleteRow(index, row, rows) {
D 840   if (!rows || rows.length === 1 || rows.filter(e => e.modelparamportorder === row.modelparamportorder).length === 1) {
841     message.error('不可删除!')
cd9f11 842     return
L 843   }
844   rows.splice(index, 1)
845   orderRow(rows)
846 }
83f63a 847
L 848 function addRow(index: string, rows) {
cd9f11 849   let row = JSON.parse(JSON.stringify(rows[index]))
L 850   rows.splice(index, 0, row)
851   orderRow(rows)
d8e4be 852 }
61c379 853
fcd59a 854 function addItemOutput() {
D 855   if (!dataForm.value.mmItemOutputList) {
856     dataForm.value.mmItemOutputList = []
857   }
858   dataForm.value.mmItemOutputList.push({})
859   orderItemOutput(dataForm.value.mmItemOutputList)
d8e4be 860 }
61c379 861
d8e4be 862 function deleteItemOutput(index: string, rows) {
D 863   if (!rows || rows.length === 1) {
864     message.error('不能全部删除!')
865     return
866   }
867   rows.splice(index, 1)
868   orderItemOutput(rows)
869 }
61c379 870
d8e4be 871 function orderItemOutput(list) {
D 872   list.sort((a, b) => a.outputorder - b.outputorder);
873   let outputorder = 1
874   list.forEach(function (value) {
875     value.outputorder = outputorder
876     outputorder++
877   })
878 }
879
880 function resultTypeChange(value, row) {
881   if (value === 1) {
882     row.resultIndex = undefined
61c379 883   } else if (value === 2) {
d8e4be 884     row.resultIndex = 0
D 885   }
cd9f11 886 }
7462da 887
83f63a 888 function orderRow(rows) {
cd9f11 889   let modelparamorder = 0
L 890   let modelparamportorder = 0
891   rows.forEach(function (value) {
892     if (value.modelparamportorder !== modelparamportorder) {
893       modelparamportorder = value.modelparamportorder
894       modelparamorder = 1
895     }
896     value.modelparamorder = modelparamorder
897     modelparamorder++
898   })
899 }
83f63a 900
2caade 901 const setDefaultFields = () => {
83f63a 902   dataForm.value.mmPredictItem.workchecked = 0
L 903   dataForm.value.mmPredictItem.status = 1
904   dataForm.value.mmPredictItem.isfuse = 0
905   dataForm.value.mmPredictItem.predictphase = 0
906   dataForm.value.mmPredictItem.unittransfactor = 1
907   dataForm.value.mmPredictItem.saveindex = '2'
908   dataForm.value.dmModuleItem.status = 1
909   dataForm.value.mmPredictModel.trainsamplength = 60
910   dataForm.value.mmPredictModel.isonlinetrain = 0
911   dataForm.value.mmPredictModel.status = 1
d8e4be 912   dataForm.value.mmItemOutputList = []
83f63a 913   expressionList.value = [{
L 914     point: '',
915     operator: ''
916   }]
917   fileList.value = []
918 }
919
fcd59a 920 const changePredictLength = (value) => {
D 921   expressionList.value = [{
922     point: '',
923     operator: ''
924   }]
925 }
926
7462da 927 /** 重置表单 */
d3ee81 928 const resetForm = () => {
cd9f11 929   dataForm.value = {
L 930     mmModelArithSettingsList: [],
931     mmModelParamList: [],
932     id: '',
e1ff2d 933     itemtypename: 'NormalItem',
cd9f11 934     mmPredictItem: {
L 935       id: '',
936       itemno: '',
937       itemname: '',
938       caltypeid: '',
939       itemtypeid: '',
940       predictlength: '',
d3ee81 941       granularity: 60,
cd9f11 942       status: '',
L 943       isfuse: '',
944       predictphase: '',
d3ee81 945       workchecked: 0,
cd9f11 946       unittransfactor: '',
L 947       saveindex: ''
948     },
949     dmModuleItem: {
950       id: '',
951       moduleid: '',
952       itemid: '',
d3ee81 953       itemorder: 1,
cd9f11 954       status: 1,
L 955       categoryid: ''
956     },
d8e4be 957     mmItemOutputList: [],
cd9f11 958     mmPredictModel: {
L 959       id: '',
960       modelno: '',
961       modelname: '',
962       itemid: '',
963       arithid: '',
964       trainsamplength: '',
965       predictsamplength: '',
966       isonlinetrain: '',
967       modelpath: '',
968       isnormal: '',
969       normalmax: '',
970       normalmin: '',
971       status: 1,
972       classname: '',
973       methodname: '',
974       modelparamstructure: '',
975       resultstrid: '',
976       settingmap: ''
977     },
978     mmPredictMergeItem: {
979       id: '',
980       itemid: '',
981       expression: '',
982       num: ''
983     }
7462da 984   }
L 985   formRef.value?.resetFields()
d3ee81 986 }
cd9f11 987
L 988 onMounted(() => {
989   init()
990 })
991
83f63a 992 function init() {
cd9f11 993 }
7462da 994 </script>