|
@@ -1,30 +1,71 @@
|
1
|
1
|
const app = getApp();
|
2
|
|
-
|
|
2
|
+const ImageType = 'images';
|
|
3
|
+const TextType = 'text';
|
3
|
4
|
Page({
|
4
|
5
|
|
5
|
6
|
|
6
|
7
|
* 页面的初始数据
|
7
|
8
|
*/
|
8
|
9
|
data: {
|
9
|
|
- focus: false,
|
10
|
|
-
|
|
10
|
+ scrollTopVal: 1,
|
11
|
11
|
menu: false,
|
12
|
|
- uploadImages: ["/image/smyz2.png","/image/smyz1.png"],
|
|
12
|
+ Expression: false,
|
|
13
|
+ Sendoutshow: false,
|
|
14
|
+ menushow: true,
|
|
15
|
+ _width:500,
|
|
16
|
+
|
13
|
17
|
news:'',
|
14
|
|
- inputValue: null,
|
15
|
|
-
|
16
|
|
- messages:'',
|
|
18
|
+ KeyboardHeight: 366.66666666666674,
|
|
19
|
+ ExpressionImg:'',
|
|
20
|
+ inputValue:'',
|
17
|
21
|
photo:'',
|
|
22
|
+
|
|
23
|
+ Receive_news:'',
|
|
24
|
+ UserToken:'',
|
|
25
|
+ limit_page:1,
|
|
26
|
+
|
|
27
|
+ myheadurl:'',
|
|
28
|
+ headUrl:'',
|
|
29
|
+
|
|
30
|
+ to_id:'',
|
|
31
|
+ form_id:'',
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+ connectemojiO: ['😊','😅','😲', '😭', '😂', '😄', '😩', '😞', '😵', '😒', '😍', '😤', '😜', '😝', '😋', '😘', '😚', '😷', '😳', '😃', '😆', '😁', '😢', '😨', '😠', '😣', '😌', '😖', '😔', '😰', '😱', '😪', '😏', '😓'],
|
|
35
|
+
|
18
|
36
|
},
|
19
|
37
|
|
20
|
38
|
|
21
|
39
|
onLoad: function (options) {
|
22
|
40
|
var that = this;
|
23
|
|
- console.log(options);
|
|
41
|
+
|
|
42
|
+ that.ArrMsg = [];
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
24
|
49
|
const friend = options;
|
25
|
|
- this.SocketSend({ to_id: friend.to_id, form_id: getApp().UserId(), type: 'get_history', page: this.data.limit_page });
|
26
|
50
|
|
|
51
|
+ that.setData({
|
|
52
|
+ to_id: friend.to_id,
|
|
53
|
+ UserToken: getApp().UserToken(),
|
|
54
|
+ myheadurl: options.myheadurl,
|
|
55
|
+ headUrl: options.headUrl,
|
|
56
|
+ })
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ this.SocketSend({
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+ type: 'get_history',
|
|
63
|
+ page: this.data.limit_page
|
|
64
|
+ });
|
27
|
65
|
getApp().Imsocket().onSocketMessageCallback = this.onSocketMessageCallback;
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
28
|
69
|
},
|
29
|
70
|
|
30
|
71
|
|
|
@@ -33,18 +74,35 @@ Page({
|
33
|
74
|
var that = this;
|
34
|
75
|
that.setData({
|
35
|
76
|
menu: false,
|
|
77
|
+ Expression: false,
|
36
|
78
|
})
|
37
|
79
|
},
|
38
|
80
|
|
|
81
|
+
|
39
|
82
|
|
40
|
83
|
chatInputExtraClickEvent:function(){
|
41
|
84
|
var that = this;
|
42
|
85
|
that.setData({
|
43
|
|
- menu: !that.data.menu
|
|
86
|
+ menu: !that.data.menu,
|
|
87
|
+ Expression: false,
|
44
|
88
|
})
|
45
|
89
|
},
|
46
|
90
|
|
47
|
91
|
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+ExpressionClickEvent: function () {
|
|
95
|
+ var that = this;
|
|
96
|
+ that.setData({
|
|
97
|
+ Expression: !that.data.Expression,
|
|
98
|
+ menu: false,
|
|
99
|
+ })
|
|
100
|
+ },
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
48
|
106
|
|
49
|
107
|
enlarge: function (e) {
|
50
|
108
|
var that = this;
|
|
@@ -52,7 +110,7 @@ Page({
|
52
|
110
|
|
53
|
111
|
wx.previewImage({
|
54
|
112
|
current: e.currentTarget.dataset.src,
|
55
|
|
- urls: that.data.uploadImages,
|
|
113
|
+ urls: [e.currentTarget.dataset.src],
|
56
|
114
|
})
|
57
|
115
|
|
58
|
116
|
|
|
@@ -60,32 +118,20 @@ Page({
|
60
|
118
|
|
61
|
119
|
|
62
|
120
|
|
63
|
|
-
|
64
|
|
- Sendout: function (e) {
|
65
|
|
- var that = this;
|
66
|
|
- console.log(that.data.news);
|
67
|
|
-
|
68
|
|
- that.setData({
|
69
|
|
- menu: false,
|
70
|
|
- inputValue: '',
|
71
|
|
- messages: that.data.news,
|
72
|
|
- })
|
73
|
|
- console.log('发送');
|
74
|
|
-
|
75
|
|
- },
|
76
|
|
-
|
77
|
|
-
|
|
121
|
+
|
78
|
122
|
Telephone: function (e) {
|
79
|
123
|
var that = this;
|
80
|
|
-
|
81
|
|
-
|
|
124
|
+ console.log(e.detail.value);
|
82
|
125
|
that.setData({
|
83
|
126
|
news: e.detail.value,
|
84
|
127
|
})
|
|
128
|
+
|
85
|
129
|
|
|
130
|
+ that.Sendoutswitch(e.detail.value);
|
86
|
131
|
},
|
87
|
132
|
|
88
|
133
|
|
|
134
|
+
|
89
|
135
|
|
90
|
136
|
chooseImageTap: function () {
|
91
|
137
|
var that = this;
|
|
@@ -95,18 +141,52 @@ Page({
|
95
|
141
|
sourceType: ['album', 'camera'],
|
96
|
142
|
success(res) {
|
97
|
143
|
|
|
144
|
+ wx.uploadFile({
|
|
145
|
+ url: getApp().globalData.url + 'imsocket/images/chatimg',
|
|
146
|
+ filePath: res.tempFilePaths[0],
|
|
147
|
+ name: 'photo',
|
|
148
|
+ formData: {
|
|
149
|
+ key: wx.getStorageSync('access_key'),
|
|
150
|
+ token: wx.getStorageSync('access_token')
|
|
151
|
+ },
|
|
152
|
+ success: function (res) {
|
|
153
|
+ var data = JSON.parse(res.data);
|
|
154
|
+
|
|
155
|
+ console.log(data, '图片上传成功');
|
|
156
|
+
|
|
157
|
+ if (data.code == 201) {
|
|
158
|
+ let con = data.data;
|
|
159
|
+
|
|
160
|
+ console.log(con, 1);
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+ that.SocketSend({type: ImageType, content: con});
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+ } else if (data.code == 301) {
|
|
168
|
+ wx.showModal({
|
|
169
|
+ title: '提示',
|
|
170
|
+ content: data.msg,
|
|
171
|
+ showCancel: false,
|
|
172
|
+ })
|
|
173
|
+ }
|
|
174
|
+ }, fail: function (d) {
|
|
175
|
+ }
|
|
176
|
+ })
|
98
|
177
|
console.log(res.tempFilePaths[0]);
|
99
|
178
|
|
100
|
179
|
that.setData({
|
101
|
180
|
photo: res.tempFilePaths[0],
|
|
181
|
+ menu: false,
|
102
|
182
|
});
|
103
|
183
|
|
104
|
184
|
}
|
105
|
185
|
})
|
106
|
|
-
|
107
|
|
-
|
108
|
186
|
},
|
109
|
187
|
|
|
188
|
+
|
|
189
|
+
|
110
|
190
|
|
111
|
191
|
retransmission:function(){
|
112
|
192
|
wx.showModal({
|
|
@@ -119,30 +199,305 @@ Page({
|
119
|
199
|
}
|
120
|
200
|
}
|
121
|
201
|
})
|
122
|
|
-
|
123
|
202
|
},
|
124
|
|
- SocketSend: function (msg) {
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+ SocketSend: function (msg) {
|
|
208
|
+ var that =this;
|
|
209
|
+ msg.form_id = getApp().UserId();
|
|
210
|
+ msg.to_id = that.data.to_id;
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
125
|
214
|
|
126
|
215
|
|
127
|
216
|
getApp().Imsocket().sendSocketMessage({
|
128
|
|
- msg: JSON.stringify(msg),
|
129
|
|
- success: function (res) {
|
|
217
|
+ msg: JSON.stringify(msg),
|
|
218
|
+
|
|
219
|
+ success: function (res) {
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+ switch(msg.type){
|
|
223
|
+
|
|
224
|
+ case "alone":
|
|
225
|
+
|
|
226
|
+ console.log(' 发送文本');
|
|
227
|
+ var obj = {
|
|
228
|
+ content: that.data.news,
|
|
229
|
+ type: 1,
|
|
230
|
+ time: Date.now(),
|
|
231
|
+ isMy: true,
|
|
232
|
+ send: true,
|
|
233
|
+ };
|
|
234
|
+ let _Receive_news = that.data.Receive_news;
|
|
235
|
+ _Receive_news.push(obj);
|
|
236
|
+
|
|
237
|
+ console.log(_Receive_news,'aaa');
|
|
238
|
+ that.setData({
|
|
239
|
+ Receive_news: _Receive_news,
|
|
240
|
+ });
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+ that.scrollbar(_Receive_news);
|
|
244
|
+
|
|
245
|
+ break;
|
|
246
|
+
|
|
247
|
+ case "images":
|
|
248
|
+
|
|
249
|
+ console.log(' 发送图片');
|
|
250
|
+
|
|
251
|
+ var obj = {
|
|
252
|
+ content: that.data.photo,
|
|
253
|
+ type: 2,
|
|
254
|
+ time: Date.now(),
|
|
255
|
+ isMy: true,
|
|
256
|
+ send: true,
|
|
257
|
+ };
|
|
258
|
+ let _Receive_img = that.data.Receive_news;
|
|
259
|
+ _Receive_img.push(obj);
|
|
260
|
+
|
|
261
|
+ console.log(_Receive_img, '发送图片');
|
|
262
|
+ that.setData({
|
|
263
|
+ Receive_news: _Receive_img,
|
|
264
|
+ });
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+ that.scrollbar(_Receive_img);
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+ break;
|
|
273
|
+ }
|
|
274
|
+
|
130
|
275
|
console.log(res, '获取历史消息成功');
|
131
|
|
- }, fail: function (res) {
|
|
276
|
+
|
|
277
|
+ }, fail: function (res) {
|
|
278
|
+
|
132
|
279
|
console.log('获取历史消息失败')
|
|
280
|
+
|
133
|
281
|
}
|
134
|
282
|
})
|
|
283
|
+
|
135
|
284
|
},
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
136
|
288
|
onSocketMessageCallback: function (e) {
|
|
289
|
+ var that = this;
|
137
|
290
|
let data = JSON.parse(e);
|
138
|
|
-
|
139
|
|
- console.log(data,'接受消息成功');
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+ var arrData = data.data;
|
|
295
|
+
|
|
296
|
+ switch(data.type){
|
|
297
|
+
|
|
298
|
+ case "get_history":
|
|
299
|
+
|
|
300
|
+ for (var index in arrData) {
|
|
301
|
+ if (arrData[index].form_id == getApp().UserToken()) {
|
|
302
|
+ arrData[index].isMy = true;
|
|
303
|
+ }else{
|
|
304
|
+ arrData[index].isMy = false;
|
|
305
|
+ }
|
|
306
|
+ that.ArrMsg.push(arrData[index]);
|
|
307
|
+ }
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+ var scrollTopValLength = "";
|
|
311
|
+ if (that.data.limit_page == 1) {
|
|
312
|
+ scrollTopValLength = arrData.length * 999
|
|
313
|
+ } else {
|
|
314
|
+ scrollTopValLength = arrData.length * 100
|
|
315
|
+ }
|
|
316
|
+
|
|
317
|
+ console.log(that.ArrMsg, 111112222);
|
|
318
|
+ that.setData({
|
|
319
|
+ Receive_news: that.sortarr(that.ArrMsg),
|
|
320
|
+ scrollTopVal: scrollTopValLength,
|
|
321
|
+ });
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+ break;
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+ case "alone":
|
|
329
|
+ console.log(arrData,"aaasd");
|
|
330
|
+
|
|
331
|
+ var obj = {
|
|
332
|
+ content: arrData.content,
|
|
333
|
+ type: 1,
|
|
334
|
+ time: Date.now(),
|
|
335
|
+ isMy: false,
|
|
336
|
+ };
|
|
337
|
+
|
|
338
|
+ let _Receive_news = that.data.Receive_news;
|
|
339
|
+ _Receive_news.push(obj);
|
|
340
|
+
|
|
341
|
+ that.setData({
|
|
342
|
+ Receive_news: _Receive_news,
|
|
343
|
+ });
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+ that.scrollbar(_Receive_news);
|
|
347
|
+ break;
|
|
348
|
+
|
|
349
|
+ case "images":
|
|
350
|
+ console.log(arrData, "接收图片");
|
|
351
|
+
|
|
352
|
+ var obj = {
|
|
353
|
+ content: arrData.content,
|
|
354
|
+ type: 2,
|
|
355
|
+ time: Date.now(),
|
|
356
|
+ isMy: false,
|
|
357
|
+ };
|
|
358
|
+
|
|
359
|
+ let _Receive_img = that.data.Receive_news;
|
|
360
|
+ _Receive_img.push(obj);
|
|
361
|
+
|
|
362
|
+ that.setData({
|
|
363
|
+ Receive_news: _Receive_img,
|
|
364
|
+ });
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+ that.scrollbar(_Receive_img);
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+ break;
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+ }
|
|
375
|
+
|
|
376
|
+
|
140
|
377
|
|
141
|
378
|
},
|
142
|
379
|
|
|
380
|
+
|
|
381
|
+ scrollbar: function (data) {
|
|
382
|
+ var that =this;
|
|
383
|
+ if(data){
|
|
384
|
+ let lengNum = data.length;
|
|
385
|
+
|
143
|
386
|
|
|
387
|
+ that.setData({
|
|
388
|
+ scrollTopVal: lengNum * 999
|
|
389
|
+ })
|
|
390
|
+ console.log(lengNum * 999);
|
|
391
|
+ }
|
144
|
392
|
|
|
393
|
+ },
|
145
|
394
|
|
|
395
|
+
|
|
396
|
+ Sendout: function (e) {
|
|
397
|
+ var that = this;
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+ let msg = {
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+ type: 'alone',
|
|
404
|
+ content: that.data.news
|
|
405
|
+ };
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+ this.SocketSend(msg);
|
|
409
|
+
|
|
410
|
+ that.setData({
|
|
411
|
+ menu: false,
|
|
412
|
+ Expression: false,
|
|
413
|
+ inputValue: '',
|
|
414
|
+ news: '',
|
|
415
|
+ })
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+ that.Sendoutswitch(that.data.news)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+ },
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+ sortarr: function (arr) {
|
|
426
|
+ for (let i = 0; i < arr.length - 1; i++) {
|
|
427
|
+ for (let j = 0; j < arr.length - 1 - i; j++) {
|
|
428
|
+ if (arr[j].create_at > arr[j + 1].create_at) {
|
|
429
|
+ var temp = arr[j];
|
|
430
|
+ arr[j] = arr[j + 1];
|
|
431
|
+ arr[j + 1] = temp;
|
|
432
|
+ }
|
|
433
|
+ }
|
|
434
|
+ }
|
|
435
|
+ return arr;
|
|
436
|
+ },
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+ upper: function (e) {
|
|
440
|
+
|
|
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 })
|
146
|
448
|
|
147
|
449
|
|
|
450
|
+ },
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+ Expression:function(e){
|
|
455
|
+ var that = this;
|
|
456
|
+
|
|
457
|
+ var _news = that.data.news;
|
|
458
|
+ var _text = _news + e.currentTarget.dataset.id;
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+ console.log(that.data.news)
|
|
462
|
+ console.log(_text)
|
|
463
|
+ that.setData({
|
|
464
|
+ news: _text,
|
|
465
|
+ inputValue: _text,
|
|
466
|
+ })
|
|
467
|
+
|
|
468
|
+ that.Sendoutswitch(that.data.news)
|
|
469
|
+ },
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+ bindfocusclick: function(e) {
|
|
474
|
+ var that = this;
|
|
475
|
+ that.setData({
|
|
476
|
+ Expression: false,
|
|
477
|
+ menu: false,
|
|
478
|
+ KeyboardHeight: e.detail.height,
|
|
479
|
+ })
|
|
480
|
+ console.log(e.detail.height);
|
|
481
|
+ },
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+ Sendoutswitch: function (data) {
|
|
485
|
+ var that = this;
|
|
486
|
+ if (data == '') {
|
|
487
|
+ that.setData({
|
|
488
|
+ menushow: true,
|
|
489
|
+ Sendoutshow: false,
|
|
490
|
+ _width: 500,
|
|
491
|
+ })
|
|
492
|
+ } else {
|
|
493
|
+ that.setData({
|
|
494
|
+ menushow: false,
|
|
495
|
+ Sendoutshow: true,
|
|
496
|
+ _width: 447,
|
|
497
|
+ })
|
|
498
|
+ }
|
|
499
|
+ },
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
148
|
503
|
})
|