1
lzhe
2024-10-24 e795a1c5647efaae2b98b4b1a3fa2bc2037c4383
src/views/mdc/realtime-status/index.vue
@@ -1,8 +1,8 @@
<!--
 * @Date: 2024-04-09 22:11:21
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-10-06 22:31:43
 * @FilePath: /mdc/Users/mache/Documents/demo/cps-web/src/views/mdc/realtime-status/index.vue
 * @LastEditTime: 2024-10-22 20:56:44
 * @FilePath: /cps-web/src/views/mdc/realtime-status/index.vue
 实时看板
-->
<template>
@@ -16,7 +16,7 @@
            <el-icon class="setIcon">
               <Setting />
            </el-icon>
            <span class="setBtn" @click="goSet">设置</span>
            <span class="setBtn" @click="goSet">分析设置</span>
         </span>
      </div>
      <ul class="status-view-box" v-if="station == '状态视图'">
@@ -44,11 +44,12 @@
               <ArrowRight />
            </el-icon>
         </div>
         <div class="status-content-cardp" v-for="item in timestatus" :style="{ 'width': (100 / column) + '%' }">
         <div class="status-content-cardp" v-for="(item, index) 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">
                     <div title="461" class="status-card-detail-name">{{ item.code }}</div>
                     <div class="status-card-detail-name" :title="item.name">{{ item.name }}</div>
                     <div class="status-card-detail-status">
                        <div class="status-card-detail-point" :style="{ 'background-color': item.statusStyle }">
                        </div>{{ item.statusName }}
@@ -59,22 +60,19 @@
                  </div>
                  <div class="status-card-machine" style="border-color: #ccc;">
                     <div class="status-card-machine-img">
                        <img src="./station.png" width="68" height="68">
                        <img :src="item.avatar" width="68" height="68">
                     </div>
                     <div class="status-card-machine-mesg">
                        <div class="status-card-machine-mesg-form">
                           <div class="status-card-machine-mesg-label">工位编号</div>
                           <div class="status-card-machine-mesg-value">{{ item.code }}</div>
                        </div>
                        <div class="status-card-machine-mesg-form">
                           <div class="status-card-machine-mesg-label">工单</div>
                           <div class="status-card-machine-mesg-value">-</div>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="status-card-bottom">
                  <div class="status-card-bottom-realtime" @click="showvisible(item)"><i
                  <div class="status-card-bottom-realtime" @click="showvisible(item, index)"><i
                        class="iconfont saber-xiangqing status-card-bottom-icon"></i> 实时数据</div>
                  <div class="status-card-bottom-detail" @click="gostatus(item)"><i
                        class="iconfont saber-shuju status-card-bottom-icon"></i> 工位详情</div>
@@ -84,7 +82,7 @@
      </div>
      <el-dialog :title="titleMap" v-model="visible" :width="740">
         <div class="dialogstyle">
            <div class="realtime-analysis-card" v-for="item in visibleList">
            <div class="realtime-analysis-card" v-for="item in timestatus[clickIndex].properties">
               <div class="card-name" :style="{ 'background-color': item.color }">{{ item.name }}</div>
               <div class="card-value"
                  :class="{ 'card-value': true, 'card-value-bg1': item.key != 'Alarm', 'card-value-bg2': item.key == 'Alarm' }">
