gaoshp
2024-06-18 179136b6d89e4d24c37fc3981848f62b5673495c
src/views/mdc/realtime-status/index.vue
@@ -1,7 +1,7 @@
<!--
 * @Date: 2024-04-09 22:11:21
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-09 22:12:14
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-06-18 18:14:08
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/realtime-status/index.vue
 实时看板
-->
@@ -36,7 +36,7 @@
           <div class="status-next" @click="next">
              <el-icon><ArrowRight /></el-icon>
           </div>
           <div class="status-content-cardp" v-for="item in timestatus" style="width: 33.3333%; height: 50%;">
           <div class="status-content-cardp" v-for="item in timestatus" :style="{'width': (100/column) + '%'}">
              <div class="status-card-box" style="border-color: #ccc;">
                 <div class="status-card-top">
                    <div class="status-card-detail">
@@ -104,22 +104,39 @@
              stationlabel: "",
              stationlabelList: [],
              current: "1",
            size: "9",
              total: 0,
              deviceStatus: [],
              workStationGroupIdList: []
              workStationGroupIdList: [],
              line: "",
              column: ""
           }
        },
        mounted() {
         this.getdevicestatus();  //获取顶部title
         this.getstationlabelList();  //获取标签视图下的list
         this.setIntervalTime();   //十秒增加时间
         this.getSetting(); //设置几行几列 ==》获取顶部title
         //this.getprocess(); //获取颜色,获取机器
         this.gettimestatus();  //ws
      },
        methods: {
           getSetting() {
              this.$HTTP.get(`/api/blade-system/param/detail?paramKey=mdc.realtime.setting`).then(res=> {
               if(res.code == 200) {
                  var paramValue = JSON.parse(res.data.paramValue);
                  this.line = paramValue.line==0?1:paramValue.line;
                  this.column = paramValue.column;
                  this.current = "1";
                  this.size = this.line * this.column;
                  this.getdevicestatus();  //获取顶部title/具体数据
               }
            })
           },
           setIntervalTime() {
              function addTime(timeStr) {
                 var increaseByMilliseconds = 10 * 1000; // 10秒转换为毫秒  
               // 解析时间字符串为天数、小时、分钟和秒  
               if(timeStr != undefined) {
               if(timeStr != undefined && timeStr != "--") {
                  var parts = timeStr.match(/(\d+)天(\d+)时(\d+)分(\d+)秒/);  
                  var days = parseInt(parts[1], 10) * 24 * 60 * 60 * 1000; // 天数转换为毫秒  
                  var hours = parseInt(parts[2], 10) * 60 * 60 * 1000; // 小时转换为毫秒  
@@ -205,9 +222,10 @@
              this.gettimestatus();
           },
           next() {
              if((this.total/9 - this.current) < 0) return;
              this.current = Number(this.current) + 1;
              this.gettimestatus();
              if((this.current * this.line) < this.total/this.column) {
                 this.current = Number(this.current) + 1;
                 this.gettimestatus();
              }
           },
           goSet() {
              this.$router.push('/mdc/configuration');
@@ -219,7 +237,6 @@
            this.$HTTP.get(`/api/blade-cps/global_wcs/wcs-achievements`).then(res=> {
               if(res.code == 200) {
                  this.allwcs = res.data;
                  this.gettimestatus();
               }
            })
         },
@@ -246,8 +263,9 @@
               workStationGroupIdList: this.workStationGroupIdList
              }
              this.timestatus = [];
              this.$HTTP.post(`/api/blade-cps/workstation/real-time-status?current=${this.current}&size=9`,obj).then(res=> {
              this.$HTTP.post(`/api/blade-cps/workstation/real-time-status?current=${this.current}&size=${this.size}`,obj).then(res=> {
               if(res.code == 200) {
                  this.timestatus = res.data.records;
                  var ids = [];
                  res.data.records.forEach(item=> {
                     item.statusName = "未知";
@@ -255,16 +273,40 @@
                     ids.push(item.id);
                     if(item.properties != null) {
                        item.properties.forEach(item1=> {
                           this.devicestatus.forEach(item2=> {
                              if(item2.status == item1.value) {
                                 item.statusName = item2.statusName;
                                 item1.statusName = item2.statusName;
                                 item.statusStyle = item2.color;
                              }
                           })
                           // this.devicestatus.forEach(item2=> {
                           //    if(item2.status == item1.value) {
                           //       item.statusName = item2.statusName;
                           //       item1.statusName = item2.statusName;
                           //       item.statusStyle = item2.color;
                           //    }
                           // })
                           if(item1.value == 1) {
                              item.statusName = '报警';
                              item1.statusName = '报警';
                              item.statusStyle = "#370C0D";
                           }
                           if(item1.value == 2) {
                              item.statusName = '运行';
                              item1.statusName = '运行';
                              item.statusStyle = "#73D13D";
                           }
                           if(item1.value == 3) {
                              item.statusName = "待机";
                              item1.statusName = "待机";
                              item.statusStyle = "#FFC53D";
                           }
                           if(item1.value == 4) {
                              item.statusName = "离线";
                              item1.statusName = "离线";
                              item.statusStyle = "#595959";
                           }
                           if(item1.value == 5) {
                              item.statusName = "调试";
                              item1.statusName = "调试";
                              item.statusStyle = "#40A9FF";
                           }
                        })
                     }
                  })
                  this.total = res.data.total;
                  //发送websocket
@@ -292,15 +334,15 @@
                     }else {
                        var diffTime = "--";
                     }
                     if(res.data.records.length == 0) return;  //没值不用循环
                       res.data.records.forEach(item=> {  //第一步把v放到code里
                     if(that.timestatus.length == 0) return;  //没值不用循环
                       that.timestatus.forEach((item,index)=> {  //第一步把v放到code里
                          if(eventData.id == item.id) {
                             if(item.properties == null) {
                                item.properties = [];
                                return;
                             }
                             item.time = diffTime;
                             item.properties.forEach(item1=> {
                             item.properties.forEach((item1,index1)=> {
                                if(item1.key == "DeviceStatus") {  //机器状态
                                   //item1.code = eventData.data[item1.key].v;
                                   if(item1.value == "2") {
@@ -311,26 +353,40 @@
                                   }
                                }else {
                                  if(item1.key == 'Alarm') {  //报警
                                     var v = JSON.parse(eventData.data[item1.key].v);
                                     item1.name = v.code;
                                     item1.code = v.msg;
                                     item1.color = "#370C0D";
                                    if(eventData.data[item1.key]) {
                                       var v = JSON.parse(eventData.data[item1.key].v);
                                       if(Array.isArray(v)) {  //如果是数组,不赋值
                                          if(v.length == 0) {
                                             res.data.records[index].properties.splice(index1,1);
                                          }else {
                                             item1.name = v[0].code;
                                             item1.code = v[0].msg;
                                             item1.color = "#370C0D";
                                          }
                                       }else {
                                          item1.name = v.code;
                                          item1.code = v.msg;
                                          item1.color = "#370C0D";
                                       }
                                    }
                                  }else {
                                     item1.code = eventData.data[item1.key].v;
                                      item1.color = "#75C0C0";
                                    if(eventData.data[item1.key]) {
                                       item1.code = eventData.data[item1.key].v;
                                         item1.color = "#75C0C0";
                                    }
                                  }
                               }
                             })
                          }
                     });
                   };
                   var len = res.data.records.length;
                   intervalId = setInterval(function() {
                      if (num === len) {
                         clearInterval(intervalId);
                         that.timestatus = res.data.records;  //等所有socket回来以后赋值
                     }
                  }, 500);
                   // var len = res.data.records.length;
                   // intervalId = setInterval(function() {
                   //    if (num === len) {
                  //        clearInterval(intervalId);
                  //        that.timestatus = res.data.records;  //等所有socket回来以后赋值
                  //    }
                  // }, 500);
               }
            })
           },
@@ -340,8 +396,8 @@
                  res.data.forEach(item=> {
                     item.active = false;
                  })
                  res.data[0].color = "#73D13D";
                  res.data[1].color = "#370C0D";
                  res.data[0].color = "#370C0D";
                  res.data[1].color = "#73D13D";
                  res.data[2].color = "#FFC53D";
                  res.data[3].color = "#595959";
                  res.data[4].color = "#40A9FF";
@@ -351,7 +407,6 @@
                  res.data[3].icon = "Warning";
                  res.data[4].icon = "Odometer";
                  this.devicestatus = res.data;
                  this.getprocess(); //获取颜色,获取机器
               }
            })
           }
@@ -422,7 +477,7 @@
      display: block;
   }
   .status-content-cardp {
       min-width: 266px;
       height: 50%;
       min-height: 170px;
       margin: 0;
       padding: 4px;