heyujie
2022-07-18 fb1705290de89f8341d1f314ed2181637b5e21e7
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
<template>
  <div class="equipmentDetail">
    <IndexHeader :opacity="false"></IndexHeader>
    <!-- 面包屑 -->
    <div class="heart">
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/manageCenter' }"
          >管理中心</el-breadcrumb-item
        >
        <el-breadcrumb-item :to="{ path: '/equipmentList' }"
          >设备管理</el-breadcrumb-item
        >
        <el-breadcrumb-item>设备详情</el-breadcrumb-item>
      </el-breadcrumb>
 
      <!-- 第一行 -->
      <div class="control">
        <div class="left">
          <div class="name">{{ detailData.devName }}</div>
          <div class="time">设备当前时间: {{ time }}</div>
        </div>
 
        <div class="right">
          <div class="button resetDevice" @click="reStart">
            <span class="iconfont">&#xe61f;</span>重启设备
          </div>
          <div class="button resetSet" @click="showSettingBox = true">
            <span class="iconfont">&#xe620;</span>重启设置
          </div>
          <div class="button reset unBind" @click="showUnbindBox = true">
            <span class="iconfont">&#xe615;</span>解绑设备
          </div>
        </div>
      </div>
 
      <!-- 第二行 -->
      <div class="second">
        <div class="property row">
          <div class="title">设备性能</div>
          <el-carousel
            trigger="click"
            height="130px"
            :loop="false"
            :autoplay="false"
          >
            <el-carousel-item
              v-for="(arr, index) in devicePerformance"
              :key="index"
            >
              <div class="content">
                <div
                  class="contentItem"
                  v-for="(item, index) in arr"
                  :key="index"
                >
                  <el-progress
                    v-if="item.type == 'mem'"
                    :percentage="+item.data"
                    :color="customColors1"
                    type="circle"
                    :width="100"
                    :stroke-width="25"
                    stroke-linecap="butt"
                    class="type1"
                    :class="{ warn: item.data >= 85 }"
                  ></el-progress>
 
                  <el-progress
                    v-if="item.type == 'gpu'"
                    :percentage="+item.data"
                    :color="customColors2"
                    type="circle"
                    :width="100"
                    :stroke-width="25"
                    stroke-linecap="butt"
                    class="type2"
                    :class="{ warn: item.data >= 85 }"
                  ></el-progress>
 
                  <el-progress
                    v-if="item.type == 'cpu'"
                    :percentage="+item.data"
                    :color="customColors3"
                    type="circle"
                    :width="100"
                    :stroke-width="25"
                    stroke-linecap="butt"
                    class="type3"
                    :class="{ warn: item.data >= 85 }"
                  ></el-progress>
 
                  <el-progress
                    v-if="item.type == 'dist'"
                    :percentage="+item.data"
                    :color="customColors4"
                    type="circle"
                    :width="100"
                    :stroke-width="25"
                    stroke-linecap="butt"
                    class="type4"
                    :class="{ warn: item.data >= 85 }"
                  ></el-progress>
                  <div class="label">{{ item.name }}</div>
                </div>
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
        <div class="info row">
          <div class="title">设备版本信息</div>
          <div class="version">当前版本: V{{ versionInfo.curVersion }}</div>
          <div class="newVersion" v-if="versionInfo.hasNewVersion">
            检测到有最新版本: V{{ versionInfo.newVersion }}
          </div>
          <div
            class="button upset"
            v-if="versionInfo.hasNewVersion"
            @click="showUpdateBox = true"
          >
            更新
          </div>
        </div>
      </div>
 
      <!-- 第三行 -->
      <div class="deviceInfo row">
        <div class="title">设备信息</div>
        <div class="deviceInfo_row">
          <div class="item">
            <div class="label">设备名称</div>
            <div class="data">{{ detailData.devName }}</div>
          </div>
 
          <div class="item">
            <div class="label">设备ID</div>
            <div class="data">{{ detailData.devId }}</div>
          </div>
 
          <div class="item">
            <div class="label">使用激活码</div>
            <div class="data">{{ detailData.activateCode }}</div>
          </div>
 
          <div class="item">
            <div class="label">安装时间</div>
            <div class="data">{{ detailData.installTime }}</div>
          </div>
        </div>
 
        <div class="deviceInfo_row">
          <div class="item">
            <div class="label">绑定用户</div>
            <div class="data">{{ detailData.username }}</div>
          </div>
 
          <div class="item">
            <div class="label">IP地址</div>
            <div class="data">{{ detailData.devIp }}</div>
          </div>
 
          <div class="item">
            <div class="label">设备位置</div>
            <div class="data">{{ detailData.address }}</div>
          </div>
 
          <div class="item">
            <div class="label">首次使用时间</div>
            <div class="data">{{ detailData.firstUseTime }}</div>
          </div>
        </div>
 
        <div class="deviceInfo_row">
          <div class="item">
            <div class="label">端口</div>
            <div class="data">{{ detailData.serverPort }}</div>
          </div>
 
          <div class="item">
            <div class="label">子网隐码</div>
            <div class="data">{{ detailData.subMask }}</div>
          </div>
 
          <div class="item">
            <div class="label">网关</div>
            <div class="data">{{ detailData.gateway }}</div>
          </div>
 
          <div class="item">
            <div class="label">DNS</div>
            <div class="data">{{ detailData.dns }}</div>
          </div>
        </div>
      </div>
 
      <!-- 第四行 -->
      <div class="hardWare row">
        <div class="title">硬件信息</div>
        <div class="hardWare_row">
          <div class="item">
            <div class="label">设备型号</div>
            <div class="data">{{ detailData.devMode }}</div>
          </div>
 
          <div class="item">
            <div class="label">设备类型</div>
            <div class="data">{{ detailData.devDesc }}</div>
          </div>
 
          <div class="item">
            <div class="label">通道个数</div>
            <div class="data">{{ detailData.channelCount }}</div>
          </div>
 
          <div class="item">
            <div class="label">主控版本</div>
            <div class="data">{{ detailData.masterVersion }}</div>
          </div>
        </div>
 
        <div class="hardWare_row">
          <div class="item">
            <div class="label">web版本</div>
            <!-- <div class="data">{{ detailData.webVersion }}</div> -->
            <div class="data">2.0.0</div>
          </div>
 
          <div class="item">
            <div class="label">硬盘信息</div>
            <div class="data">{{ detailData.disk }}</div>
          </div>
 
          <div class="item">
            <div class="label">内存</div>
            <div class="data">{{ detailData.mem }}</div>
          </div>
 
          <div class="item">
            <div class="label">CPU</div>
            <div class="data">{{ detailData.devCpu }}</div>
          </div>
        </div>
 
        <div class="hardWare_row">
          <div class="item">
            <div class="label">运行时间</div>
            <div class="data">{{ detailData.runtime }}</div>
          </div>
        </div>
      </div>
 
      <!-- 表格区域 -->
      <FormArea :data="deviceProcesses"></FormArea>
    </div>
 
    <!-- 解绑弹窗 -->
    <UnbindBox
      v-if="showUnbindBox"
      :id="id"
      @close="showUnbindBox = false"
    ></UnbindBox>
 
    <!-- 重启设置弹窗 -->
    <SettingBox
      v-if="showSettingBox"
      @close="showSettingBox = false"
      :id="id"
    ></SettingBox>
 
    <!-- 更新弹窗 -->
    <UpdateBox
      v-if="showUpdateBox"
      @close="closeUpdateBox"
      :id="id"
    ></UpdateBox>
 
    <Footer :isBlack="true"></Footer>
  </div>
