chenxiaofeng 6 年之前
父節點
當前提交
9bc5f92125
共有 4 個文件被更改,包括 40 次插入11 次删除
  1. 5 3
      app.json
  2. 9 5
      pages/chat-list/chat-list.js
  3. 23 1
      pages/information/chat/chat.js
  4. 3 2
      utils/websocket.js

+ 5 - 3
app.json

@@ -1,9 +1,11 @@
1
 {
1
 {
2
   "pages": [
2
   "pages": [
3
-    "pages/information/chat/chat",
3
+        "pages/index/index",
4
+  "pages/Jurisdiction/click_Jurisdiction/click_Jurisdiction",
4
 "pages/personal_core/vehicle/vehicle",
5
 "pages/personal_core/vehicle/vehicle",
6
+  "pages/information/chat/chat",
5
  "pages/personal_core/remind/remind",
7
  "pages/personal_core/remind/remind",
6
-  "pages/Jurisdiction/click_Jurisdiction/click_Jurisdiction",
8
+ 
7
   "pages/Setup/modify/modify",
9
   "pages/Setup/modify/modify",
8
   "pages/Landpage/Land/Land",
10
   "pages/Landpage/Land/Land",
9
   "pages/zheo_More/zheo_More",
11
   "pages/zheo_More/zheo_More",
@@ -27,7 +29,7 @@
27
 
29
 
28
     "pages/personal_core/home_list/home_list",
30
     "pages/personal_core/home_list/home_list",
29
     "pages/index_details/index_details",
31
     "pages/index_details/index_details",
30
-    "pages/index/index",
32
+
31
     "pages/index_screen/index_screen",
33
     "pages/index_screen/index_screen",
32
     "pages/Landpage/Retrievepassword/Retrievepassword",
34
     "pages/Landpage/Retrievepassword/Retrievepassword",
33
     "pages/register/fillTel/fillTel",
35
     "pages/register/fillTel/fillTel",

+ 9 - 5
pages/chat-list/chat-list.js

@@ -21,6 +21,10 @@ Page({
21
     onLoad(options) {
21
     onLoad(options) {
22
       let that = this;
22
       let that = this;
23
 
23
 
24
+  
25
+
26
+
27
+      //获取自己的头像
24
       app.postRequest('my/images/headurl', {}, function (res) {
28
       app.postRequest('my/images/headurl', {}, function (res) {
25
         if (res.code == 201) {
29
         if (res.code == 201) {
26
         //  console.log(res);
30
         //  console.log(res);
@@ -34,7 +38,7 @@ Page({
34
     // emojiChar: "☺-😋-😌-😍-😏-😜-😝-😞-😔-😪-😭-😁-😂-😃-😅-😆-👿-😒-😓-😔-😏-😖-😘-😚-😒-😡-😢-😣-😤-😢-😨-😳-😵-😷-😸-😻-😼-😽-😾-😿-🙊-🙋-🙏-✈-🚇-🚃-🚌-🍄-🍅-🍆-🍇-🍈-🍉-🍑-🍒-🍓-🐔-🐶-🐷-👦-👧-👱-👩-👰-👨-👲-👳-💃-💄-💅-💆-💇-🌹-💑-💓-💘-🚲",
38
     // emojiChar: "☺-😋-😌-😍-😏-😜-😝-😞-😔-😪-😭-😁-😂-😃-😅-😆-👿-😒-😓-😔-😏-😖-😘-😚-😒-😡-😢-😣-😤-😢-😨-😳-😵-😷-😸-😻-😼-😽-😾-😿-🙊-🙋-🙏-✈-🚇-🚃-🚌-🍄-🍅-🍆-🍇-🍈-🍉-🍑-🍒-🍓-🐔-🐶-🐷-👦-👧-👱-👩-👰-👨-👲-👳-💃-💄-💅-💆-💇-🌹-💑-💓-💘-🚲",
35
 
39
 
36
 
40
 
37
-
41
+   
38
 
42
 
39
     },
43
     },
40
   toChat(e) { //跳转进入聊天页面
44
   toChat(e) { //跳转进入聊天页面
@@ -52,7 +56,7 @@ Page({
52
     // wx.setStorageSync('','');
56
     // wx.setStorageSync('','');
53
     wx.setStorageSync('chat_to_id', e.currentTarget.dataset.item.to_id)
57
     wx.setStorageSync('chat_to_id', e.currentTarget.dataset.item.to_id)
54
     wx.navigateTo({
58
     wx.navigateTo({
55
-      url: '../chat/chat?to_id=' + e.currentTarget.dataset.item.to_id + '&headUrl=' + e.currentTarget.dataset.item.img + '&myheadurl='+_that.data.myheadurl
59
+      url: '../information/chat/chat?to_id=' + e.currentTarget.dataset.item.to_id + '&headUrl=' + e.currentTarget.dataset.item.img + '&myheadurl='+_that.data.myheadurl
56
     });
60
     });
57
   },
61
   },
58
     /**
62
     /**
@@ -72,7 +76,7 @@ Page({
72
     } catch (e) {
76
     } catch (e) {
73
 
77
 
74
     }
78
     }
75
-      console.log(e,111111222222);
79
+
76
       webSocket.sendSocketMessage({
80
       webSocket.sendSocketMessage({
77
         msg: JSON.stringify({ form_id: getApp().UserId(), type: 'Chat_list' }),
81
         msg: JSON.stringify({ form_id: getApp().UserId(), type: 'Chat_list' }),
78
         success: function (res) {
82
         success: function (res) {
@@ -81,8 +85,8 @@ Page({
81
           console.log('发送消息失败')
85
           console.log('发送消息失败')
82
         }
86
         }
83
       })
87
       })
84
-
85
       webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
88
       webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
89
+
86
       // console.log(Times.dealChatTime(new Date(), 1555257947));
90
       // console.log(Times.dealChatTime(new Date(), 1555257947));
87
       // _this.setData({
91
       // _this.setData({
88
       //   conversations: [{
92
       //   conversations: [{
@@ -120,7 +124,7 @@ Page({
120
           //清除缓存
124
           //清除缓存
121
           if (chatlistcount && dataAtt[index].to_str == chatlistcount) {
125
           if (chatlistcount && dataAtt[index].to_str == chatlistcount) {
122
             wx.removeStorageSync('ChatListCount');
126
             wx.removeStorageSync('ChatListCount');
123
-            console.log(112233);
127
+            // console.log(112233);
124
             dataAtt[index].count = 0;
128
             dataAtt[index].count = 0;
125
           }
129
           }
126
           if (dataAtt[index].type == 2) {
130
           if (dataAtt[index].type == 2) {

+ 23 - 1
pages/information/chat/chat.js

@@ -20,7 +20,11 @@ Page({
20
 
20
 
21
   onLoad: function (options) {
21
   onLoad: function (options) {
22
     var that = this;
22
     var that = this;
23
+    console.log(options);
24
+    const friend = options;
25
+    this.SocketSend({ to_id: friend.to_id, form_id: getApp().UserId(), type: 'get_history', page: this.data.limit_page });
23
 
26
 
27
+    getApp().Imsocket().onSocketMessageCallback = this.onSocketMessageCallback;
24
   },
28
   },
25
 
29
 
26
 
30
 
@@ -116,7 +120,25 @@ Page({
116
       }
120
       }
117
     })
121
     })
118
 
122
 
119
-  }
123
+  },
124
+    SocketSend: function (msg) {
125
+    // { to_id: friend.to_id, form_id: getApp().UserId(), type: 'get_history' }
126
+    // msg.type = 'get_history';
127
+    getApp().Imsocket().sendSocketMessage({
128
+      msg: JSON.stringify(msg),
129
+      success: function (res) {
130
+        console.log(res, '获取历史消息成功');
131
+      }, fail: function (res) {
132
+        console.log('获取历史消息失败')
133
+      }
134
+    })
135
+  },
136
+  onSocketMessageCallback: function (e) {
137
+    let data = JSON.parse(e);
138
+   
139
+      console.log(data,'接受消息成功');
140
+
141
+  },
120
 
142
 
121
 
143
 
122
 
144
 

+ 3 - 2
utils/websocket.js

@@ -143,14 +143,15 @@ var webSocket = {
143
     }
143
     }
144
     self.sendSocketMessage({
144
     self.sendSocketMessage({
145
       msg: JSON.stringify({
145
       msg: JSON.stringify({
146
-        'type': 'ping'
146
+        form_id: getApp().UserId(),
147
+        type: 'login'
147
       }),
148
       }),
148
       success: function (res) {
149
       success: function (res) {
149
         console.log('socket心跳成功');
150
         console.log('socket心跳成功');
150
         if (heart) {
151
         if (heart) {
151
           heartBeatTimeOut = setTimeout(() => {
152
           heartBeatTimeOut = setTimeout(() => {
152
             self.heartBeat();
153
             self.heartBeat();
153
-          }, 25000);
154
+          }, 120000);
154
         }
155
         }
155
       },
156
       },
156
       fail: function (res) {
157
       fail: function (res) {