1
李喆(开发组)
2025-07-10 c8df3f7110ecb3d26078c8499cd8364b4419cd06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
<template>
  <basic-container>
    <avue-crud
      :addBtn="false"
      :option="option"
      :table-loading="loading"
      :data="data"
      ref="crud"
      v-model:search="search"
      v-model:page="mypage"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
      @tree-load="treeLoad"
      @row-click="rowClick"
    >
      <template #menu-left>
        <el-button :size="size" type="primary" @click="showAdd()">新增根节点</el-button>
      </template>
      <template #name="{ row }">
        <span>{{row.name}}</span>
        <el-button :size="size" text v-if="row.nodeType != 70" icon="el-icon-setting" type="primary" placeholder="修改" @click="showEdit(row)" title="修改"></el-button>
        <el-button :size="size" text icon="el-icon-delete" type="primary" @click="showDel(row)" placeholder="删除" title="删除"></el-button>
        <el-button :size="size" text v-if="row.nodeType < 60" icon="el-icon-document-add" type="primary" @click="showAdd(row)" placeholder="新增子级" title="新增子级"></el-button>
        <el-button :size="size" text v-if="row.nodeType == 60" icon="el-icon-upload" type="primary" @click="showUpload(row)" placeholder="文件上传" title="文件上传"></el-button>
        <el-button :size="size" text v-if="row.nodeType == 60" icon="el-icon-pie-chart" type="primary" @click="upgrade(row)" placeholder="升级" title="升级"></el-button>
        <el-button :size="size" text v-if="row.nodeType == 70 && !isSM" icon="el-icon-position" type="primary" @click="downsend(row)" placeholder="下发" title="下发"></el-button>
      </template>
    </avue-crud>
    <!-- 新增节点 -->
    <el-dialog :title="modalTitle" append-to-body v-model="modalBox">
      <avue-form :option="modalOption" v-model="modalForm" @submit="modalSubmit" @reset-change="modalCancel"/>
    </el-dialog>
    <el-dialog title="上传文件" append-to-body v-model="uploadmodalBox">
      <avue-form :option="uploadmodalOption" v-model="uploadmodalForm" @submit="uploadmodalSubmit" @reset-change="uploadmodalCancel" :upload-before="uploadBefore" :upload-after="uploadAfter" ref="uploadRef"></avue-form>
    </el-dialog>
    <avue-tabs :option="tabsOption" @change="tabsHandleChange" style="margin-top: 30px;" v-if="isShowTabs"></avue-tabs>
      <avue-form v-if="tabsType == 'tab1'" :option="tabsFormOption" v-model="tabsForm"></avue-form>
      <span v-else-if="tabsType == 'tab2'">版本信息</span>
      <template v-else-if="tabsType == 'tab3'">
          {{fileContent}}
          <!-- <div v-for="item in fileList" v-if="fileList.length > 0" class="fileListStyle">
            <span>{{item.name}}</span>
            <span class="delFile" @click="delFile(item)">X</span>
          </div> -->
      </template>
  </basic-container>
</template>
 
<script>
 