</template>
 
<script>
import {
  findDevDetail,
  restart,
  checkVersion,
  showSystemStates,
  showProcesses,
  clockInfo,
} from "@/api/device";
import IndexHeader from "@/components/IndexHeader";
import Footer from "@/components/Footer";
import FormArea from "@/views/equipmentManagement/equipmentDetail/components/FormArea";
import UnbindBox from "@/views/equipmentManagement/equipmentDetail/components/UnbindBox";
import SettingBox from "@/views/equipmentManagement/equipmentDetail/components/SettingBox";
import UpdateBox from "@/views/equipmentManagement/equipmentDetail/components/UpdateBox";
export default {
  components: {
    IndexHeader,
    FormArea,
    Footer,
    UnbindBox,
    SettingBox,
    UpdateBox,
  },
  created() {
    this.findDetail();
    this.getVersion();
    this.getDevicePerformance();
    this.showProcesses();
    this.getTime();
  },
  data() {
    return {
      userId: null,
      id: null,
      time: "",
      detailData: {},
      //四个环形进度条颜色
      customColors1: [
        { color: "#363CE7", percentage: 85 },
        { color: "#FF4B33", percentage: 100 },
      ],
      customColors2: [
        { color: "#40B63A", percentage: 85 },
        { color: "#FF4B33", percentage: 100 },
      ],
      customColors3: [
        { color: "#F9AE22", percentage: 85 },
        { color: "#FF4B33", percentage: 100 },
      ],
      customColors4: [
        { color: "#DF23B6", percentage: 85 },
        { color: "#FF4B33", percentage: 100 },
      ],
      showUnbindBox: false, //解绑弹出框
      showSettingBox: false, //设置弹出框
      showUpdateBox: false, //重启弹出框
      versionInfo: {}, //版本信息
      devicePerformance: [], //设备性能
      deviceProcesses: {}, //算法所占资源
    };
  },
  methods: {
    //获取设备详情
    async findDetail() {
      this.userId = JSON.parse(sessionStorage.getItem("userInfo")).id;
      this.id = this.$route.query.id;
      const res = await findDevDetail({ devId: this.id });
      this.detailData = res.data;
    },
    //获取版本信息
    async getVersion() {
      const res = await checkVersion({ nodeId: this.id });
      this.versionInfo = res.data;
    },
    //获取设备性能
    async getDevicePerformance() {
      const res = await showSystemStates({
        userId: this.userId,
        nodeId: this.id,
      });
      this.devicePerformance.push({
        data: res.data.mem.usedPercent.toString().split(".")[0],
        name: "内存",
        type: "mem",
      });
      this.devicePerformance.push({
        data: res.data.gpu.toString().split(".")[0],
        name: "算力",
        type: "gpu",
      });
      this.devicePerformance.push({
        data: res.data.cpu.toString().split(".")[0],
        name: "cpu",
        type: "cpu",
      });
      res.data.disk.forEach((item, index) => {
        this.devicePerformance.push({
          data: item.info.usedPercent.toString().split(".")[0],
          name: `硬盘${index + 1}`,
          type: "dist",
        });
      });
      const arr = [];
      this.devicePerformance.forEach((item, index) => {
        let i = index / 5 + "";
        if (i.indexOf(".") != -1) {
          i = i.split(".")[0];
        }
        if (!arr[i]) {
          arr[i] = [];
        }
        arr[i].push(item);
      });
      this.devicePerformance = arr;
    },
    //获取算法所占资源
    async showProcesses() {
      const res = await showProcesses({ userId: this.userId, nodeId: this.id });
      this.deviceProcesses = res.data;
      if (!this.deviceProcesses.algos) {
        this.deviceProcesses.algos = [];
      }
      if (!this.deviceProcesses.apps) {
        this.deviceProcesses.apps = [];
      }
    },
    //获取设备时间戳
    async getTime() {
      const res = await clockInfo({ userId: this.userId, nodeId: this.id });
      if (res && res.success) {
        //   const timezone = res.data.time_zone;
        let timestamp = res.data.local_time;
        this.time = this.formatTime(++timestamp * 1000, "Y-M-D h:m:s");
      }
    },
    //格式化时间戳
    formatTime(timestamp, format) {
      const formatNumber = (n) => {
        n = n + "";
        return n[1] ? n : "0" + n;
      };
      var formateArr = ["Y", "M", "D", "h", "m", "s"];
      var returnArr = [];
      var date = new Date(timestamp);
      returnArr.push(date.getFullYear());
      returnArr.push(formatNumber(date.getMonth() + 1));
      returnArr.push(formatNumber(date.getDate()));
      returnArr.push(formatNumber(date.getHours()));
      returnArr.push(formatNumber(date.getMinutes()));
      returnArr.push(formatNumber(date.getSeconds()));
      for (var i in returnArr) {
        format = format.replace(formateArr[i], returnArr[i]);
      }
      return format;
    },
    //重启
    reStart() {
      this.$confirm("确定要重启吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await restart({ userId: this.userId, nodeId: this.id });
          if (res.success) {
            this.$notify({
              title: "成功",
              message: res.data,
              type: "success",
            });
          } else {
            this.$notify.error({
              title: "错误",
              message: "重启失败",
            });
          }
        })
        .catch(() => {});
    },
    closeUpdateBox() {
      this.showUpdateBox = false;
      this.getVersion();
    },
  },
};
</script>
 
