chenxiaofeng 5 years ago
parent
commit
e25ed87c45
4 changed files with 57 additions and 43 deletions
  1. 4 21
      app.js
  2. 3 7
      pages/Landpage/Land/Land.js
  3. 38 14
      pages/chat-list/chat-list.js
  4. 12 1
      pages/chat/chat.js

+ 4 - 21
app.js

@@ -7,29 +7,9 @@ App({
7 7
 
8 8
 
9 9
   asd() {
10
-    try {
11
-      const value = wx.getStorageSync('wx_id')
12
-      if (value) {
13
-        // Do something with return value
14
-      }
15
-    } catch (e) {
16
-      // Do something when catch error
17
-    }
18
-
19
-    try {
20
-      const value = wx.getStorageSync('access_token')
21
-      if (value) {
22
-        // Do something with return value
23
-      }
24
-    } catch (e) {
25
-      // Do something when catch error
26
-    }
27
-    // console.log(wx.getStorageSync('wx_id'))    //已经授权 id
28
-    // console.log(wx.getStorageSync('access_token'))    //是否注册过
29
-
30 10
 
31 11
     if (wx.getStorageSync('access_token')) {   //是否注册过
32
-
12
+      
33 13
       wx.reLaunch({
34 14
         url: '/pages/index/index'        //注册过 进入首页
35 15
       })
@@ -207,6 +187,9 @@ App({
207 187
   },
208 188
   UserId: function () {
209 189
     return wx.getStorageSync('access_token');
190
+  },
191
+  UserToken: function () {
192
+      return wx.getStorageSync('access_user');
210 193
   }
211 194
 
212 195
 })

+ 3 - 7
pages/Landpage/Land/Land.js

@@ -73,8 +73,9 @@ Page({
73 73
       password: this.data.password,    // 密码
74 74
     };
75 75
     app.postRequest(Land_url, Land_data, function (res) {
76
+
76 77
       if (res.code == 201) {
77
-        //  console.log(res.data);
78
+         console.log(res.data);
78 79
         // console.log(res.data.access_key);
79 80
         // console.log(res.data.access_token);
80 81
 
@@ -85,13 +86,8 @@ Page({
85 86
                   // 全局同步传参
86 87
                   try {
87 88
                     wx.setStorageSync('access_key', res.data.access_key)
88
-                  } catch (e) {
89
-
90
-                  }
91
-
92
-                  // 全局同步传参
93
-                  try {
94 89
                     wx.setStorageSync('access_token', res.data.access_token)
90
+                    wx.setStorageSync('access_user', res.data.access_user)
95 91
                   } catch (e) {
96 92
 
97 93
                   }

+ 38 - 14
pages/chat-list/chat-list.js

@@ -22,15 +22,6 @@ Page({
22 22
       let that = this;
23 23
       // emojiChar: "☺-😋-😌-😍-😏-😜-😝-😞-😔-😪-😭-😁-😂-😃-😅-😆-👿-😒-😓-😔-😏-😖-😘-😚-😒-😡-😢-😣-😤-😢-😨-😳-😵-😷-😸-😻-😼-😽-😾-😿-🙊-🙋-🙏-✈-🚇-🚃-🚌-🍄-🍅-🍆-🍇-🍈-🍉-🍑-🍒-🍓-🐔-🐶-🐷-👦-👧-👱-👩-👰-👨-👲-👳-💃-💄-💅-💆-💇-🌹-💑-💓-💘-🚲",
24 24
 
25
-      app.postRequest('my/images/headurl', {}, function (res){
26
-        if (res.code == 201) {
27
-          console.log(res);
28
-          that.setData({
29
-            myheadurl: res.data.img,
30
-            // optioninfocode: res,
31
-          })
32
-        } 
33
-      })
34 25
 
35 26
 
36 27
 
@@ -39,6 +30,13 @@ Page({
39 30
     // console.log(e);
40 31
     // return ;
41 32
     let _that = this;
33
+    for (var index in _that.data.conversations){
34
+      if (_that.data.conversations[index].to_id == e.currentTarget.dataset.item.to_id){
35
+        _that.data.conversations[index].count = 0;
36
+      }
37
+    }
38
+    // wx.setStorageSync('','');
39
+    wx.setStorageSync('chat_to_id', e.currentTarget.dataset.item.to_id)
42 40
     wx.navigateTo({
43 41
       url: '../chat/chat?to_id=' + e.currentTarget.dataset.item.to_id + '&headUrl=' + e.currentTarget.dataset.item.img + '&myheadurl='+_that.data.myheadurl
44 42
     });
@@ -46,9 +44,35 @@ Page({
46 44
     /**
47 45
      * 生命周期函数--监听页面显示
48 46
      */
49
-    onShow() {
47
+    onShow(e) {
50 48
       var _this = this;
49
+      try {
50
+          let value = wx.getStorageSync('chat_to_id')
51
+      if (value) {
52
+        for (var index in _this.data.conversations) {
53
+          if (_this.data.conversations[index].to_id == value) {
54
+            _this.data.conversations[index].count = 0;
55
+          }
56
+        }  
57
+      }
58
+    } catch (e) {
59
+
60
+    }
61
+      console.log(e,111111222222);
62
+   
51 63
     console.log(11);
64
+
65
+      app.postRequest('my/images/headurl', {}, function (res) {
66
+        if (res.code == 201) {
67
+          console.log(res);
68
+          _this.setData({
69
+            myheadurl: res.data.img,
70
+            // optioninfocode: res,
71
+          })
72
+        }
73
+      })
74
+
75
+      console.log(getApp().UserId());
52 76
       webSocket.sendSocketMessage({
53 77
         msg: JSON.stringify({ form_id: getApp().UserId(), type: 'Chat_list' }),
54 78
         success: function (res) {
@@ -101,12 +125,12 @@ Page({
101 125
       case 'chat_list_message':
102 126
         let dataArr = _this.data.conversations;
103 127
         let idData = [];
104
-        console.log(data.data);
128
+        console.log(data.data,'chat_list_message');
105 129
     
106 130
         for (var index in dataArr){
107 131
           // idData.push(String(dataArr[index].to_id));
108
-          idData.push(String(dataArr[index].to_id)); //统一转换成string
109
-            if (dataArr[index].to_id == data.data.to_id)
132
+          idData.push(String(dataArr[index].to_str)); //统一转换成string
133
+          if (dataArr[index].to_str == data.data.to_str)
110 134
             {
111 135
               dataArr[index].count = data.data.count;
112 136
               dataArr[index].content = data.data.content;
@@ -120,7 +144,7 @@ Page({
120 144
          } 
121 145
      
122 146
         //新增一列
123
-        if (idData.indexOf(String(data.data.to_id)) == '-1'){
147
+        if (idData.indexOf(String(data.data.to_str)) == '-1'){
124 148
           dataArr.push(data.data); 
125 149
         }
126 150
          _this.setData({

+ 12 - 1
pages/chat/chat.js

@@ -233,6 +233,7 @@ Page({
233 233
         case 'get_history':
234 234
        
235 235
           console.log(data, '分页消息');
236
+          console.log(getApp().UserId(),'UserId');
236 237
           for (var index in data.data) {
237 238
             switch(data.data[index].type){
238 239
                 case 1:
@@ -246,7 +247,8 @@ Page({
246 247
             // data.data[index].time = data.data[index].create_at;
247 248
             data.data[index].showTime = true;
248 249
             //自己 
249
-            if (data.data[index].form_id == getApp().UserId()) {
250
+            console.log(getApp().UserToken());
251
+            if (data.data[index].form_id == getApp().UserToken()) {
250 252
               data.data[index].isMy = true;
251 253
               data.data[index].userId = data.data[index].form_id;
252 254
               data.data[index].headUrl = _that.data.myheadurl
@@ -295,6 +297,15 @@ Page({
295 297
   },
296 298
 
297 299
   onUnload:function(e){
300
+
301
+      let url = 'imsocket/imchatmessage/clearunreadmsg';
302
+      let datas  = {
303
+        to_id: this.data.friendId, form_id: getApp().UserId()
304
+      };
305
+    //清除未读信息
306
+    getApp().postRequest(url, datas, function (res) {
307
+          console.log(res,11111);
308
+    })
298 309
     console.log('销毁页面');
299 310
   },
300 311
   SocketSend:function(msg){