Your Name 5 年之前
父节点
当前提交
9bca9c2a06

+ 148 - 101
pages/information/chat/chat.js

@@ -7,34 +7,36 @@ Page({
7 7
    * 页面的初始数据
8 8
    */
9 9
   data: {
10
+    toView:'Stop',
10 11
     scrollTopVal: 1,    //滚动条
11 12
     menu: false, //菜单显示隐藏
12 13
     Expression: false,  // 表情显示隐藏
13 14
     Sendoutshow: false, // 发送按钮显示隐藏
14 15
     menushow: true, //菜单按钮显示隐藏
15
-    _width:500, //input高度
16
+    _width: 500, //input高度
16 17
     // uploadImages: ["/image/smyz2.png","/image/smyz1.png"], //相册放大图集
17
-    news:'',//input消息
18
+    news: '',//input消息
18 19
     KeyboardHeight: 366.66666666666674, //键盘高度
19
-    ExpressionImg:'', //表情
20
-    inputValue:'',  //input 的 value 
21
-    photo:'', //相片
20
+    ExpressionImg: '', //表情
21
+    // Loadmore: true, //用来判断加载聊天记录。。每次只能执行一次
22
+    inputValue: '',  //input 的 value 
23
+    photo: '', //相片
22 24
 
23
-    Receive_news:'', //历史消息
24
-    UserToken:'',  //区分自己
25
-    limit_page:1,
25
+    Receive_news: '', //历史消息
26
+    UserToken: '',  //区分自己
27
+    limit_page: 1,
26 28
 
27
-    myheadurl:'', //我的头像
28
-    headUrl:'', //他人头像
29
+    myheadurl: '', //我的头像
30
+    headUrl: '', //他人头像
29 31
 
30
-    to_id:'',    //他人
31
-    form_id:'',   //自己
32
+    to_id: '',    //他人
33
+    form_id: '',   //自己
32 34
 
33 35
     // scrollTop:'' //下拉更多时的位置
34
-    connectemojiO: ['😊','😅','😲', '😭', '😂', '😄', '😩', '😞', '😵', '😒', '😍', '😤', '😜', '😝', '😋', '😘', '😚', '😷', '😳', '😃', '😆', '😁', '😢', '😨', '😠', '😣', '😌', '😖', '😔', '😰', '😱', '😪', '😏', '😓'],
36
+    connectemojiO: ['😊', '😅', '😲', '😭', '😂', '😄', '😩', '😞', '😵', '😒', '😍', '😤', '😜', '😝', '😋', '😘', '😚', '😷', '😳', '😃', '😆', '😁', '😢', '😨', '😠', '😣', '😌', '😖', '😔', '😰', '😱', '😪', '😏', '😓'],
35 37
 
36
-  },
37 38
 
39
+  },
38 40
 
39 41
   onLoad: function (options) {
40 42
     var that = this;
@@ -57,10 +59,13 @@ Page({
57 59
 
58 60
 
59 61
     this.SocketSend({
60
-        //  to_id: friend.to_id,    // 他人
61
-        //  form_id: getApp().UserId(),   //自己
62
-         type: 'get_history', 
63
-         page: this.data.limit_page
62
+      //  to_id: friend.to_id,    // 他人
63
+      //  form_id: getApp().UserId(),   //自己
64
+      type: 'get_history',
65
+      page: this.data.limit_page,
66
+      limit:10
67
+      
68
+
64 69
     });
65 70
     getApp().Imsocket().onSocketMessageCallback = this.onSocketMessageCallback;
66 71
 
@@ -69,19 +74,19 @@ Page({
69 74
   },
70 75
 
71 76
 
72
-// 点击scroll-view 关闭底部菜单
73
-  resetInputStatus: function() {
77
+  // 点击scroll-view 关闭底部菜单
78
+  resetInputStatus: function () {
74 79
     var that = this;
75
-    that.setData({ 
80
+    that.setData({
76 81
       menu: false, //关闭底部菜单
77 82
       Expression: false, //关闭表情
78 83
     })
79 84
   },
80 85
 
81 86
 
82
-// 底部菜单显示隐藏切换
83
-  chatInputExtraClickEvent:function(){
84
-        var that = this;
87
+  // 底部菜单显示隐藏切换
88
+  chatInputExtraClickEvent: function () {
89
+    var that = this;
85 90
     that.setData({
86 91
       menu: !that.data.menu,
87 92
       Expression: false, //关闭表情
@@ -91,7 +96,7 @@ Page({
91 96
 
92 97
 
93 98
   // 关闭表情显示隐藏切换
94
-ExpressionClickEvent: function () {
99
+  ExpressionClickEvent: function () {
95 100
     var that = this;
96 101
     that.setData({
97 102
       Expression: !that.data.Expression,
@@ -99,11 +104,11 @@ ExpressionClickEvent: function () {
99 104
     })
100 105
   },
101 106
 
102
-  
103 107
 
104 108
 
105 109
 
106
-// 相册点击放大
110
+
111
+  // 相册点击放大
107 112
   enlarge: function (e) {
108 113
     var that = this;
109 114
     // console.log(that.data.uploadImages)
@@ -125,7 +130,7 @@ ExpressionClickEvent: function () {
125 130
     that.setData({
126 131
       news: e.detail.value,     //获取输入文字
127 132
     })
128
- 
133
+
129 134
 
130 135
     that.Sendoutswitch(e.detail.value); // 发送键切换
131 136
   },
@@ -158,9 +163,9 @@ ExpressionClickEvent: function () {
158 163
               let con = data.data;
159 164
               //显示图片
160 165
               console.log(con, 1);
161
-        
166
+
162 167
               // console.log(ImgRes.tempFilePaths[0], 1222222);
163
-              that.SocketSend({type: ImageType,  content: con});
168
+              that.SocketSend({ type: ImageType, content: con });
164 169
 
165 170
               // that.msgManager.sendMsg({ type: IMOperator.ImageType, content: con })
166 171
 
@@ -184,11 +189,11 @@ ExpressionClickEvent: function () {
184 189
       }
185 190
     })
186 191
   },
187
-  
192
+
188 193
 
189 194
 
190 195
   // 重发消息
191
-  retransmission:function(){
196
+  retransmission: function () {
192 197
     wx.showModal({
193 198
       content: '重发该消息?',
194 199
       success(res) {
@@ -203,9 +208,9 @@ ExpressionClickEvent: function () {
203 208
 
204 209
 
205 210
 
206
-// 发送消息
211
+  // 发送消息
207 212
   SocketSend: function (msg) {
208
-    var that =this;
213
+    var that = this;
209 214
     msg.form_id = getApp().UserId();
210 215
     msg.to_id = that.data.to_id;
211 216
 
@@ -214,13 +219,13 @@ ExpressionClickEvent: function () {
214 219
     // { to_id: friend.to_id, form_id: getApp().UserId(), type: 'get_history' }
215 220
     // msg.type = 'get_history';
216 221
     getApp().Imsocket().sendSocketMessage({
217
-       msg: JSON.stringify(msg),
218
-   
219
-        success: function (res) {   //发送成功
222
+      msg: JSON.stringify(msg),
223
+
224
+      success: function (res) {   //发送成功
220 225
 
221 226
         // 我跟他人说话
222
-        switch(msg.type){
223
-       
227
+        switch (msg.type) {
228
+
224 229
           case "alone":     //  发送文本
225 230
 
226 231
             console.log(' 发送文本');
@@ -230,22 +235,22 @@ ExpressionClickEvent: function () {
230 235
               time: Date.now(),         //时间
231 236
               isMy: true,   //自己
232 237
               send: true,   //    发送成功  为true   失败false 
233
-              };
234
-            let _Receive_news =  that.data.Receive_news;
238
+            };
239
+            let _Receive_news = that.data.Receive_news;
235 240
             _Receive_news.push(obj);   //合并历史消息对象
236 241
 
237
-            console.log(_Receive_news,'aaa');
242
+            console.log(_Receive_news, 'aaa');
238 243
             that.setData({
239 244
               Receive_news: _Receive_news,     //前台数据赋值 
240 245
             });
241 246
 
242 247
             //调用页面滚动条处理
243 248
             that.scrollbar(_Receive_news);
244
-  
245
-           break;
246 249
 
247
-           case "images":   //  发送图片
248
-    
250
+            break;
251
+
252
+          case "images":   //  发送图片
253
+
249 254
             console.log(' 发送图片');
250 255
 
251 256
             var obj = {     //创建对象,用来合并历史消息对象
@@ -269,8 +274,8 @@ ExpressionClickEvent: function () {
269 274
 
270 275
 
271 276
 
272
-           break; 
273
-        } 
277
+            break;
278
+        }
274 279
 
275 280
         console.log(res, '获取历史消息成功');
276 281
 
@@ -284,49 +289,80 @@ ExpressionClickEvent: function () {
284 289
   },
285 290
 
286 291
 
287
-// 接收消息
292
+  // 接收消息
288 293
   onSocketMessageCallback: function (e) {
289 294
     var that = this;
290 295
     let data = JSON.parse(e);
291
-
296
+  
292 297
     //  console.log(data,'接受消息成功');
293 298
 
294 299
     var arrData = data.data;
295 300
 
296
-    switch(data.type){
301
+    switch (data.type) {
297 302
       // 接收历史消息
298 303
       case "get_history":
299 304
         // console.log(arrData,111112222);
305
+
306
+        // let total = arrData.length - 1;
307
+        // console.log(total);
300 308
         for (var index in arrData) {     //二次赋值  
301 309
           if (arrData[index].form_id == getApp().UserToken()) {   //判断  如果等于自己 true  ,等于他人  false。
302 310
             arrData[index].isMy = true;    //自己
303
-            }else{
311
+          } else {
304 312
             arrData[index].isMy = false;   //他人
305
-            }
313
+          }
314
+      
315
+        
306 316
           that.ArrMsg.push(arrData[index]);
307 317
         }
308 318
 
309
-        // 滚动条处理
310
-        var scrollTopValLength = "";
319
+
320
+        for (var index in that.ArrMsg) {     //二次赋值  
321
+              if(that.ArrMsg[index].hooks){
322
+                that.ArrMsg[index].hooks = '';
323
+              }
324
+        }
325
+     
326
+
327
+        // // 滚动条处理
328
+   
329
+        // that.ceshi();
330
+        let Arrs1 = that.sortarr(that.ArrMsg);
331
+        if(Arrs1[10]){
332
+          Arrs1[10].hooks = 'Stop';
333
+        }
334
+    
335
+        console.log(Arrs1, 111112222);
336
+ 
337
+
338
+     
339
+
311 340
         if (that.data.limit_page == 1) {
312
-          scrollTopValLength = arrData.length * 999
313
-        } else {
314
-          scrollTopValLength = arrData.length * 100
341
+
342
+          that.setData({
343
+            Receive_news: Arrs1,        //前台数据赋值 
344
+            scrollTopVal: that.ArrMsg.length * 999,    // 滚动条赋值
345
+            toView: false,
346
+          });
347
+
348
+        }else{
349
+          that.setData({
350
+            Receive_news: Arrs1,        //前台数据赋值 
351
+            toView: 'Stop'
352
+          });
315 353
         }
316 354
 
317
-        console.log(that.ArrMsg, 111112222);
355
+
318 356
         that.setData({
319
-          Receive_news: that.sortarr(that.ArrMsg),        //前台数据赋值 
320
-          scrollTopVal: scrollTopValLength,    // 滚动条赋值
357
+          toView: false,
321 358
         });
322 359
 
323
-    
324 360
         // that.scrollbar(that.ArrMsg);      //调用页面滚动条处理  这里不对
325
-      break; 
361
+        break;
326 362
 
327 363
 
328 364
       case "alone":       // 接收他人文本
329
-        console.log(arrData,"aaasd");
365
+        console.log(arrData, "aaasd");
330 366
 
331 367
         var obj = {     //创建对象,用来合并历史消息对象
332 368
           content: arrData.content,   //发送消息内容
@@ -337,14 +373,14 @@ ExpressionClickEvent: function () {
337 373
 
338 374
         let _Receive_news = that.data.Receive_news;
339 375
         _Receive_news.push(obj);      //合并历史消息对象
340
-     
376
+
341 377
         that.setData({
342 378
           Receive_news: _Receive_news,     //前台数据赋值 
343 379
         });
344 380
 
345 381
         //调用页面滚动条处理
346 382
         that.scrollbar(_Receive_news);
347
-      break; 
383
+        break;
348 384
 
349 385
       case "images":   // 接收他人图片
350 386
         console.log(arrData, "接收图片");
@@ -367,7 +403,7 @@ ExpressionClickEvent: function () {
367 403
         that.scrollbar(_Receive_img);
368 404
 
369 405
 
370
-        break; 
406
+        break;
371 407
 
372 408
 
373 409
 
@@ -377,10 +413,10 @@ ExpressionClickEvent: function () {
377 413
 
378 414
   },
379 415
 
380
-// 处理滚动条
416
+  // 处理滚动条
381 417
   scrollbar: function (data) {
382
-    var that =this;
383
-    if(data){
418
+    var that = this;
419
+    if (data) {
384 420
       let lengNum = data.length;
385 421
       //页面滚动条处理
386 422
 
@@ -396,7 +432,7 @@ ExpressionClickEvent: function () {
396 432
   Sendout: function (e) {
397 433
     var that = this;
398 434
     // console.log(that.data.news);
399
-    
435
+
400 436
     let msg = {
401 437
       // to_id: that.data.to_id,
402 438
       // form_id: getApp().UserId(),
@@ -407,12 +443,12 @@ ExpressionClickEvent: function () {
407 443
     // console.log(msg);
408 444
     this.SocketSend(msg);
409 445
 
410
-      that.setData({
411
-        menu: false,  //隐藏底部菜单
412
-        Expression: false,//隐藏表情栏
413
-        inputValue: '',  //清空 input
414
-        news: '', //清空 input内容
415
-      })
446
+    that.setData({
447
+      menu: false,  //隐藏底部菜单
448
+      Expression: false,//隐藏表情栏
449
+      inputValue: '',  //清空 input
450
+      news: '', //清空 input内容
451
+    })
416 452
 
417 453
 
418 454
     that.Sendoutswitch(that.data.news)  // 发送键切换
@@ -421,7 +457,7 @@ ExpressionClickEvent: function () {
421 457
 
422 458
   },
423 459
 
424
-//冒泡排序
460
+  //冒泡排序
425 461
   sortarr: function (arr) {
426 462
     for (let i = 0; i < arr.length - 1; i++) {
427 463
       for (let j = 0; j < arr.length - 1 - i; j++) {
@@ -435,31 +471,32 @@ ExpressionClickEvent: function () {
435 471
     return arr;
436 472
   },
437 473
 
438
- 
439
-   upper: function (e) {
440
-    // console.log(e,'加载')
441
- 
442
-     let that = this;
443
-     that.setData({
444
-       limit_page: that.data.limit_page * 1 + 1
445
-     })
446
-     console.log(that.data.limit_page * 1 + 1)
447
-     that.SocketSend({type: 'get_history', page: that.data.limit_page })
448 474
 
449
-  
475
+  //  下拉加载聊天记录
476
+  upper: function (e) {
477
+    var that = this;
478
+    console.log(e,'加载')
479
+
480
+    that.setData({
481
+      limit_page: that.data.limit_page * 1 + 1
482
+    })
483
+    console.log(that.data.limit_page * 1 + 1)
484
+    that.SocketSend({ type: 'get_history', page: that.data.limit_page,limit:10})
485
+
486
+    console.log('执行')
450 487
   },
451 488
 
452 489
 
453
-// 点击表情
454
-  Expression:function(e){
490
+  // 点击表情
491
+  Expression: function (e) {
455 492
     var that = this;
456 493
 
457 494
     var _news = that.data.news;
458 495
     var _text = _news + e.currentTarget.dataset.id;
459 496
 
460 497
 
461
-    console.log(that.data.news) 
462
-    console.log(_text) 
498
+    console.log(that.data.news)
499
+    console.log(_text)
463 500
     that.setData({
464 501
       news: _text,
465 502
       inputValue: _text,
@@ -469,14 +506,14 @@ ExpressionClickEvent: function () {
469 506
   },
470 507
 
471 508
 
472
-// 点击input
473
-  bindfocusclick: function(e) {
509
+  // 点击input
510
+  bindfocusclick: function (e) {
474 511
     var that = this;
475
-   that.setData({
476
-     Expression: false,
477
-     menu: false,
478
-     KeyboardHeight: e.detail.height,
479
-   })
512
+    that.setData({
513
+      Expression: false,
514
+      menu: false,
515
+      KeyboardHeight: e.detail.height,
516
+    })
480 517
     console.log(e.detail.height);
481 518
   },
482 519
 
@@ -497,7 +534,17 @@ ExpressionClickEvent: function () {
497 534
       })
498 535
     }
499 536
   },
500
-
537
+  // ceshi: function (e) {
538
+  //   var that = this;
539
+
540
+  //   that.setData({
541
+  //     // mscrollTop: e.detail.scrollTop,
542
+  //     mscrollHeight: e.detail.scrollHeight
543
+  //   })
544
+  //   // console.log(e.detail.scrollTop);
545
+  //   // console.log(e.detail.scrollHeight);
546
+  //   // console.log(e.detail);
547
+  // }
501 548
 
502 549
 
503 550
 })

+ 7 - 7
pages/information/chat/chat.wxml

@@ -3,12 +3,13 @@
3 3
     bindscrolltoupper="upper"
4 4
     bindscrolltolower="lower"
5 5
     bindscroll="scroll" -->
6
-    
7
-<scroll-view class="history"     scroll-top="{{scrollTopVal}}"    scroll-y="true" bindtap="resetInputStatus"  bindscrolltoupper="upper" >
8
-
6
+   <!-- bindscroll="ceshi" -->
7
+<scroll-view class="history"     scroll-top="{{scrollTopVal}}"    scroll-y="true"  bindtap="resetInputStatus"  bindscrolltoupper="upper"   scroll-into-view="{{toView}}">
8
+  <!-- <view style='height:1000px;'></view>
9
+     <view  id="red"  style='height:10px;'></view> -->
9 10
           <!-- 自己 -->
10 11
            <block  wx:for='{{Receive_news}}' wx:key="item">
11
-                <view class='my_right c' wx:if="{{item.isMy === true}}">
12
+                <view class='my_right c' wx:if="{{item.isMy === true}}" id="{{item.hooks}}">
12 13
                           <text class='time' wx:if="{{item.time}}">{{item.time}}</text>
13 14
                             <!-- 文字-->
14 15
                           <view class='information' wx:if="{{item.type == 1}}">   
@@ -45,7 +46,7 @@
45 46
 
46 47
 
47 48
               <!-- 他人 -->
48
-                <view class='my_left c' wx:if="{{item.isMy === false}}">
49
+                <view class='my_left c' wx:if="{{item.isMy === false}}"  id="{{item.hooks}}">
49 50
                           <text class='l_time' wx:if="{{item.time}}">{{item.time}}</text>
50 51
                         
51 52
                           <view class='l_information' wx:if="{{item.type == 1}}">
@@ -62,8 +63,7 @@
62 63
                 </view>
63 64
 
64 65
         </block>
65
-  
66
-          <!-- <view style='height:148rpx'></view> -->
66
+
67 67
 
68 68
 </scroll-view>
69 69
 

+ 1 - 1
pages/personal_core/home/home.js

@@ -71,7 +71,7 @@ Page({
71 71
       if (res.code == 201) {
72 72
         console.log(res.data);
73 73
         that.setData({
74
-          memberstatus: res.data.msg
74
+          memberstatus: res.data.messages
75 75
         })
76 76
       }
77 77
     })

+ 3 - 7
pages/personal_core/home/home.wxml

@@ -7,13 +7,9 @@
7 7
               <text class='core_l_id'>NO:{{datum.number}}</text>    
8 8
 
9 9
               <view class='core_style c'>
10
-
11
-                            <text wx:if="{{datum.member}}"  style='background:#FAC466'>{{datum.member}}</text>
12
-                            <text wx:if="{{datum.real_name}}"  style='background:#70E18B'>{{datum.real_name}}</text>
13
-
14
-                          <!-- <image class='asd' src='/image/a1.png' mode="widthFix"></image>
15
-                          <image class='asd' src='/image/a2.png' mode="widthFix"></image>
16
-                          <image class='asd' src='/image/a3.png' mode="widthFix"></image> -->
10
+                            <image  wx:if="{{datum.member}}"  src='{{datum.member}}' mode="widthFix"></image>
11
+                            <image  wx:if="{{datum.real_name}}" src='{{datum.real_name}}' mode="widthFix"></image>
12
+                            <!-- <image  wx:if="{{datum.real_name}}" src='/image/a2.png' mode="widthFix"></image> -->
17 13
                </view>
18 14
        </view>
19 15
 

+ 1 - 1
pages/personal_core/home/home.wxss

@@ -6,7 +6,7 @@
6 6
 .core_l_id{font-size:28rpx;margin-top:5rpx;}
7 7
 .core_style{margin-top:10rpx;}
8 8
 .core_style text{font-size:18rpx;color:#FFF;background:#F55858;margin-right:12rpx;padding:4rpx 10rpx;float:left;border-radius:6rpx;}
9
-
9
+.core_style  image{width:40rpx;display:block;float:left;margin-right:20rpx;}
10 10
 
11 11
 .core_data{width:180rpx;height:180rpx;float:right;position:relative;border-radius:100rpx;overflow: hidden;background:#FFF;}
12 12