|
@@ -1,4 +1,5 @@
|
1
|
1
|
const app = getApp();
|
|
2
|
+const time = require('../../../utils/time.js');
|
2
|
3
|
const ImageType = 'images';
|
3
|
4
|
const TextType = 'text';
|
4
|
5
|
Page({
|
|
@@ -7,6 +8,8 @@ Page({
|
7
|
8
|
* 页面的初始数据
|
8
|
9
|
*/
|
9
|
10
|
data: {
|
|
11
|
+ codedata: true, //用来判断code
|
|
12
|
+ frequency:true, //多次加载次数限制
|
10
|
13
|
hiddenName:true, // 加载更多显示隐藏
|
11
|
14
|
toView:'Stop', //锚点
|
12
|
15
|
scrollTopVal: 1, //滚动条
|
|
@@ -72,6 +75,8 @@ Page({
|
72
|
75
|
|
73
|
76
|
|
74
|
77
|
|
|
78
|
+
|
|
79
|
+
|
75
|
80
|
},
|
76
|
81
|
|
77
|
82
|
|
|
@@ -127,7 +132,7 @@ Page({
|
127
|
132
|
//input输入框
|
128
|
133
|
Telephone: function (e) {
|
129
|
134
|
var that = this;
|
130
|
|
- console.log(e.detail.value);
|
|
135
|
+ // console.log(e.detail.value);
|
131
|
136
|
that.setData({
|
132
|
137
|
news: e.detail.value, //获取输入文字
|
133
|
138
|
})
|
|
@@ -166,7 +171,7 @@ Page({
|
166
|
171
|
console.log(con, 1);
|
167
|
172
|
|
168
|
173
|
// console.log(ImgRes.tempFilePaths[0], 1222222);
|
169
|
|
- that.SocketSend({ type: ImageType, content: con });
|
|
174
|
+ that.SocketSend({ type: ImageType, content: con.img_name });
|
170
|
175
|
|
171
|
176
|
// that.msgManager.sendMsg({ type: IMOperator.ImageType, content: con })
|
172
|
177
|
|
|
@@ -224,16 +229,24 @@ Page({
|
224
|
229
|
|
225
|
230
|
success: function (res) { //发送成功
|
226
|
231
|
|
|
232
|
+ var current_time = Date.now();
|
|
233
|
+ var _time = time.TimeFormatting(current_time); // 时间格式化
|
|
234
|
+ // console.log(_time);
|
|
235
|
+
|
227
|
236
|
// 我跟他人说话
|
228
|
237
|
switch (msg.type) {
|
229
|
238
|
|
230
|
239
|
case "alone": // 发送文本
|
231
|
240
|
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
232
|
245
|
console.log(' 发送文本');
|
233
|
246
|
var obj = { //创建对象,用来合并历史消息对象
|
234
|
247
|
content: that.data.news, //发送消息内容
|
235
|
248
|
type: 1, //类型 1 : 文字类型 类型 2 : 图片
|
236
|
|
- time: Date.now(), //时间
|
|
249
|
+ time: _time, //时间
|
237
|
250
|
isMy: true, //自己
|
238
|
251
|
send: true, // 发送成功 为true 失败false
|
239
|
252
|
};
|
|
@@ -252,12 +265,13 @@ Page({
|
252
|
265
|
|
253
|
266
|
case "images": // 发送图片
|
254
|
267
|
|
|
268
|
+
|
255
|
269
|
console.log(' 发送图片');
|
256
|
270
|
|
257
|
271
|
var obj = { //创建对象,用来合并历史消息对象
|
258
|
272
|
content: that.data.photo, //发送消息内容
|
259
|
273
|
type: 2, //类型 1 : 文字类型 类型 2 : 图片
|
260
|
|
- time: Date.now(), //时间
|
|
274
|
+ time: _time, //时间
|
261
|
275
|
isMy: true, //自己
|
262
|
276
|
send: true, // 发送成功 为true 失败false
|
263
|
277
|
};
|
|
@@ -293,27 +307,48 @@ Page({
|
293
|
307
|
// 接收消息
|
294
|
308
|
onSocketMessageCallback: function (e) {
|
295
|
309
|
var that = this;
|
296
|
|
- let data = JSON.parse(e);
|
|
310
|
+ let data = JSON.parse(e);
|
297
|
311
|
|
298
|
|
- // console.log(data,'接受消息成功');
|
|
312
|
+ console.log(data,'接受消息成功');
|
299
|
313
|
|
300
|
|
- var arrData = data.data;
|
|
314
|
+ var arrData = data.data.data;
|
301
|
315
|
|
|
316
|
+
|
302
|
317
|
switch (data.type) {
|
303
|
318
|
// 接收历史消息
|
304
|
319
|
case "get_history":
|
305
|
320
|
// console.log(arrData,111112222);
|
306
|
321
|
|
|
322
|
+ var _code = data.code;
|
|
323
|
+
|
|
324
|
+ if (_code == 201){
|
|
325
|
+
|
307
|
326
|
// let total = arrData.length - 1;
|
308
|
327
|
// console.log(total);
|
|
328
|
+
|
|
329
|
+ // var vasd = time.TimeFormatting(1561186210);
|
|
330
|
+ // console.log(vasd)
|
|
331
|
+
|
|
332
|
+ console.log(arrData);
|
|
333
|
+
|
309
|
334
|
for (var index in arrData) { //二次赋值
|
310
|
335
|
if (arrData[index].form_id == getApp().UserToken()) { //判断 如果等于自己 true ,等于他人 false。
|
311
|
336
|
arrData[index].isMy = true; //自己
|
312
|
337
|
} else {
|
313
|
338
|
arrData[index].isMy = false; //他人
|
314
|
339
|
}
|
315
|
|
-
|
316
|
|
- that.ArrMsg.push(arrData[index]); //每次接到的数据拼接
|
|
340
|
+
|
|
341
|
+ if (arrData[index].type == 2){
|
|
342
|
+ arrData[index].content = data.data.url + arrData[index].content + data.data.stylename;
|
|
343
|
+ }
|
|
344
|
+
|
|
345
|
+ if (arrData[index].create_at){
|
|
346
|
+ var _time = time.TimeFormatting(arrData[index].create_at); // 时间格式化
|
|
347
|
+ arrData[index].time = _time; //时间从新赋值
|
|
348
|
+ }
|
|
349
|
+
|
|
350
|
+ that.ArrMsg.push(arrData[index]);
|
|
351
|
+
|
317
|
352
|
}
|
318
|
353
|
|
319
|
354
|
for (var index in that.ArrMsg) { //二次赋值 把所有的数据 hooks参数 清空
|
|
@@ -329,10 +364,6 @@ Page({
|
329
|
364
|
|
330
|
365
|
console.log(Arrs1, 111112222);
|
331
|
366
|
|
332
|
|
- that.setData({
|
333
|
|
- hiddenName: true,
|
334
|
|
- });
|
335
|
|
-
|
336
|
367
|
|
337
|
368
|
if (that.data.limit_page == 1) { //判断 分页 1 的时候
|
338
|
369
|
that.setData({
|
|
@@ -347,22 +378,38 @@ Page({
|
347
|
378
|
toView: 'Stop' //开启锚点 赋值
|
348
|
379
|
});
|
349
|
380
|
}
|
350
|
|
-
|
351
|
|
-
|
|
381
|
+
|
352
|
382
|
that.setData({ //最后关闭锚点 方便每次进来 在开启 修复 描点会闪动
|
353
|
383
|
toView: false,
|
|
384
|
+ frequency: true,
|
|
385
|
+ hiddenName: true, //隐藏加载更多图片
|
354
|
386
|
});
|
355
|
|
-
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+ }else{
|
|
390
|
+ that.setData({
|
|
391
|
+ hiddenName: true, //隐藏加载更多图片
|
|
392
|
+ codedata: false //code 301
|
|
393
|
+ });
|
|
394
|
+
|
|
395
|
+ }
|
356
|
396
|
break;
|
357
|
397
|
|
358
|
398
|
|
359
|
399
|
case "alone": // 接收他人文本
|
360
|
|
- console.log(arrData, "aaasd");
|
|
400
|
+
|
|
401
|
+ var arrDatatext = data.data;
|
|
402
|
+ console.log(arrDatatext, "aaasd");
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+ var current_time = Date.now();
|
|
406
|
+ var _time = time.TimeFormatting(current_time); // 时间格式化
|
|
407
|
+ // console.log(_time);
|
361
|
408
|
|
362
|
409
|
var obj = { //创建对象,用来合并历史消息对象
|
363
|
|
- content: arrData.content, //发送消息内容
|
|
410
|
+ content: arrDatatext.content, //发送消息内容
|
364
|
411
|
type: 1, //类型 1 : 文字类型 类型 2 : 图片
|
365
|
|
- time: Date.now(), //时间
|
|
412
|
+ time: _time, //时间
|
366
|
413
|
isMy: false, //他人
|
367
|
414
|
};
|
368
|
415
|
|
|
@@ -378,13 +425,20 @@ Page({
|
378
|
425
|
break;
|
379
|
426
|
|
380
|
427
|
case "images": // 接收他人图片
|
381
|
|
- console.log(arrData, "接收图片");
|
|
428
|
+ var arrDataimg = data.data;
|
|
429
|
+
|
|
430
|
+ console.log(arrDataimg, "接收图片");
|
|
431
|
+
|
|
432
|
+ var current_time = Date.now();
|
|
433
|
+ var _time = time.TimeFormatting(current_time); // 时间格式化
|
|
434
|
+ // console.log(_time);
|
382
|
435
|
|
383
|
436
|
var obj = { //创建对象,用来合并历史消息对象
|
384
|
|
- content: arrData.content, //发送消息内容
|
|
437
|
+ content: arrDataimg.content, //发送消息内容
|
385
|
438
|
type: 2, //类型 1 : 文字类型 类型 2 : 图片
|
386
|
|
- time: Date.now(), //时间
|
|
439
|
+ time: _time, //时间
|
387
|
440
|
isMy: false, //他人
|
|
441
|
+
|
388
|
442
|
};
|
389
|
443
|
|
390
|
444
|
let _Receive_img = that.data.Receive_news;
|
|
@@ -472,18 +526,24 @@ Page({
|
472
|
526
|
var that = this;
|
473
|
527
|
// console.log(e,'加载')
|
474
|
528
|
|
475
|
|
- that.setData({ // 显示加载更多图片
|
476
|
|
- hiddenName:false,
|
477
|
|
- })
|
|
529
|
+ if (that.data.codedata == true){
|
|
530
|
+ that.setData({ // 显示加载更多图片
|
|
531
|
+ hiddenName: false,
|
|
532
|
+ })
|
|
533
|
+ }
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+ if (that.data.frequency == true){
|
478
|
537
|
|
479
|
|
- setTimeout(function () {
|
|
538
|
+ // setTimeout(function () {
|
480
|
539
|
that.setData({
|
481
|
|
- limit_page: that.data.limit_page * 1 + 1
|
|
540
|
+ limit_page: that.data.limit_page * 1 + 1,
|
|
541
|
+ frequency:false
|
482
|
542
|
})
|
483
|
543
|
console.log(that.data.limit_page * 1 + 1)
|
484
|
544
|
that.SocketSend({ type: 'get_history', page: that.data.limit_page,limit:10})
|
485
|
|
- }, 3000);
|
486
|
|
-
|
|
545
|
+ // }, 1000);
|
|
546
|
+ }
|
487
|
547
|
// console.log('执行')
|
488
|
548
|
},
|
489
|
549
|
|
|
@@ -515,7 +575,7 @@ Page({
|
515
|
575
|
menu: false,
|
516
|
576
|
KeyboardHeight: e.detail.height,
|
517
|
577
|
})
|
518
|
|
- console.log(e.detail.height);
|
|
578
|
+ // console.log(e.detail.height);
|
519
|
579
|
},
|
520
|
580
|
|
521
|
581
|
// 发送键切换
|