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