chenxiaofeng 5 years ago
parent
commit
9bc5f92125
4 changed files with 40 additions and 11 deletions
  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 2
   "pages": [
3
-    "pages/information/chat/chat",
3
+        "pages/index/index",
4
+  "pages/Jurisdiction/click_Jurisdiction/click_Jurisdiction",
4 5
 "pages/personal_core/vehicle/vehicle",
6
+  "pages/information/chat/chat",
5 7
  "pages/personal_core/remind/remind",
6
-  "pages/Jurisdiction/click_Jurisdiction/click_Jurisdiction",
8
+ 
7 9
   "pages/Setup/modify/modify",
8 10
   "pages/Landpage/Land/Land",
9 11
   "pages/zheo_More/zheo_More",
@@ -27,7 +29,7 @@
27 29
 
28 30
     "pages/personal_core/home_list/home_list",
29 31
     "pages/index_details/index_details",
30
-    "pages/index/index",
32
+
31 33
     "pages/index_screen/index_screen",
32 34
     "pages/Landpage/Retrievepassword/Retrievepassword",
33 35
     "pages/register/fillTel/fillTel",

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

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

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

@@ -20,7 +20,11 @@ Page({
20 20
 
21 21
   onLoad: function (options) {
22 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 144
     self.sendSocketMessage({
145 145
       msg: JSON.stringify({
146
-        'type': 'ping'
146
+        form_id: getApp().UserId(),
147
+        type: 'login'
147 148
       }),
148 149
       success: function (res) {
149 150
         console.log('socket心跳成功');
150 151
         if (heart) {
151 152
           heartBeatTimeOut = setTimeout(() => {
152 153
             self.heartBeat();
153
-          }, 25000);
154
+          }, 120000);
154 155
         }
155 156
       },
156 157
       fail: function (res) {