export default {
  data() {
    return {
      file: null,
      fileContent: "",
      isSM: false,  //是否是涉密网 ,工控网5个,涉密网4个
      isShowTabs: true,
      nodeTypeList: [],
      fileList: [],
      tabsType: "tab1",
      tabsOption: {},
      tabsOption1: {
        column: [{
          icon: 'el-icon-info',
          label: '节点信息',
          prop: 'tab1',
        }, {
          icon: 'el-icon-warning',
          label: '版本信息',
          prop: 'tab2',
        }]
      },
      tabsOption2: {
        column: [{
          icon: 'el-icon-info',
          label: '节点信息',
          prop: 'tab1',
        }, {
          icon: 'el-icon-warning',
          label: '版本信息',
          prop: 'tab2',
        }, {
          icon: 'el-icon-warning',
          label: '文件内容',
          prop: 'tab3'
        }]
      },
      tabsFormOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '节点类型',
            prop: 'nodeTypeName',
            disabled: true,
            placeholder: " "
          },
          {
            label: '创建人',
            prop: 'createUserName',
            disabled: true,
            placeholder: " "
          },
          {
            label: '节点名称',
            prop: 'name',
            disabled: true,
            placeholder: " "
          },
          {
            label: '创建时间',
            prop: 'createTime',
            disabled: true,
            placeholder: " "
          },
          {
            label: '节点描述',
            prop: 'description',
            disabled: true,
            placeholder: " "
          },
          {
            label: '最后修改时间',
            prop: 'updateTime',
            disabled: true,
            placeholder: " "
          }
        ]
      },
      tabsForm: {},
      uploadmodalBox: false,
      uploadmodalForm: {},
      selectedColumn: {},
      modalForm: {},
      modalOption: {
        submitText: "保存",
        emptyText: "取消",
        menuPosition: "right",
        column: [
          {
            label: '节点类型',
            prop: 'nodeType',
            type: 'select',
            dicUrl: '/blade-system/dict-biz/dictionary?code=nc_node_type',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            disabled: true
          },
          {
            label: '设备(机床)',
            prop: 'machineCode',
            type: 'select',
            dicUrl: '/blade-mdm/machine/page',
            props: {
              label: 'name',
              value: 'code',
            },
            dicFormatter(res) {
              return res.data.records;
            }
          },
          {
            label: '节点名称',
            prop: 'name'
          },
          {
            label: '节点描述',
            prop: 'description',
            hide: true
          },
          {
            label: '备注',
            prop: 'remark',
            type: "textarea",
            span: 24
          }
        ]
      },
      modalBox: false,
      modalTitle: "",
      id: "",
      parentId:1,
      search: {
        keyword: "",
        machineGroupCode: ""
      },
      loading: true,
      mypage: {
        size: 10,
        current: 1,
        total: 0,
      },
      option: {
        rowKey: "id",
        treeProps: {
          children: "children",
          hasChildren: 'hasChildren',
        },
        lazy: true,
        rowKey: 'id',
        addBtn: false,
        editBtn: false,
        delBtn: false,
        fit: true,
        menu: false,
        column: [
          {
            label: '目录',
            prop: 'name',
            width: '360'
          },
          {
            label: '版本',
            prop: 'abc'
          },
          {
            label: '版次',
            prop: 'abc'
          },
          {
            label: '描述',
            prop: 'abc'
          },
          {
            label: '类型',
            prop: 'nodeTypeName'
          },
          {
            label: '设备',
            prop: 'machineCode'
          },
          {
            label: '固化状态',
            prop: 'abc'
          },
          {
            label: '锁定状态',
            prop: 'abc'
          },
          {
            label: '流程状态',
            prop: 'abc'
          },
          {
            label: '测试程序',
            prop: 'abc'
          },
          {
            label: '创建人',
            prop: 'createUserName',
            width: '180'
          }
        ],
      },
      data: [],
      upData: []
    };
  },
  computed: {
    uploadmodalOption() {
      return {
        submitText: "保存",
        emptyText: "取消",
        menuPosition: "right",
        column: [
          {
            label: '节点类型',
            prop: 'nodeType',
            type: 'select',
            dicUrl: '/blade-system/dict-biz/dictionary?code=nc_node_type',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            disabled: true
          },
          {
            label: '设备编号',
            prop: 'machineCode',
            type: 'select',
            dicUrl: '/blade-mdm/machine/page',
            props: {
              label: 'name',
              value: 'code',
            },
            dicFormatter(res) {
              return res.data.records;
            }
          },
          {
            label: '零组件号/图号',
            prop: 'drawingNo'
          },
          {
            label: '工序',
            prop: 'processName'
          },
          {
            label: '工序版本',
            prop: 'processEdition'
          },
          {
            label: '节点分类',
            prop: 'category',
            type: 'select',
            dicUrl: '/blade-system/dict-biz/dictionary?code=node_file_type',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            }
          },
          {
            label: '选择文件',
            prop: 'uploadFile',
            type: 'upload',
            data: {nodeId: this.id}, 
            action: "",
            showFileList: false,
            span: 24,
            tip: "请上传文件,将在提交时统一处理",
            action: "/blade-mdm/program/ncfile/upload"
          },
          {
            label: '备注',
            prop: 'remark',
            type: "textarea",
            span: 24
          }
        ]
      }
    }
  },
  watch: {
    uploadmodalBox(old) {
      //this.onLoad();
    }
  },
  methods: {
    downsend(row) {  //下发
      // this.loading = true;
      // axios({
      //   url: '/program/ncfile/send-to-machine-by-nodeid',
      //   method: 'get',
      //   params: {nodeId:id},
      // }).then(
      //   res => {
          
      //   }
      // );
    },
    upgrade(row) {  //升级
      this.loading = true;
      var obj = {id: row.id}
      axios({
        url: '/blade-mdm/program/ncfile/upgrade-process-edition',
        method: 'post',
        data: obj,
      }).then(
        resp => {
          this.$message.success('升级成功');
        }
      );
    },
    delFile(item) {
      this.loading = true;
      var obj = {id: item.id}
      axios({
        url: '/blade-mdm/program/ncfile/remove',
        method: 'post',
        params: obj,
      }).then(
        resp => {
          this.loading = false;
          this.getFile(this.id);
        }
      );
    },
    uploadBefore(file,done,loading,column) {
      //done();
      this.file = file;
      return false;
    },
    uploadAfter() {
    },
    uploadmodalSubmit(row,done) {
      if(this.file == null) {
        this.$message.error('请上传文件');
        return;
      }
      var formData = new FormData();
      formData.append('file', this.file);
      formData.append('nodeId', this.id);
      Object.keys(this.uploadmodalForm).forEach(key => {
        formData.append(key, this.uploadmodalForm[key]);
      });
      this.loading = true;
      axios({
        url: '/blade-mdm/program/ncfile/upload',
        method: 'post',
        data: formData,
      }).then(
        res => {
          this.loading = false;
          this.uploadmodalBox = false;
          this.addLocalTreeNode(row.parentId);  //重新加载下一级
          done();
        }
      );
    },
    rowClick(row) {
      this.tabsForm = row;
      this.id = row.id;
      this.isShowTabs = false;
      this.nodeTypeList.forEach(item=> {
        if(item.dictKey == row.nodeType) {
          this.tabsForm.nodeTypeName = item.dictValue;
        }
      })
      if(this.tabsForm.nodeType < 70) {
        this.tabsOption = this.tabsOption1;
      }else {
        this.tabsOption = this.tabsOption2;
        //获取文件list
        this.getFile(row.id);
      }
      this.$nextTick(()=> {
        this.tabsType = 'tab1';
        this.isShowTabs = true;
      })
    },
    tabsHandleChange(tabs) {
      this.tabsType = tabs.prop;
    },
    showUpload(row) {
      this.uploadmodalForm = row;
      this.uploadmodalBox = true;
    },
    getFile(id) { //查看文件内容
      this.loading = true;
      axios({
        url: '/blade-mdm/program/ncfile/content-by-nodeid',
        method: 'get',
        params: {nodeId:id},
      }).then(
        res => {
          this.loading = false;
          this.fileContent = res.data.data;
        }
      );
    },
    showEdit(row,done) {
      this.modalTitle = "修改";
      this.modalBox = true;
      this.modalForm = row;
    },
    showDel(row) {
      this.$confirm('将会删除该节点及其子节点,是否确认删除?', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning',
      }).then(() => {
        //调用接口
        this.loading = true;
        axios({
          url: '/blade-mdm/program/node/remove',
          method: 'post',
          params: {id: row.id},
        }).then(
          res => {
            this.loading = false;
            var nodeArr = this.$refs.crud.$refs.table.store.states.lazyTreeNodeMap.value[row.parentId];
            var arr = nodeArr.filter(item => item.id !== row.id);
            this.$refs.crud.$refs.table.store.states.lazyTreeNodeMap.value[row.parentId] = arr;
          }
        );
      })
    },
    showAdd (row) {  //新增子节点
      if(!row) {
        this.modalTitle = "新增根节点";
        this.modalForm.nodeType = "10";
        this.modalForm.parentId = 0;
      }else {
        if(row.nodeType == 60) {
          return;
        }
        this.modalTitle = "新增子节点";
        this.selectedColumn.nodeType = String(Number(row.nodeType) + 10);
        this.selectedColumn.parentId = row.id;
        this.selectedColumn.name = "";
        this.selectedColumn.id = "";
        this.modalForm = this.selectedColumn;
      }
      this.modalBox = true;
    },
    modalSubmit(row,done) {  //新增子节点保存/修改
      if(this.modalTitle == "修改") {
        var url = "/blade-mdm/program/node/update";
      }else {
        var url = "/blade-mdm/program/node/save";
      }
      //调用接口
      this.loading = true;
      axios({
        url,
        method: 'post',
        data: this.modalForm,
      }).then(
        res => {
          this.$message.success('操作成功');
          this.modalBox = false;
          // 修改,更新本地数据
          if (this.modalTitle === "修改") {
            this.updateLocalTreeNode(this.modalForm);
          }else {
            // 如果是新增操作,可能需要重新加载数据
            //this.$refs.crud.refreshTable();
            //this.onLoad();
            //新增,更新本地数据
            this.addLocalTreeNode(row.parentId);
          }
          this.loading = false;
          done(row);
        }
      );
    },
    addLocalTreeNode(parentId) {
      if(this.modalTitle == "新增根节点") {
        this.onLoad();
        return;
      }
      this.loading = true;
      var obj = {parentId: parentId}
      axios({
        url: '/blade-mdm/program/node/lazy-list',
        method: 'get',
        params: obj,
      }).then(
        res => {
          var children = res.data.data || [];
          this.$refs.crud.$refs.table.store.states.lazyTreeNodeMap.value[parentId] = [...children];
          this.loading = false;
        }
      );
    },
    updateLocalTreeNode(nodeData) {   //修改的方法
      const updateNode = (nodes) => {
        for (let i = 0; i < nodes.length; i++) {
          if (nodes[i].id === nodeData.id) {
            // 更新节点数据
            Object.assign(nodes[i], nodeData);
            return true;
          }
          if (Array.isArray(nodes[i].children) && nodes[i].children.length > 0) {
            if (updateNode(nodes[i].children)) {
              return true;
            }
          }
        }
        return false;
      };
      updateNode(this.data);
    },
    modalCancel() {
      this.modalBox = false;
    },
    uploadmodalCancel() {
      this.uploadmodalBox = false;
    },
    treeLoad (tree, treeNode, resolve) {
      this.loading = true;
      var obj = {parentId: tree.id}
      axios({
        url: '/blade-mdm/program/node/lazy-list',
        method: 'get',
        params: obj,
      }).then(
        res => {
          this.loading = false;
          resolve(res.data.data);
        }
      );
    },
    currentChange(current) {
      this.mypage.current = current;
    },
    sizeChange(size) {
      this.mypage.size = size;
    },
    refreshChange() {
      
    },
    onLoad() {  //查询treeTable
      this.loading = true;
      var obj = {parentId: ""}
      axios({
        url: '/blade-mdm/program/node/lazy-list',
        method: 'get',
        params: obj,
      }).then(
        res => {
          this.loading = false;
          this.data = res.data.data;
          if(this.data.length == 0) {
            return;
          }
          this.tabsForm = res.data.data[0];  //节点信息
          this.nodeTypeList.forEach(item=> {
            if(item.dictKey == this.data[0].nodeType) {
              this.tabsForm.nodeTypeName = item.dictValue;
            }
          })
        }
      );
    }
  },
  mounted() {
    this.tabsOption = this.tabsOption1;
    //获取nodetype
    axios({url: '/blade-system/dict-biz/dictionary?code=nc_node_type',method: 'get'}).then(res => {
        this.nodeTypeList = res.data.data;
      }
    );
    //判断版本  0:涉密网,1:工控网;//工控网5个,涉密网4个  
    axios({url: '/blade-mdm/system/param/getValue?paramKey=networkType',method: 'get'}).then(res => {
        if(res.data.data === "0") {
          this.isSM = true;
        }
      }
    );
  }
};
</script>
 
<style lang="scss">
.el-form-item__label {
  width: 120px!important;
}
.delFile {
  color: red;
  margin-left: 12px;
  cursor: pointer;
}
.fileListStyle {
  margin-left: 10px;
  margin-top: 12px;
}
</style>