From a2441175073f8b09a7eff29effd7e3e617de2f7d Mon Sep 17 00:00:00 2001
From: lzhe <lzhe@example.com>
Date: 星期四, 06 六月 2024 18:23:01 +0800
Subject: [PATCH] Merge branch 'master' of http://www.beijingsoft.cn:9090/r/smart-web

---
 src/views/mdc/realtime-status/index.vue |  195 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 168 insertions(+), 27 deletions(-)

diff --git a/src/views/mdc/realtime-status/index.vue b/src/views/mdc/realtime-status/index.vue
index 3aa324f..fdb35ae 100644
--- a/src/views/mdc/realtime-status/index.vue
+++ b/src/views/mdc/realtime-status/index.vue
@@ -36,14 +36,14 @@
 		  	<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">
 		  					<div title="461" class="status-card-detail-name">{{item.code}}</div>
 		  					<div class="status-card-detail-status">
 		  						<div class="status-card-detail-point" :style="{'background-color': item.statusStyle}"></div>{{item.statusName}}
-		        				<div class="status-card-detail-time" style="color: #ccc;">---</div>
+		        				<div class="status-card-detail-time" :style="{'color': item.statusStyle}">{{item.time}}</div>
 		        			</div>
 		        		</div>
 		        		<div class="status-card-machine" style="border-color: #ccc;">
@@ -72,8 +72,8 @@
 		  <el-dialog :title="titleMap" v-model="visible" :width="740">
 		  		<div class="dialogstyle">
 		  			<div class="realtime-analysis-card" v-for="item in visibleList">
-				  		<div class="card-name" :style="{'background-color': item.namecolor}">{{item.name}}</div>
-				  		<div class="card-value" :style="{'background-color': item.statuscolor}">{{item.statusName}}</div>
+				  		<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'}">{{item.code}}</div>
 				  	</div>
 		  		</div>
 		  </el-dialog>
@@ -81,6 +81,7 @@
 </template>
 
 <script>
+	import moment from 'moment';
 	import * as ElementPlusIconsVue from '@element-plus/icons-vue'
 	let icons = []
 	for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
@@ -92,6 +93,7 @@
 	    },
         data() {
         	return {
+        		allwcs: [],
         		statusStyle: "#ccc",
         		titleMap: "",
         		visible: false,
@@ -102,16 +104,68 @@
         		stationlabel: "",
         		stationlabelList: [],
         		current: "1",
+				size: "9",
         		total: 0,
         		deviceStatus: [],
-        		workStationGroupIdList: []
+        		workStationGroupIdList: [],
+        		line: "",
+        		column: ""
         	}
         },
         mounted() {
-			this.getdevicestatus();  //鑾峰彇椤堕儴title
 			this.getstationlabelList();  //鑾峰彇鏍囩瑙嗗浘涓嬬殑list
+			this.setIntervalTime();   //鍗佺澧炲姞鏃堕棿
+			this.getSetting(); //璁剧疆鍑犺鍑犲垪
 		},
         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绉掕浆鎹负姣  
