jiangniuniu 4 жил өмнө
parent
commit
0459f4af64

+ 136 - 24
pages/situationsCenter/situationsCenter.vue

@@ -1,5 +1,15 @@
 <template>
 	<view class="situationsCenter-page">
+		<view class="calender-remind" @click="toMessagePage">
+		  <image
+		    :src="
+		      messageType
+		        ? '/static/message-unread.png'
+		        : '/static/message-read.png'
+		    "
+		    mode=""
+		  ></image>
+		</view>
 		<view class="situation-list">
 			<view class="search-box">
 				<view class="search-model" @click="openSearchBar" v-show="isSearchBoxShow">
@@ -46,6 +56,7 @@
  * 情境中心
  */
 <script>
+	import websocket from "../../utils/ws.js"; //引入websocket
 	export default {
 		data() {
 			return {
@@ -56,34 +67,32 @@
 				isSearchBoxShow:true,//搜索图标是否可见
 				situationList:[],//情境卡片列表
 				totalCount:'',//返回数据的总条数
+				refTimer: null,
+				isInitWs: null,
+				messageType: null,
 			}
 		},
 		created: function() {
 			this.nowPermission=uni.getStorageSync('nowPermission');
-			this.$store.dispatch({
-				type: 'situationsCenter/commActions',
-				payload: {
-					key: 'situationList',
-					data:{
-						pageNum:1,
-						pageSize:10
-					}
-				}
-			}).then((data) => {
-				if (data) {
-					this.totalCount=data.totalCount;
-					this.situationList=data.list.map((item,index)=>{
-						return{
-							name:item.name,
-							checkStatus:item.checkStatus,
-							nextCheckTime:item.nextCheckTime,
-							checkGroupName:item.checkGroupName,
-							topic:item.topic==0?true:false,
-							situationID:item.id,
-						}
-					});
-				}
-			});
+			
+			this.init(true);
+			this.refTimer = setInterval(() => {
+			  this.isInitWs = websocket.ws ? false : true;
+			  this.init(this.isInitWs);
+			}, 3 * 60 * 1000);
+			this.messStatus();
+		},
+		beforeDestroy() {
+		  // 关闭ws连接
+		  websocket.close();
+		  clearInterval(this.refTimer);
+		},
+		watch:{
+			  "$route":{
+				  handler(route){
+					  this.messStatus();
+				  }
+			  }
 		},
 		methods: {
 			openSearchBar(){
@@ -163,6 +172,10 @@
 									situationID:item.id,
 								}
 							});
+							let hiId = uni.getStorageSync("hiId");
+							let user = uni.getStorageSync("id");
+							let permission = uni.getStorageSync("nowPermission");
+							this.isInitWs && this.initWebsocket(hiId, user, permission);
 						}
 					});
 				}
@@ -174,6 +187,90 @@
 					});
 				}
 			},
+			toMessagePage() {
+			  // this.messageType = false;
+			  uni.navigateTo({
+			    url: `/pages/messages/messages`,
+			  });
+			},
+			
+			init(isInitWs) {
+			  this.isInitWs = isInitWs;
+			  this.getSituationList();
+			},
+			initWebsocket(hiId, user, permission) {
+			  websocket.url = `ws://192.168.1.45:8088/imed/pfm/websocket/${hiId}/${user}/${permission}`;
+			  websocket.createWebSocket(this.resolverWsData.bind(this));
+			},
+			// 解析websocket返回数据
+			resolverWsData(type) {
+			  let types = JSON.parse(type);
+			  switch (types.type) {
+			    case "TO_READ":
+			      this.messageType = true;
+			      break;
+			    default:
+			      this.messageType = false;
+			      break;
+			  }
+			},
+			getSituationList(){
+				this.$store.dispatch({
+					type: 'situationsCenter/commActions',
+					payload: {
+						key: 'situationList',
+						data:{
+							pageNum:1,
+							pageSize:10
+						}
+					}
+				}).then((data) => {
+					if (data) {
+						this.totalCount=data.totalCount;
+						this.situationList=data.list.map((item,index)=>{
+							return{
+								name:item.name,
+								checkStatus:item.checkStatus,
+								nextCheckTime:item.nextCheckTime,
+								checkGroupName:item.checkGroupName,
+								topic:item.topic==0?true:false,
+								situationID:item.id,
+							}
+						});
+						let hiId = uni.getStorageSync("hiId");
+						let user = uni.getStorageSync("id");
+						let permission = uni.getStorageSync("nowPermission");
+						this.isInitWs && this.initWebsocket(hiId, user, permission);
+					}
+				});
+			},
+			messStatus(){
+				let num = 1;
+				let timer = setInterval(()=>{
+				  this.$store.dispatch({
+					  type: "calendar/commActions",
+					  payload: {
+						key: "messagesList",
+						data: {
+						  pageNum: num,
+						  pageSize: 100,
+						},
+					  },
+					}).then((res)=>{
+						if(res && res.list.length == 0){
+							clearInterval(timer)
+						}else if(res && res.list.length != 0){
+							res.list.map((item)=>{
+								if(!item.readStatus){
+									this.messageType = true;
+									return;
+								}
+							})
+						}
+					})
+				  num++;
+				},200)
+			}
 		}
 	}
 </script>
@@ -181,6 +278,21 @@
 <style lang="less">
 	.situationsCenter-page{
 		height: 100%;
+		.calender-remind {
+		  width: 62.5rpx;
+		  height: 62.5rpx;
+		  position: fixed;
+		  right: 25rpx;
+		  background: rgba(255, 255, 255, 0.95);
+		  border-radius: 50%;
+		  z-index: 2;
+		  image {
+		    margin-left: 17.5rpx;
+		    margin-top: 16.87rpx;
+		    width: 27.5rpx;
+		    height: 28.75rpx;
+		  }
+		}
 		.situation-list{
 			// display: flex;
 			// flex-flow: row wrap;