dengzedong
5 天以前 3357b5f0f0919f7a52cd32a6d6de0acb14e0daaf
提交 | 用户 | 时间
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>
de0f62 139             <el-button type="primary" plain @click="setReplaceModelOnly(true)">
d3ee81 140               <Icon icon="ep:upload"/>
141               更新模型
142             </el-button>
143           </el-upload>
7462da 144         </el-col>
L 145       </el-row>
be4298 146       <el-row v-if="dataForm.itemtypename === 'NormalItem'">
d8e4be 147         <el-col :span="12">
22bece 148           <el-form-item label="关联项目" prop="mmPredictModel.mpkprojectid">
be4298 149             <el-select v-model="dataForm.mmPredictModel.mpkprojectid" placeholder="请选择">
D 150               <el-option
151                 v-for="item in mpkProjectList"
152                 :key="item.id"
153                 :label="item.projectName"
154                 :value="item.id"/>
155             </el-select>
156           </el-form-item>
157         </el-col>
d8e4be 158         <el-col :span="12">
e1ff2d 159           <el-form-item label="编号">
d3ee81 160             <el-input
e1ff2d 161               v-model="dataForm.mmPredictModel.modelno" placeholder="编号" maxlength="30" readonly
d3ee81 162               disabled/>
163           </el-form-item>
164         </el-col>
cd9f11 165       </el-row>
d3ee81 166       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
cd9f11 167         <el-col :span="24">
2caade 168           <el-form-item label="路径">
L 169             <el-input
170               v-model="dataForm.mmPredictModel.modelpath" placeholder="路径" maxlength="32"
171               disabled/>
cd9f11 172           </el-form-item>
L 173         </el-col>
174       </el-row>
d3ee81 175       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
cd9f11 176         <el-col :span="24">
2caade 177           <el-form-item label="类名">
L 178             <el-input
179               v-model="dataForm.mmPredictModel.classname" placeholder="类名" maxlength="32"
180               disabled/>
cd9f11 181           </el-form-item>
L 182         </el-col>
183       </el-row>
d3ee81 184       <el-row :gutter="8" v-if="dataForm.itemtypename === 'NormalItem'">
cd9f11 185         <el-col :span="12">
2caade 186           <el-form-item label="方法名">
L 187             <el-input
188               v-model="dataForm.mmPredictModel.methodname" placeholder="方法名"
189               maxlength="32" disabled/>
cd9f11 190           </el-form-item>
L 191         </el-col>
192         <el-col :span="12">
2caade 193           <el-form-item label="参数">
L 194             <el-input
195               v-model="dataForm.mmPredictModel.modelparamstructure" placeholder="参数"
196               maxlength="32" disabled/>
cd9f11 197           </el-form-item>
L 198         </el-col>
199       </el-row>
d8e4be 200       <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型输出
D 201       </el-divider>
202       <el-button
5c475d 203         v-if="dataForm.itemtypename === 'NormalItem'"
fcd59a 204         @click="addItemOutput()"
d8e4be 205         type="primary"
D 206         size="small">
207         添加
208       </el-button>
209       <el-table
210         v-if="dataForm.itemtypename === 'NormalItem'"
211         :data="dataForm.mmItemOutputList"
212         border
213         style="width: 100%; margin-top: 5px;">
61c379 214         <el-table-column prop="outputorder" label="排序" align="center" width="80px"/>
32396c 215         <el-table-column label="结果KEY" align="center" width="150px">
d8e4be 216           <template #default="scope">
D 217             <el-input v-model="scope.row.resultstr" placeholder="请输入"/>
218           </template>
219         </el-table-column>
32396c 220         <el-table-column label="结果类型" align="center" width="150px">
d8e4be 221           <template #default="scope">
D 222             <el-select
223               v-model="scope.row.resultType"
224               @change="(value) => resultTypeChange(value,scope.row)"
225               filterable
226               placeholder="请选择">
227               <el-option
228                 v-for="dict in getIntDictOptions(DICT_TYPE.MODEL_RESULT_TYPE)"
229                 :key="dict.value"
230                 :label="dict.label"
231                 :value="dict.value"/>
232             </el-select>
233           </template>
234         </el-table-column>
32396c 235         <el-table-column label="索引" align="center" width="100px">
d8e4be 236           <template #default="scope">
61c379 237             <el-input-number style="width:100%;hight:100%" :disabled="scope.row.resultType !== 2"
238                              v-model="scope.row.resultIndex" :min="0" step-strictly
239                              controls-position="right"/>
32396c 240           </template>
241         </el-table-column>
242         <el-table-column label="结果名称" align="center" width="150px">
243           <template #default="scope">
244             <el-input v-model="scope.row.resultName" placeholder="请输入"/>
d8e4be 245           </template>
D 246         </el-table-column>
247         <el-table-column label="数据点" align="center">
248           <template #default="scope">
249             <el-select
250               v-model="scope.row.pointid"
251               filterable
d7baa4 252               clearable
d8e4be 253               @change="(value) => changeOutputPoint(value,scope.row)"
D 254               placeholder="请选择">
255               <el-option
256                 v-for="item in pointList"
257                 :key="item.id"
258                 :label="item.pointName"
259                 :value="item.id"/>
260             </el-select>
261           </template>
262         </el-table-column>
263         <el-table-column prop="" label="操作" width="80" align="center">
264           <template #default="scope">
265             <el-button
266               @click="deleteItemOutput(scope.$index, dataForm.mmItemOutputList)"
267               type="text"
268               size="small">
269               删除
270             </el-button>
271           </template>
272         </el-table-column>
273       </el-table>
274       <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型设置参数
275       </el-divider>
cd9f11 276       <el-table
L 277         v-if="dataForm.itemtypename === 'NormalItem'"
278         :data="dataForm.mmModelArithSettingsList"
279         border
280         style="width: 100%; margin-top: 5px;">
7b1ce6 281         <el-table-column prop="key" label="键" align="center" min-width="150"/>
282         <el-table-column prop="name" label="名称" align="center" min-width="150"/>
283         <el-table-column prop="valuetype" label="类型" align="center" min-width="150"/>
32396c 284         <el-table-column prop="" label="值" align="center" min-width="200">
cd9f11 285           <template #default="scope">
d3ee81 286             <el-input size="mini" v-model="scope.row.value" maxlength="256"
5c475d 287                       :disabled="scope.row.key === 'pyFile'"
d3ee81 288                       style="width:100%;height:100%"/>
cd9f11 289           </template>
L 290         </el-table-column>
291       </el-table>
d8e4be 292       <el-divider content-position="left" v-if="dataForm.itemtypename === 'NormalItem'">模型输入参数
cd9f11 293       </el-divider>
L 294       <el-table
2caade 295         v-if="dataForm.itemtypename === 'NormalItem'"
cd9f11 296         :data="dataForm.mmModelParamList"
L 297         border
298         style="width: 100%; margin-top: 5px;">
299         <el-table-column prop="modelparamportorder" label="端口" width="60" align="center"/>
300         <el-table-column prop="modelparamorder" label="序号" width="60" align="center"/>
301         <el-table-column prop="" label="类型" width="200" align="center">
302           <template #default="scope">
61c379 303             <el-select v-model="scope.row.modelparamtype"
304                        @change="changeModelparamtype(scope.row)"
305                        placeholder="请选择">
cd9f11 306               <el-option
d3ee81 307                 v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_PARAM_TYPE)"
308                 :key="dict.value"
309                 :label="dict.label"
310                 :value="dict.value"
311               />
cd9f11 312             </el-select>
L 313           </template>
314         </el-table-column>
315         <el-table-column prop="" label="参数名称" align="center">
316           <template #default="scope">
5c475d 317             <el-select v-if="scope.row.modelparamtype === 'NormalItem'"
D 318               v-model="scope.row.modelparamid"
319               placeholder="请选择"
320               filterable
321               @change="changeModelparam(scope.row)"
322               style="width: 100%">
323               <el-option-group
324                 v-for="group in modelparamListMap['NormalItem']"
325                 :key="group.value"
326                 :label="group.label"
327               >
328                 <el-option
329                   v-for="item in group.children"
330                   :key="item.value"
331                   :label="item.label"
332                   :value="item.value"
333                 />
334               </el-option-group>
335             </el-select>
336             <el-select v-else
cd9f11 337               v-model="scope.row.modelparamid"
L 338               filterable
339               @change="changeModelparam(scope.row)"
340               placeholder="请选择">
341               <el-option
342                 v-for="(item, index) in modelparamListMap[scope.row.modelparamtype]"
343                 :key="index"
344                 :label="item.name"
345                 :value="item.id"/>
346             </el-select>
347           </template>
348         </el-table-column>
349         <el-table-column prop="" label="参数长度" width="120" align="center">
350           <template #default="scope">
e1ff2d 351             <el-input-number v-model="scope.row.datalength" :min="0" clearable
352                              controls-position="right"
353                              style="width:100%;hight:100%"/>
cd9f11 354           </template>
L 355         </el-table-column>
7b1ce6 356         <el-table-column prop="" label="操作" width="120" align="center">
cd9f11 357           <template #default="scope">
L 358             <el-button
359               @click="addRow(scope.$index, dataForm.mmModelParamList)"
360               type="text"
7b1ce6 361               size="mini">
cd9f11 362               添加
L 363             </el-button>
364             <el-button
22bece 365               @click="deleteRow(scope.$index, scope.row, dataForm.mmModelParamList)"
cd9f11 366               type="text"
7b1ce6 367               size="mini">
cd9f11 368               删除
L 369             </el-button>
370           </template>
371         </el-table-column>
372       </el-table>
373       <el-divider content-position="left" v-if="dataForm.itemtypename === 'MergeItem'">表达式
374       </el-divider>
375       <el-table
2caade 376         v-if="dataForm.itemtypename === 'MergeItem'"
cd9f11 377         :data="expressionList"
L 378         border
379         style="width: 100%; margin-top: 5px;">
380         <el-table-column
381           prop=""
5c475d 382           label="预测项(NormalItem)"
cd9f11 383           align="center">
L 384           <template #default="scope">
385             <el-select
386               v-model="scope.row.point"
5c475d 387               placeholder="请选择"
cd9f11 388               filterable
fcd59a 389               :no-data-text="'无数据(predictlength:' + dataForm.mmPredictItem.predictlength + ')'"
D 390               @change="changeNormalItemSelect"
5c475d 391               style="width: 100%">
D 392               <el-option-group
fcd59a 393                 v-for="group in modelparamListMap['NormalItem'].filter(e => e.predictlength == dataForm.mmPredictItem.predictlength)"
5c475d 394                 :key="group.value"
D 395                 :label="group.label"
396               >
397                 <el-option
398                   v-for="item in group.children"
399                   :key="item.value"
400                   :label="item.label"
401                   :value="item.value"
402                 />
403               </el-option-group>
cd9f11 404             </el-select>
L 405           </template>
406         </el-table-column>
407         <el-table-column
408           prop="point"
409           label="编号"
410           align="center"/>
411         <el-table-column
412           prop=""
413           label="运算符"
414           align="center">
415           <template #default="scope">
7b1ce6 416             <el-select v-model="scope.row.operator" placeholder="请选择" clearable>
cd9f11 417               <el-option
L 418                 v-for="item in operatorList"
419                 :key="item"
420                 :label="item"
421                 :value="item"/>
422             </el-select>
423           </template>
424         </el-table-column>
425         <el-table-column
426           prop=""
427           label="操作"
2caade 428           width="140"
cd9f11 429           align="center">
L 430           <template #default="scope">
431             <el-button
432               @click="addExpressionRow(scope.$index, expressionList)"
433               type="text"
434               size="small">
435               添加
436             </el-button>
437             <el-button
438               @click="deleteExpressionRow(scope.$index, expressionList)"
439               type="text"
440               size="small">
441               删除
442             </el-button>
443           </template>
444         </el-table-column>
445       </el-table>
7462da 446     </el-form>
L 447     <template #footer>
448       <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
449       <el-button @click="dialogVisible = false">取 消</el-button>
450     </template>
451   </Dialog>
452 </template>
453 <script lang="ts" setup>
d3ee81 454 import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'
7b1ce6 455 import * as MmPredictItem from '@/api/model/pre/item'
456 import * as MmItemType from '@/api/model/pre/type'
cd9f11 457 import * as DmModule from '@/api/model/pre/dm'
be4298 458 import * as ProjectApi from '@/api/model/mpk/project'
cd9f11 459 import * as DaPoint from '@/api/data/da/point'
7b1ce6 460 import {useUpload} from '@/api/model/pre/item'
e1ff2d 461 import * as ScheduleModelApi from '@/api/model/sche/model'
d3ee81 462
463 const {uploadUrl, httpRequest} = useUpload()
7462da 464
L 465 defineOptions({name: 'DataMmPredictItemForm'})
466
467 const {t} = useI18n() // 国际化
468 const message = useMessage() // 消息弹窗
469 const dialogVisible = ref(false) // 弹窗的是否展示
470 const dialogTitle = ref('') // 弹窗的标题
471 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
472 const formType = ref('') // 表单的类型:create - 新增;update - 修改
cd9f11 473 const itemTypeList = ref([])
L 474 const itemTypeMap = ref({})
475 const moduleList = ref([])
be4298 476 const mpkProjectList = ref([])
2caade 477 const pointNoList = ref([])
cd9f11 478 const pointList = ref([])
L 479 const pointMap = ref({})
d3ee81 480 const modelparamListMap = ref({})
cd9f11 481 const modelparamMap = ref({})
L 482 const expressionList = ref([])
483 const fileList = ref([])
484 const operatorList = ['+', '-']
d3ee81 485 const replaceModelOnly = ref(false)
cd9f11 486 const queryParams = reactive({
L 487   pageNo: 1,
488   pageSize: 10,
489   pointNo: undefined,
490   pointName: undefined,
491 })
492 const dataForm = ref({
2caade 493   id: undefined,
e1ff2d 494   itemtypename: 'NormalItem',
cd9f11 495   mmPredictItem: {
2caade 496     id: undefined,
L 497     itemno: undefined,
498     itemname: undefined,
499     caltypeid: undefined,
500     itemtypeid: undefined,
501     predictlength: undefined,
d3ee81 502     granularity: 60,
2caade 503     status: undefined,
L 504     isfuse: undefined,
505     predictphase: undefined,
d3ee81 506     workchecked: 0,
2caade 507     unittransfactor: undefined,
L 508     saveindex: undefined
cd9f11 509   },
L 510   dmModuleItem: {
2caade 511     id: undefined,
L 512     moduleid: undefined,
513     itemid: undefined,
d3ee81 514     itemorder: 1,
2caade 515     status: undefined,
L 516     categoryid: undefined
cd9f11 517   },
d8e4be 518   mmItemOutputList: [],
cd9f11 519   mmPredictModel: {
2caade 520     id: undefined,
L 521     modelno: undefined,
522     modelname: undefined,
523     itemid: undefined,
524     arithid: undefined,
525     trainsamplength: undefined,
526     predictsamplength: undefined,
527     isonlinetrain: undefined,
528     modelpath: undefined,
529     isnormal: undefined,
530     normalmax: undefined,
531     normalmin: undefined,
532     status: undefined,
533     classname: undefined,
534     methodname: undefined,
535     modelparamstructure: undefined,
536     resultstrid: undefined,
be4298 537     settingmap: undefined,
D 538     mpkprojectid: undefined
cd9f11 539   },
L 540   mmPredictMergeItem: {
2caade 541     id: undefined,
L 542     itemid: undefined,
543     expression: undefined,
544     num: undefined
cd9f11 545   },
L 546   mmModelArithSettingsList: [],
547   mmModelParamList: []
7462da 548 })
L 549 const formRules = reactive({
d3ee81 550   'mmPredictItem.itemname': [{required: true, message: '预测项名不能为空', trigger: 'blur'}],
551   'mmPredictItem.itemtypeid': [{required: true, message: '类型不能为空', trigger: 'blur'}],
e1ff2d 552   'mmPredictItem.granularity': [{
d3ee81 553     required: true,
554     message: '粒度不能为空',
555     trigger: 'blur'
556   }],
e1ff2d 557   'mmPredictItem.workchecked': [{
d3ee81 558     required: true,
559     message: '是否检查不能为空',
560     trigger: 'blur'
561   }],
e1ff2d 562   'mmPredictItem.status': [{required: true, message: '是否启用不能为空', trigger: 'blur'}],
563   'dmModuleItem.moduleid': [{required: true, message: '管网不能为空', trigger: 'blur'}],
564   'dmModuleItem.itemorder': [{required: true, message: '排序不能为空', trigger: 'blur'}],
fcd59a 565   'mmPredictItem.predictlength': [{required: true, message: '预测长度不能为空', trigger: 'blur'}],
22bece 566   'mmPredictModel.mpkprojectid': [{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 => {
7db73a 638       if (e.resultstr == undefined || e.resultstr === '' || e.resultType == undefined || e.resultType === '' || (e.resultType === 2 && (e.resultIndex == undefined || e.resultIndex === ''))) {
5c475d 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
22bece 838 function deleteRow(index, row, rows) {
D 839   if (!rows || rows.length === 1 || rows.filter(e => e.modelparamportorder === row.modelparamportorder).length === 1) {
840     message.error('不可删除!')
cd9f11 841     return
L 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>