+					// 瑙f瀽鏃堕棿瀛楃涓蹭负澶╂暟銆佸皬鏃躲�佸垎閽熷拰绉�  
+					if(timeStr != undefined) {
+						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; // 绉掕浆鎹负姣    
+						// 鍒涘缓涓�涓狹oment.js鐨勬寔缁椂闂村璞�  
+						var duration = moment.duration(days + hours + minutes + seconds);  
+						// 澧炲姞鏃堕棿  
+						duration.add(increaseByMilliseconds); // 澧炲姞10绉�  
+						// 灏嗘寔缁椂闂磋浆鎹㈠洖澶╂暟銆佸皬鏃躲�佸垎閽熷拰绉掞紙娉ㄦ剰杩欓噷鍙兘涓嶅畬鍏ㄧ簿纭紝鍥犱负澶╂暟鍙兘涓嶆槸鏁存暟锛�  
+						var totalMilliseconds = duration.asMilliseconds();  
+						var totalDays = Math.floor(totalMilliseconds / (1000 * 60 * 60 * 24));  
+						var remainingMilliseconds = totalMilliseconds % (1000 * 60 * 60 * 24);  
+						var totalHours = Math.floor(remainingMilliseconds / (1000 * 60 * 60));  
+						remainingMilliseconds %= (1000 * 60 * 60);  
+						var totalMinutes = Math.floor(remainingMilliseconds / (1000 * 60));  
+						remainingMilliseconds %= (1000 * 60);  
+						var totalSeconds = Math.floor(remainingMilliseconds / 1000); 
+						return `${totalDays}澶�${totalHours}鏃�${totalMinutes}鍒�${totalSeconds}绉抈;
+					}else {
+						return timeStr;
+					}
+        		}  
+        		setInterval(()=> {
+        			if(this.timestatus.length !=0) {
+        				this.timestatus.forEach(item=> {
+        					item.time = addTime(item.time);
+        				})
+        			}
+        		},1000*10)
+        	},
         	changestationlabel(name) {
         		this.stationlabel = name;
         		this.stationlabelList.forEach(item=> {
@@ -140,7 +194,7 @@
         		this.gettimestatus();  //鏌ヨ鍒楄〃
         	},
         	showvisible(item) {
-        		if(item.properties == null) {
+        		if(item.properties == null || item.properties.length == 0) {
         			this.$message({
 			          message: '璇烽厤缃噰闆嗛」',
 			          type: 'warning'
@@ -148,16 +202,6 @@
 			        return;
         		}
         		var visibleList = JSON.parse(JSON.stringify(item.properties));
-        		visibleList.forEach(item=> {
-        			if(item.statusName) {
-        				item.namecolor = "#ccc";
-        				item.statuscolor = "rgba(89, 89, 89, 0.14)";
-        			}else {
-        				item.namecolor = "rgb(127, 192, 192)";
-        				item.statuscolor = "rgba(127, 192, 192, 0.14)";
-        			}
-        			
-        		})
         		this.titleMap = "瀹炴椂鏁版嵁(" + item.code + ")";
         		this.visibleList = visibleList;
         		this.visible = true;
@@ -176,9 +220,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');
@@ -186,17 +231,44 @@
         	gostatus(item) {
         		this.$router.push('/mdc/station-live?code='+item.id);
         	},
+        	getprocess() {  //棰滆壊鐘舵��
+				this.$HTTP.get(`/api/blade-cps/global_wcs/wcs-achievements`).then(res=> {
+					if(res.code == 200) {
+						this.allwcs = res.data;
+						this.gettimestatus();
+					}
+				})
+			},
+			changeTime(time) {
+				// 浣跨敤Moment.js瑙f瀽杩欎袱涓棩鏈熷瓧绗︿覆  
+				var date1 = moment(time);  
+				var date2 = moment(moment().format('YYYY-MM-DD HH:mm:ss'));  
+				// 璁$畻涓や釜鏃ユ湡涔嬮棿鐨勫樊寮傦紙姣锛�  
+				var differenceInMilliseconds = date2.diff(date1); // 娉ㄦ剰锛歞ate2 - date1 缁欏嚭姝f暟宸紓  
+				// 浣跨敤duration瀵硅薄灏嗗樊寮傝浆鎹负鏇存槗浜庡鐞嗙殑鍗曚綅  
+				var duration = moment.duration(differenceInMilliseconds);  
+				// 鎻愬彇澶╂暟銆佸皬鏃舵暟銆佸垎閽熸暟鍜岀鏁�  
+				var differenceInDays = duration.asDays();  
+				var differenceInHours = duration.hours(); // 鐩存帴浣跨敤hours()鏂规硶鑾峰彇灏忔椂鏁�  
+				var differenceInMinutes = duration.minutes(); // 鐩存帴浣跨敤minutes()鏂规硶鑾峰彇鍒嗛挓鏁�  
+				var differenceInSeconds = duration.seconds(); // 鐩存帴浣跨敤seconds()鏂规硶鑾峰彇绉掓暟  
+				// 杈撳嚭缁撴灉锛堜娇鐢∕ath.floor纭繚鏁存暟锛�  
+				return Math.floor(differenceInDays) + "澶�" + Math.floor(differenceInHours) + "鏃�" + Math.floor(differenceInMinutes) + "鍒�" + Math.floor(differenceInSeconds) + "绉�";
+			},
         	gettimestatus() {
+        		var that = this;
         		var obj = {
         			deviceStatus: this.deviceStatus,
 					workStationGroupIdList: this.workStationGroupIdList
         		}
-        		this.$HTTP.post(`/api/blade-cps/workstation/real-time-status?current=${this.current}&size=9`,obj).then(res=> {
+        		this.timestatus = [];
+        		this.$HTTP.post(`/api/blade-cps/workstation/real-time-status?current=${this.current}&size=${this.size}`,obj).then(res=> {
 					if(res.code == 200) {
-						var records = JSON.parse(JSON.stringify(res.data.records));
-						records.forEach(item=> {
+						var ids = [];
+						res.data.records.forEach(item=> {
 							item.statusName = "鏈煡";
 							item.statusStyle = '#ccc';
+							ids.push(item.id);
 							if(item.properties != null) {
 								item.properties.forEach(item1=> {
 									this.devicestatus.forEach(item2=> {
@@ -210,8 +282,71 @@
 							}
 							
 						})
-						this.timestatus = records;
-						this.total = res.data.total;	
+						this.total = res.data.total;
+						//鍙戦�亀ebsocket
+						var obj = {
+							type: "realTimeData",
+							workstationIdList: ids
+						}
+						if(this.$TOOL.socket.websocket == null) {  //娌℃湁寤虹珛鍏堝缓绔�
+							this.$TOOL.socket.connectToWebSocket(this.$TOOL.cookie.get("TOKEN")); 
+						}
+						var intervalId123 = setInterval(function() { 
+					    	if (that.$TOOL.socket.websocket.readyState == 1) {  
+							    clearInterval(intervalId123);  
+							    that.$TOOL.socket.sendDataToWebSocket(obj);  //鍙戦��
+							}  
+						}, 500);
+						var num = 0;
+						var intervalId;
+						this.$TOOL.socket.websocket.onmessage = function(event) { 
+							num ++;
+							var eventData = JSON.parse(event.data);
+							if(eventData.data.DeviceStatus != undefined) {
+								var time = moment(eventData.data.DeviceStatus.t).format('YYYY-MM-DD HH:mm:ss');
+								var diffTime = that.changeTime(time);  //杞崲鎴愬樊鍊硷紙鏃跺垎绉掞級
+							}else {
+								var diffTime = "--";
+							}
+							if(res.data.records.length == 0) return;  //娌″�间笉鐢ㄥ惊鐜�
+					        res.data.records.forEach(item=> {  //绗竴姝ユ妸v鏀惧埌code閲�
+					        	if(eventData.id == item.id) {
+					        		if(item.properties == null) {
+					        			item.properties = [];
+					        			return;
+					        		}
+					        		item.time = diffTime;
+					        		item.properties.forEach(item1=> {
+					        			if(item1.key == "DeviceStatus") {  //鏈哄櫒鐘舵��
+					        				//item1.code = eventData.data[item1.key].v;
+					        				if(item1.value == "2") {
+							        			item1.color = "#73D13D";
+							        			item1.code = "杩愯";
+							        		}else {
+							        			item1.color = "#75C0C0";
+							        		}
+					        			}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";
+									    	}else {
+									    		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;  //绛夋墍鏈塻ocket鍥炴潵浠ュ悗璧嬪��
+							}  
+						}, 500);
 					}
 				})
         	},
@@ -232,7 +367,7 @@
 						res.data[3].icon = "Warning";
 						res.data[4].icon = "Odometer";
 						this.devicestatus = res.data;
-						this.gettimestatus();  //鑾峰彇鏈哄櫒
+						this.getprocess(); //鑾峰彇棰滆壊锛岃幏鍙栨満鍣�
 					}
 				})
         	}
@@ -303,7 +438,7 @@
 		display: block;
 	}
 	.status-content-cardp {
-	    min-width: 266px;
+	    height: 50%;
 	    min-height: 170px;
 	    margin: 0;
 	    padding: 4px;
@@ -468,4 +603,10 @@
 		width: 100%;
     	flex-wrap: wrap;
 	}
+	.card-value-bg1 {
+		background-color: rgba(115, 209, 61, 0.14);
+	}
+	.card-value-bg2 {
+		background-color: rgba(55, 12, 13, 0.14);
+	}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3