chenxiaofeng 5 years ago
parent
commit
f4641de54f
2 changed files with 15 additions and 5 deletions
  1. 1 4
      pages/index/index.js
  2. 14 1
      utils/websocket.js

+ 1 - 4
pages/index/index.js

@@ -80,10 +80,7 @@ Page({
80
     } 
80
     } 
81
     app.globalData.trigger = false;
81
     app.globalData.trigger = false;
82
 
82
 
83
-    wx.setTabBarBadge({
84
-      index: 0,
85
-      text: '1'
86
-    })  
83
+ 
87
   },
84
   },
88
  
85
  
89
  
86
  

+ 14 - 1
utils/websocket.js

@@ -209,7 +209,20 @@ wx.onSocketError(function (res) {
209
 
209
 
210
 // 监听WebSocket接受到服务器的消息事件。
210
 // 监听WebSocket接受到服务器的消息事件。
211
 wx.onSocketMessage(function (res) {
211
 wx.onSocketMessage(function (res) {
212
-  //  console.log('没有回调之前的方法:' + res.data)
212
+   
213
+  let data = JSON.parse(res.data);
214
+  console.log(data);
215
+  switch(data.type){
216
+    case 'resetChatTotal':
217
+      if (data.data.message_exists == true){
218
+        wx.setTabBarBadge({
219
+          index: 0,
220
+          text: '   1'
221
+        })  
222
+      }
223
+    break;
224
+  }
225
+   console.log('没有回调之前的方法:' + res.data)
213
   webSocket.onSocketMessageCallback(res.data);
226
   webSocket.onSocketMessageCallback(res.data);
214
 })
227
 })
215
 
228