houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false"
3              :close-on-press-escape="false">
4     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()"
5              :label-width="$i18n.locale === 'en-US' ? '160px' : '100px'">
6       <el-divider content-position="left">模型信息</el-divider>
7       <el-row :gutter="20">
8         <el-col :span="12">
9           <el-form-item :label="$t('model.modelCode')" prop="modelCode">
10             <el-input v-model="dataForm.modelCode" placeholder=""></el-input>
11           </el-form-item>
12         </el-col>
13         <el-col :span="12">
14           <el-form-item :label="$t('model.modelName')" prop="modelName">
15             <el-input v-model="dataForm.modelName" placeholder=""></el-input>
16           </el-form-item>
17         </el-col>
18       </el-row>
19       <el-row :gutter="20">
20         <el-col :span="12">
21           <el-form-item :label="$t('model.modelType')" prop="modelType">
22             <dict-select-tag style="width: 100%;" v-model="dataForm.modelType" dictCode="model_type"
23                              placeholder="请选择"></dict-select-tag>
24           </el-form-item>
25         </el-col>
26         <el-col :span="12">
27           <el-form-item :label="$t('model.modelParent')" prop="modelParent">
28             <el-input v-model="dataForm.modelParent" placeholder=""></el-input>
29           </el-form-item>
30         </el-col>
31       </el-row>
32       <el-row :gutter="20">
33         <el-col :span="24">
34           <el-form-item :label="$t('model.modelPath')" prop="modelPath">
35             <el-input v-model="dataForm.modelPath" placeholder=""></el-input>
36           </el-form-item>
37         </el-col>
38       </el-row>
39       <el-row :gutter="20">
40         <el-col :span="12">
41           <el-form-item :label="$t('model.className')" prop="className">
42             <el-input v-model="dataForm.className" placeholder=""></el-input>
43           </el-form-item>
44         </el-col>
45         <el-col :span="12">
46           <el-form-item :label="$t('model.methodName')" prop="methodName">
47             <el-input v-model="dataForm.methodName" placeholder=""></el-input>
48           </el-form-item>
49         </el-col>
50       </el-row>
51       <el-row :gutter="20">
52         <el-col :span="12">
53           <el-form-item :label="$t('model.modelLoop')" prop="modelLoop">
54             <dict-select-tag style="width: 100%"  v-model="dataForm.modelLoop" dictCode="ModelLoop"
55                              placeholder="请选择"></dict-select-tag>
56           </el-form-item>
57         </el-col>
58         <el-col :span="12">
59           <el-form-item :label="$t('model.runSort')" prop="runSort">
60             <el-input-number
61                 style="width: 100%;"
62                 v-model="dataForm.runSort" controls-position="right" :min="1" :max="100"
63                 :precision="0"></el-input-number>
64           </el-form-item>
65         </el-col>
66       </el-row>
67       <el-row :gutter="20">
68         <el-col :span="12">
69           <el-form-item :label="$t('model.paramsStructure')" prop="paramsStructure">
70             <el-input v-model="dataForm.paramsStructure" placeholder=""></el-input>
71           </el-form-item>
72         </el-col>
73         <el-col :span="12">
74           <el-form-item :label="$t('model.modelVersion')" prop="modelVersion">
75             <el-input v-model="dataForm.modelVersion" placeholder=""></el-input>
76           </el-form-item>
77         </el-col>
78       </el-row>
79       <el-row>
80         <el-col :span="24">
81           <el-form-item :label="$t('model.remark')" prop="remark">
82             <el-input v-model="dataForm.remark" placeholder="" type="textarea"></el-input>
83           </el-form-item>
84         </el-col>
85       </el-row>
86       <el-divider content-position="left">模型参数信息</el-divider>
87       <el-row :gutter="24">
88         <el-col :span="4">
89           <el-button icon="add" type="primary" size="mini" @click="addRow(1)">{{ $t('add') }}</el-button>
90         </el-col>
91       </el-row>
92       <el-table v-loading="dataListLoading" :data="dataForm.modelParamList" border
93                 style="width: 100%; margin-top: 5px;">
94         <el-table-column
95             prop=""
96             label="输入排序"
97             width="80"
98             align="center">
99           <template slot-scope="scope">
100             <el-input-number size="mini" v-model="scope.row.paramPortOrder" :min="1" :max="50"
101                              :precision="0"
102                              :controls="false" clearable
103                              style="width:100%;hight:100%"></el-input-number>
104           </template>
105         </el-table-column>
106         <el-table-column
107             prop=""
108             label="参数排序"
109             width="80"
110             align="center">
111           <template slot-scope="scope">
112             <el-input-number size="mini" v-model="scope.row.paramOrder" :min="1" :max="50" :precision="0"
113                              :controls="false" clearable
114                              style="width:100%;hight:100%"></el-input-number>
115           </template>
116         </el-table-column>
117         <el-table-column
118             prop=""
119             label="参数类型"
120             min-width="80"
121             align="center">
122           <template slot-scope="scope">
123             <dict-select-tag style="width: 100%" size="mini" v-model="scope.row.paramType" dictCode="paramtype"
124                              @change="scope.row.paramId = ''"
125                              placeholder="请选择"></dict-select-tag>
126           </template>
127         </el-table-column>
128         <el-table-column
129             prop=""
130             label="参数名称"
131             min-width="160"
132             align="center">
133           <template slot-scope="scope">
134             <!--测点选项-->
135             <el-select v-if="scope.row.paramType === 'point'"
136                        style="width: 100%" size="mini"
137                        v-model="scope.row.paramId" filterable clearable
138                        placeholder="请选择">
139               <el-option
140                   v-for="(item, index) in pointList"
141                   :key="index"
142                   :label="item.pointName"
143                   :value="item.pointNo">
144               </el-option>
145             </el-select>
146
147             <!--指标项-->
148             <el-select v-else-if="scope.row.paramType === 'ind'"
149                        style="width: 100%" size="mini"
150                        v-model="scope.row.paramId" filterable clearable
151                        placeholder="请选择">
152               <el-option
153                   v-for="(item, index) in indItemList"
154                   :key="index"
155                   :label="item.itemName"
156                   :value="item.itemNo">
157               </el-option>
158             </el-select>
159
160             <!--其他-->
161             <el-input v-else
162                       style="width: 100%" size="mini"
163                       v-model="scope.row.paramId">
164             </el-input>
165           </template>
166         </el-table-column>
167         <el-table-column
168             prop=""
169             label="参数长度"
170             width="80"
171             align="center">
172           <template slot-scope="scope">
173             <el-input-number size="mini"
174                              v-model="scope.row.dataLength"
175                              :min="1" :max="10000" :precision="0" :controls="false" clearable
176                              style="width:100%;hight:100%"></el-input-number>
177           </template>
178         </el-table-column>
179         <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="100">
180           <template slot-scope="scope">
181             <el-button
182                 @click.native.prevent="deleteRow(scope.$index, dataForm.modelParamList)"
183                 type="text"
184                 size="mini">
185               删除
186             </el-button>
187           </template>
188         </el-table-column>
189
190       </el-table>
191       <el-divider content-position="left">模型设置信息</el-divider>
192       <el-row :gutter="20">
193         <el-col :span="4">
194           <el-button type="primary" size="mini" @click="addRow(2)">{{ $t('add') }}</el-button>
195         </el-col>
196       </el-row>
197       <el-table v-loading="dataListLoading" :data="dataForm.modelSettingList" border
198                 style="width: 100%; margin-top: 5px;">
199         <el-table-column
200             prop=""
201             label="参数名"
202             align="center">
203           <template slot-scope="scope">
204             <el-input size="mini" v-model="scope.row.settingKey" maxlength="50" clearable
205                       style="width:100%;hight:100%"></el-input>
206           </template>
207         </el-table-column>
208         <el-table-column
209             prop=""
210             label="参数值"
211             align="center">
212           <template slot-scope="scope">
213             <el-input size="mini" v-model="scope.row.settingValue" maxlength="50" clearable
214                       style="width:100%;hight:100%"></el-input>
215           </template>
216         </el-table-column>
217         <el-table-column
218             prop=""
219             label="值类型"
220             align="center">
221           <template slot-scope="scope">
222             <dict-select-tag size="mini" style="width: 100%;" v-model="scope.row.valueType" dictCode="model_setting_type"
223                              placeholder="值类型"></dict-select-tag>
224           </template>
225         </el-table-column>
226
227
228         <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="100">
229           <template slot-scope="scope">
230             <el-button
231                 @click.native.prevent="deleteRow(scope.$index, dataForm.modelSettingList)"
232                 type="text"
233                 size="mini">
234               删除
235             </el-button>
236           </template>
237         </el-table-column>
238       </el-table>
239
240       <el-divider content-position="left">下发配置</el-divider>
241       <el-row :gutter="20">
242         <el-col :span="4">
243           <el-button type="primary" size="mini" @click="addRow(3)">{{ $t('add') }}</el-button>
244         </el-col>
245       </el-row>
246       <el-table v-loading="dataListLoading" :data="dataForm.modelOutList" border
247                 style="width: 100%; margin-top: 5px;">
248         <el-table-column
249             prop=""
250             label="输出key"
251             align="center"
252             min-width="100">
253           <template slot-scope="scope">
254             <el-input size="mini" v-model="scope.row.resultKey" maxlength="50" clearable
255                       style="width:100%;hight:100%"></el-input>
256           </template>
257         </el-table-column>
258         <el-table-column
259             prop=""
260             label="是否下发"
261             align="center">
262           <template slot-scope="scope">
263             <dict-select-tag style="width: 100%;" v-model="scope.row.isWrite" dictCode="is_write" size="mini"
264                              placeholder="是否下发" clearable></dict-select-tag>
265           </template>
266         </el-table-column>
267         <el-table-column
268             prop=""
269             label="下发的点位"
270             align="center"
271             min-width="100">
272           <template slot-scope="scope">
273             <el-select
274                 style="width: 100%"
275                 size="mini"
276                 v-model="scope.row.pointNo"
277                 filterable
278                 clearable
279                 placeholder="请选择">
280               <el-option
281                   v-for="(item, index) in pointList"
282                   :key="index"
283                   :label="item.pointName"
284                   :value="item.pointNo">
285               </el-option>
286             </el-select>
287           </template>
288         </el-table-column>
289         <el-table-column
290             prop=""
291             label="无扰切换点位"
292             align="center" min-width="100">
293           <template slot-scope="scope">
294             <el-select
295                 style="width: 100%"
296                 size="mini"
297                 v-model="scope.row.disturbancePointNo"
298                 filterable
299                 clearable
300                 placeholder="请选择">
301               <el-option
302                   v-for="(item, index) in pointList"
303                   :key="index"
304                   :label="item.pointName"
305                   :value="item.pointNo">
306               </el-option>
307             </el-select>
308           </template>
309         </el-table-column>
310         <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="100">
311           <template slot-scope="scope">
312             <el-button
313                 @click.native.prevent="deleteRow(scope.$index, dataForm.modelOutList)"
314                 type="text"
315                 size="mini">
316               删除
317             </el-button>
318           </template>
319         </el-table-column>
320       </el-table>
321     </el-form>
322     <template slot="footer">
323       <el-button :loading="loading" @click="visible = false">{{ $t('cancel') }}</el-button>
324       <el-button :loading="loading" type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
325     </template>
326   </el-dialog>
327 </template>
328
329 <script>
330 import debounce from 'lodash/debounce'
331 import DictSelectTag from "@/components/dict/dict-select-tag.vue";
332
333 export default {
334   components: {DictSelectTag},
335   data() {
336     return {
337       dataListLoading: false,
338       visible: false,
339       loading: false,
340       dataForm: {
341         id: '',
342         modelCode: '',
343         modelName: '',
344         modelParent: '',
345         modelType: '',
346         modelPath: '',
347         className: '',
348         methodName: '',
349         paramsStructure: '',
350         remark: '',
351         modelLoop: '',
352         creator: '',
353         createTime: '',
354         updater: '',
355         updateTime: '',
356         modelParamList: [],
357         modelSettingList: [],
358         modelOutList: [],
359         modelVersion:''
360       },
361       pointList: [],
362       pointMap: {},
363       indItemList: [],
364       indItemMap: {},
365       upload: {
366         action: window.SITE_CONFIG['apiURL'] + '/mcs/st-model/upload',
367         fileList: []
368       }
369     }
370   },
371   computed: {
372     dataRule() {
373       return {
374         modelCode: [
375           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
376         ],
377         modelName: [
378           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
379         ],
380         modelType: [
381           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
382         ],
383         modelPath: [
384           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
385         ],
386         className: [
387           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
388         ],
389         methodName: [
390           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
391         ]
392       }
393     }
394   },
395   methods: {
396     init() {
397       this.dataListLoading = false
398       this.visible = true
399       this.loading = true
400       this.$nextTick(() => {
401         this.$refs['dataForm'].resetFields()
402         this.dataForm.modelParamList = []
403         this.dataForm.modelSettingList = []
404         this.dataForm.modelOutList = []
405         Promise.all([
406           this.getPointList(),
407           this.getIndItemList()
408         ]).then(() => {
409           if (this.dataForm.id) {
410             this.getInfo()
411           } else {
412             this.loading = false
413           }
414         })
415       })
416     },
417     // 获取信息
418     getInfo() {
419       this.$http.get(`/iailab-ntt-model/mcs/st-model/${this.dataForm.id}`).then(({data: res}) => {
420         if (res.code !== 0) {
421           return this.$message.error(res.msg)
422         }
423         this.dataForm = {
424           ...this.dataForm,
425           ...res.data
426         }
427         this.loading = false
428       }).catch(() => {})
429     },
430     // 添加行
431     addRow(id) {
432       if (id == 1) {
433         this.dataForm.modelParamList.push({
434           paramName: '',
435           paramId: '',
436           paramOrder: '',
437           paramPortOrder: '',
438           dataLength: '',
439           paramType: 'point'
440         })
441       }
442       if (id == 2) {
443         this.dataForm.modelSettingList.push({
444           settingKey: '',
445           settingValue: ''
446         })
447       }
448       if (id == 3) {
449         this.dataForm.modelOutList.push({
450           resultKey: '',
451           isWrite: '',
452           pointNo: '',
453           disturbancePointNo: '',
454
455         })
456       }
457     },
458     // 删除行
459     deleteRow(index, rows) {
460       rows.splice(index, 1)
461     },
462     // 获取测点列表
463     getPointList() {
464       let params;
465       params = {
466         isEnable: 1
467       }
468       this.pointList = []
469       return this.$http.get(`/iailab-ntt-data/da/point/pointNo`, {params: params}).then(({data: res}) => {
470         if (res.code !== 0) {
471           return this.$message.error(res.msg)
472         }
473         res.data.forEach(function (value) {
474           this.pointList.push(value)
475           this.pointMap[value.pointNo] = value.pointName
476         }, this)
477       })
478     },
479     // 获取指标项列表
480     getIndItemList() {
481       let params;
482       params = {
483         isEnable: 1
484       }
485       this.indItemList = []
486       return this.$http.get(`/iailab-ntt-data/ind/item/list`, {params: params}).then(({data: res}) => {
487         if (res.code !== 0) {
488           return this.$message.error(res.msg)
489         }
490         res.data.forEach(function (value) {
491           this.indItemList.push(value)
492           this.indItemMap[value.itemNo] = value.itemName
493         }, this)
494       })
495     },
496     // 表单提交
497     dataFormSubmitHandle: debounce(function () {
498       this.$refs['dataForm'].validate((valid) => {
499         if (!valid) {
500           return false
501         }
502         this.loading = true
503         this.$http[!this.dataForm.id ? 'post' : 'put']('/iailab-ntt-model/mcs/st-model/', this.dataForm).then(({data: res}) => {
504           this.loading = false
505           if (res.code !== 0) {
506             return this.$message.error(res.msg)
507           }
508           this.$message({
509             message: this.$t('prompt.success'),
510             type: 'success',
511             duration: 500,
512             onClose: () => {
513               this.visible = false
514               this.$emit('refreshDataList')
515             }
516           })
517         }).catch(() => {
518         })
519       })
520     }, 1000, {'leading': true, 'trailing': false}),
521
522     handleRemove(file, fileList) {
523       console.log(file, fileList);
524     },
525     handlePreview(file) {
526       console.log(file);
527     },
528     handleExceed(files, fileList) {
529       this.$message.warning(`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
530     },
531     beforeRemove(file, fileList) {
532       return this.$confirm(`确定移除 ${file.name}?`);
533     },
534     handleSuccess(response, file, fileList) {
535       this.dataForm.modelPath = response.data.path;
536     }
537   }
538 }
539 </script>