<style lang="scss" scoped>
.equipmentDetail {
  background-color: rgb(243, 245, 248);
 
  .el-breadcrumb {
    margin-top: 48px;
    margin-bottom: 24px;
 
    ::v-deep span {
      color: #666;
    }
  }
 
  .control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    padding: 0 20px;
    margin-top: 20px;
    width: 1280px;
    height: 80px;
    background: #ffffff;
 
    .left {
      display: flex;
      align-items: center;
 
      .name {
        margin-right: 20px;
        font-weight: bold;
        font-size: 18px;
      }
 
      .time {
        color: #666666;
        font-size: 14px;
      }
    }
 
    .right {
      display: flex;
      .button {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: 20px;
        width: 140px;
        height: 40px;
        color: #0065ff;
        border: 1px solid #0065ff;
        box-sizing: border-box;
 
        &.resetDevice {
          background: #0065ff;
          font-size: 14px;
          color: #fff;
        }
      }
 
      .iconfont {
        margin-right: 10px;
        font-size: 18px;
      }
    }
  }
 
  .row {
    box-sizing: border-box;
    padding: 20px;
    margin-top: 24px;
 
    .title {
      padding-left: 10px;
      margin-bottom: 30px;
      height: 20px;
      line-height: 20px;
      font-size: 16px;
      font-weight: 700;
      border-left: 4px solid #0065ff;
    }
  }
 
  .second {
    display: flex;
    justify-content: space-between;
    align-items: center;
 
    .property {
      width: 737px;
      height: 229px;
      background: #ffffff;
 
      .el-carousel ::v-deep {
        .el-carousel__indicators {
          display: none;
        }
 
        .content {
          display: flex;
          padding: 0 54px;
 
          .contentItem {
            margin-right: 22px;
 
            .label {
              margin-top: 5px;
              text-align: center;
            }
 
            &:nth-child(5) {
              margin-right: 0;
            }
          }
        }
 
        .el-carousel__arrow--left {
          width: 32px;
          height: 32px;
          left: 0;
        }
 
        .el-carousel__arrow--right {
          width: 32px;
          height: 32px;
          right: 0;
        }
      }
 
      .type1 ::v-deep .el-progress-circle__track {
        stroke: rgb(212, 227, 250);
      }
      .type2 ::v-deep .el-progress-circle__track {
        stroke: rgb(196, 242, 194);
      }
      .type3 ::v-deep .el-progress-circle__track {
        stroke: rgb(250, 231, 200);
      }
      .type4 ::v-deep .el-progress-circle__track {
        stroke: rgb(241, 215, 245);
      }
      .warn ::v-deep .el-progress-circle__track {
        stroke: rgb(250, 215, 210) !important;
      }
    }
 
    .info {
      position: relative;
      width: 519px;
      height: 229px;
      background: #ffffff;
 
      .version {
        margin-bottom: 10px;
        font-size: 14px;
        font-weight: 700;
      }
 
      .newVersion {
        font-size: 14px;
        color: #666666;
      }
 
      .upset {
        position: absolute;
        right: 20px;
        bottom: 30px;
        width: 140px;
        height: 40px;
        background: #0065ff;
        color: #fff;
        font-size: 14px;
        text-align: center;
        line-height: 40px;
      }
    }
  }
 
  .deviceInfo {
    margin-bottom: 24px;
    height: 222px;
    background-color: #fff;
 
    .deviceInfo_row {
      margin-bottom: 30px;
      display: flex;
      position: relative;
      height: 20px;
 
      .item {
        position: absolute;
        display: flex;
        top: 0;
 
        .label {
          font-size: 14px;
          color: #666666;
          margin-right: 20px;
          height: 84px;
        }
 
        .data {
          font-size: 14px;
          font-weight: 700;
        }
 
        &:nth-child(1) {
          left: 0;
        }
 
        &:nth-child(2) {
          left: 246px;
        }
 
        &:nth-child(3) {
          left: 561px;
        }
 
        &:nth-child(4) {
          left: 992px;
        }
      }
    }
  }
 
  .hardWare {
    margin-bottom: 24px;
    height: 222px;
    background-color: #fff;
 
    .hardWare_row {
      margin-bottom: 30px;
      display: flex;
      position: relative;
      height: 20px;
 
      .item {
        position: absolute;
        display: flex;
        top: 0;
 
        .label {
          font-size: 14px;
          color: #666666;
          margin-right: 20px;
          height: 84px;
        }
 
        .data {
          font-size: 14px;
          font-weight: 700;
        }
 
        &:nth-child(1) {
          left: 0;
        }
 
        &:nth-child(2) {
          left: 258px;
        }
 
        &:nth-child(3) {
          left: 579px;
        }
 
        &:nth-child(4) {
          left: 803px;
        }
      }
    }
  }
}
</style>