@@ -96,6 +94,7 @@
</template>
<script>
import station from "./station1.jpg";
import moment from 'moment';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
let icons = []
@@ -108,6 +107,8 @@
   },
   data() {
      return {
         station: station,
         clickIndex: 0,
         allwcs: [],
         statusStyle: "#ccc",
         titleMap: "",
@@ -127,9 +128,8 @@
      }
   },
   mounted() {
      this.deviceStatus = this.$route.query.currentTag?[...this.$route.query.currentTag]:[];
      this.deviceStatus = this.$route.query.currentTag ? [...this.$route.query.currentTag] : [];
      this.getstationlabelList();  //获取标签视图下的list
      this.setIntervalTime();   //十秒增加时间
      this.getprocess(); //获取颜色==》获取顶部title==》设置几行几列==》ws
   },
   methods: {
@@ -151,10 +151,17 @@
            // 解析时间字符串为天数、小时、分钟和秒  
            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; // 小时转换为毫秒
               var minutes = parseInt(parts[3], 10) * 60 * 1000; // 分钟转换为毫秒
               var seconds = parseInt(parts[4], 10) * 1000; // 秒转换为毫秒
               if(parts == null) {
                  var days = 0; // 天数转换为毫秒
                  var hours = 0; // 小时转换为毫秒
                  var minutes = 0; // 分钟转换为毫秒
                  var seconds = 0; // 秒转换为毫秒
               }else {
                  var days = parseInt(parts[1], 10) * 24 * 60 * 60 * 1000; // 天数转换为毫秒
                  var hours = parseInt(parts[2], 10) * 60 * 60 * 1000; // 小时转换为毫秒
                  var minutes = parseInt(parts[3], 10) * 60 * 1000; // 分钟转换为毫秒
                  var seconds = parseInt(parts[4], 10) * 1000; // 秒转换为毫秒
               }
               // 创建一个Moment.js的持续时间对象  
               var duration = moment.duration(days + hours + minutes + seconds);
               // 增加时间  
@@ -194,11 +201,18 @@
         this.$HTTP.get("/api/blade-cps/group/get-mdc-group").then(res => {
            if (res.code == 200) {
               this.stationlabelList = res.data;
               this.stationlabel = res.data[0].groupName;
               if (res.data.length != 0) {
                  this.stationlabel = res.data[0].groupName;
               }
            }
         })
      },
      changestatus(name) {
         if (this.stationlabelList.length == 0) {
            this.station = "状态视图";
            this.$message.error('未选定实时看板查询组,请到"分析设置 -> 实时看板查询组设置"中选择工位组');
            return;
         }
         this.station = name;
         if (this.station == '状态视图') {
            this.workStationGroupIdList = [];
@@ -208,17 +222,15 @@
         }
         this.gettimestatus();  //查询列表
      },
      showvisible(item) {
         if (item.properties == null || item.properties.length == 0) {
      showvisible(item, index) {
         if(item.properties.length == 0) {
            this.$message({
               message: '请配置采集项',
               message: '该工位没有配置数据点',
               type: 'warning'
            });
            return;
         }
         var visibleList = JSON.parse(JSON.stringify(item.properties));
         this.titleMap = "实时数据(" + item.code + ")";
         this.visibleList = visibleList;
         this.clickIndex = index;
         this.visible = true;
      },
      searchstatus(item, index) {
@@ -241,7 +253,7 @@
         }
      },
      goSet() {
         this.$router.push('/mdc/configuration');
         this.$router.push('/mdc/configuration');  //分析设置
      },
      gostatus(item) {
         this.$router.push('/mdc/station-live?code=' + item.id);
@@ -255,12 +267,12 @@
            }
         })
      },
      changeTime(time) {
      changeTime(time,diffTime) {
         // 使用Moment.js解析这两个日期字符串  
         var date1 = moment(time);
         var date2 = moment(moment().format('YYYY-MM-DD HH:mm:ss'));
         var date2 = moment(diffTime);
         // 计算两个日期之间的差异(毫秒)  
         var differenceInMilliseconds = date2.diff(date1); // 注意:date2 - date1 给出正数差异
         var differenceInMilliseconds = date1.diff(date2); // 注意:date1 - date2 给出正数差异
         // 使用duration对象将差异转换为更易于处理的单位  
         var duration = moment.duration(differenceInMilliseconds);
         // 提取天数、小时数、分钟数和秒数  
@@ -281,8 +293,10 @@
         this.$HTTP.post(`/api/blade-cps/workstation/real-time-status?current=${this.current || 0}&size=${this.size || 6}`, obj).then(res => {
            if (res.code == 200) {
               var ids = [];
               console.log(this.allwcs, res.data)
               res.data.records.forEach(item => {
                  if(item.avatar == "") {
                     item.avatar = station;
                  }
                  ids.push(item.id);
                  if (item.properties != null && item.properties.length != 0) {
                     item.properties.forEach(item1 => {
@@ -315,10 +329,10 @@
                     that.$TOOL.socket.sendDataToWebSocket(obj);  //发送
                  }
               }, 500);
               var num = 0;
               //var num = 0;
               var intervalId;
               this.$TOOL.socket.websocket.onmessage = function (event) {
                  num++;
                  //num++;
                  var eventData = JSON.parse(event.data);
                  if (that.timestatus.length == 0) return;  //没值不用循环
                  that.timestatus.forEach((item, index) => {  //第一步把v放到code里
@@ -329,7 +343,10 @@
                        }
                        if (eventData.data.DeviceStatus) {
                           var time = moment(eventData.data.DeviceStatus.t).format('YYYY-MM-DD HH:mm:ss');
                           var diffTime = that.changeTime(time);  //转换成差值(时分秒)
                           var preT = moment(eventData.data.DeviceStatus.preT).format('YYYY-MM-DD HH:mm:ss');
                           var diffTime = that.changeTime(time,preT);  //转换成差值(时分秒)
                           //that.setIntervalTime();   //十秒增加时间
                           var diffTime = diffTime;
                           item.time = diffTime;
                           that.allwcs.forEach(item1 => {
                              if (item1.code == eventData.data.DeviceStatus.v) {
@@ -345,48 +362,43 @@
                        }
                        item.properties.forEach((item1, index1) => {
                           if (item1.key == "DeviceStatus") {  //机器状态
                              if (item1.value == "2") {
                                 that.allwcs.forEach(item2 => {
                                    if (item2.code == item1.value) {
                                       item1.color = item2.color;
                                       item1.code = item2.name;
                                    }
                                 })
                              } else {
                                 item1.color = "#75C0C0";
                              }
                              that.allwcs.forEach(item2 => {
                                 if(eventData.data.DeviceStatus && item2.code == eventData.data.DeviceStatus.v) {
                                    item1.value = item2.code;
                                    item1.color = item2.color;
                                    item1.code = item2.name;
                                 }
                              })
                              if (Object.keys(eventData.data).length == 0) {  //ws没有data数据,给默认值
                                 item1.code = "";
                                 item1.color = "#E4A512";
                              };
                           } else {
                              if (item1.key == 'Alarm') {  //报警
                                 if (eventData.data[item1.key]) {
                                    if(eventData.data[item1.key].v == "") return;
                                    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;
                                          that.allwcs.forEach(item2 => {
                                             if (item2.name == "报警") {
                                                item1.color = item2.color;
                                             }
                                          })
                                          item1.code = v[0].alarmNo;
                                       }
                                    } else {
                                       item1.name = v.code;
                                       item1.code = v.msg;
                                       that.allwcs.forEach(item2 => {
                                          if (item2.name == "报警") {
                                             item1.color = item2.color;
                                          }
                                       })
                                    }
                                 }
                              } else {
                                 if (eventData.data[item1.key]) {
                                    item1.code = eventData.data[item1.key].v;
                                    item1.color = "#75C0C0";
                                 }
                              }
                              that.allwcs.forEach(item2 => {
                                 if (item2.name == "报警") {
                                    item1.color = item2.color;
                                 }
                              })
                           }
                        })
                     }
@@ -425,7 +437,7 @@
            }
         })
      }
   }
   },
}
</script>
@@ -534,7 +546,7 @@
   font-weight: 700;
   font-size: 16px;
   color: #333;
   width: 33%;
   max-width: 37%;
   overflow: hidden;
   white-space: nowrap;
   text-overflow: ellipsis;
@@ -550,12 +562,12 @@
   width: 12px;
   height: 12px;
   border-radius: 6px;
   margin-right: 8px;
   margin-right: 2px;
}
.status-card-detail-time {
   line-height: 12px;
   margin-left: 16px;
   margin-left: 2px;
}
.status-card-machine {