luyanan 7 years ago
parent
commit
0edeb64a1d
5 changed files with 199 additions and 160 deletions
  1. 13 43
      app/html/weChat.html
  2. 19 10
      app/index.html
  3. 144 105
      app/js/consultlistNew.js
  4. 2 1
      app/js/login.js
  5. 21 1
      app/js/public/base.js

+ 13 - 43
app/html/weChat.html

@ -415,11 +415,19 @@
415 415
						drag: true, //默认为true
416 416
						hold: true, //默认为false,不监听
417 417
						release: true //默认为false,不监听
418
					},
419
					beforeback:function() {
420
						var web3 = plus.webview.getWebviewById("consultlistNew.html");
421
						mui.fire(web3, "newId");
422
						return true;
418 423
					}
419 424
				});
420 425
				template.config('escape', false);
421 426
				//$.plusReady=function(fn){fn();};
422 427
				$.plusReady(function() {
428
					if($.os.ios) {
429
						 toNum();
430
				}
423 431
					plus.webview.currentWebview().setStyle({
424 432
						softinputMode: "adjustResize"
425 433
					});
@ -458,8 +466,6 @@
458 466
						}
459 467
					};
460 468
					document.getElementById("backBtn").addEventListener("tap", function() {
461
						var web3 = plus.webview.getWebviewById("consultlistNew.html");
462
						mui.fire(web3, "newId");
463 469
						var web4 = plus.webview.getLaunchWebview();
464 470
						mui.fire(web4, "newId", {
465 471
							rd: 3
@ -469,47 +475,8 @@
469 475
					var record = []; //消息数组
470 476
					messageList();
471 477
					pe();
472
					if(mui.os.ios) {
473
						totalNum();
474
					}
475
					function sendJava(num) {
476
						var infor=plus.push.getClientInfo();
477
						mui.ajax(baseUrl + '/ajax/webMsg/applyBadge', {
478
							"data": {
479
								badge:num,
480
								cid:infor.clientid,
481
								devtoken :infor.token
482
							},
483
							"type": "get",
484
							"async": true,
485
							"context": this,
486
							"success": function(data) {
487
								if(data.success) {
488
								}
489
							},
490
							"error": function() {
491
								plus.nativeUI.toast("服务器链接超时", toastStyle);
492
							}
493
						});
494
					}
495
					function totalNum() {
496
						mui.ajax(baseUrl + '/ajax/webMsg/unReadedCount', {
497
							"data": {
498
								id: plus.storage.getItem('userid')
499
							},
500
							"type": "get",
501
							"async": true,
502
							"context": this,
503
							"success": function(data) {
504
								if(data.success) {	
505
									sendJava(data.data);
506
								}
507
							},
508
							"error": function() {
509
								plus.nativeUI.toast("服务器链接超时", toastStyle);
510
							}
511
						});
512
					}
478
					
479
					
513 480

514 481
					function pe() {
515 482
						mui.ajax(baseUrl + '/ajax/professor/baseInfo/' + professorId, {
@ -664,6 +631,9 @@
664 631
							timeGe: time1
665 632
						})
666 633
						bindMsgList();
634
//						if($.os.ios) {
635
//						 toNum();
636
//						}
667 637
					})
668 638
					var toRobot = function(info) {
669 639
						var apiUrl = 'http://www.tuling123.com/openapi/api';

+ 19 - 10
app/index.html

@ -54,9 +54,12 @@
54 54
			self.append(sub);
55 55
		}
56 56
		client1()
57
 		if(mui.os.ios) {
57
 		
58
if(mui.os.ios) {
58 59
 			plus.push.addEventListener("click", function(msg) {
60
 				
59 61
 				//plus.push.clear();
62
 				toNum()
60 63
 				plus.webview.getLaunchWebview().show();
61 64
 				plus.webview.getWebviewById("html/consult_home.html").show();
62 65
 				mui(".mui-tab-item").each(function(index) {
@ -67,10 +70,13 @@
67 70
 					}
68 71
 				})
69 72
 			});
73
 			plus.push.addEventListener("receive", function(msg) {
74
 				//alert(msg)
75
 			})
70 76
 		} else {
71 77

72 78
 			plus.push.addEventListener("receive", function(msg) {
73
 				//plus.push.clear();
79
 				plus.push.clear();
74 80
 				plus.webview.getLaunchWebview().show();
75 81
 				plus.webview.getWebviewById("html/consult_home.html").show();
76 82
 				mui(".mui-tab-item").each(function(index) {
@ -87,14 +93,8 @@
87 93
				document.getElementById("meLInum").style.display="block"
88 94
				document.getElementById("meLInum").innerHTML=Number(document.getElementById("meLInum").innerHTML)+1;
89 95
			}else if(event.detail.rd==2) {
90
				var numtt=Number(document.getElementById("meLInum").innerHTML)-Number(event.detailct)
91
				if(numtt>0) {
92
					document.getElementById("meLInum").style.display="block";
93
					ocument.getElementById("meLInum").innerHTML=numtt;
94
				}else{
95 96
					document.getElementById("meLInum").style.display="none";
96 97
					ocument.getElementById("meLInum").innerHTML=0;
97
				}
98 98
			}else{
99 99
				totalNum();
100 100
			}
@ -103,16 +103,25 @@
103 103
		})
104 104
		totalNum()
105 105
		function totalNum() {
106
			var usid=plus.storage.getItem('userid');
107
			if(usid== null || usid == 'null') {
108
				
109
				document.getElementById("meLInum").style.display="none";
110
					document.getElementById("meLInum").innerHTML=0;
111
					return;
112
			}
106 113
			mui.ajax(baseUrl + '/ajax/webMsg/unReadedCount', {
107 114
						"data":{id:plus.storage.getItem('userid')},
108 115
						"type": "get",
109 116
						"async": true,
110 117
						"context": this,
111 118
						"success": function(data) {
112
							console.log(123);
113
							console.log(JSON.stringify(data))
114 119
							if(data.success) {
120
								plus.runtime.setBadgeNumber(data.data);
121
									 var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
122
            								GeTuiSdk.setBadge(data.data);
115 123
								if(data.data) {
124
									
116 125
									document.getElementById("meLInum").style.display="block"
117 126
									document.getElementById("meLInum").innerHTML=data.data;
118 127
								}else{

+ 144 - 105
app/js/consultlistNew.js

@ -8,20 +8,32 @@ mui.ready(function() {
8 8
			content1.style.display = 'none';
9 9
		} else {
10 10
			content2.style.display = 'none';
11
			messageList()
11
			messageList(true)
12 12
		}
13 13
		/*登陆*/
14 14
		window.addEventListener('logined', function(event) {
15
		 userid = event.detail.id;
15
			userid = event.detail.id;
16 16
			content1.style.display = 'block';
17 17
			content2.style.display = 'none';
18
			messageList()
18
			messageList(true);
19
			var web4 = plus.webview.getLaunchWebview();
20
			mui.fire(web4, "newId", {
21
				rd: 3
22
			});
23
			if(event.detail.rd) {
24
				websocket1();
25
			}
26
19 27
		});
20 28
		window.addEventListener('exited', function(event) {
21 29
			var userid = event.detail.id;
22 30
			content1.style.display = 'none';
23 31
			content2.style.display = 'block';
24 32
			document.getElementById('unlogin').style.display = 'block';
33
			var web4 = plus.webview.getLaunchWebview();
34
			mui.fire(web4, "newId", {
35
				rd: 2
36
			});
25 37
		});
26 38
		var regBtn = document.getElementById("regBtn");
27 39
		var logBtn = document.getElementById("logBtn");
@ -48,25 +60,112 @@ mui.ready(function() {
48 60
			});
49 61
50 62
		});
51
		var ws = new WebSocket("ws://192.168.3.233:8081/portal/websocket/msg?id=" + userid + "&pm=app");
52
		ws.onopen = function() {
53
			
54
		};
63
		websocket1()
64
65
		function websocket1() {
66
			var ws = new WebSocket("ws://192.168.3.233:8081/portal/websocket/msg?id=" + userid + "&pm=app");
67
			ws.onopen = function() {
68
69
			};
70
			ws.onmessage = function(a) {
71
				var fol = true;
72
				var $info = JSON.parse(a.data);
73
74
				var li = $("#consultList").find("li");
75
				var cf = 1;
76
				$.each(li, function() {
77
					var $id = $(this).attr("data-id");
78
79
					if($info.sender == $id) {
80
						$(this).attr("data-time", $info.sendTime)
81
						cf = 0;
82
						
83
84
						var web = plus.webview.getWebviewById("weChat.html");
85
86
						if(web) {
87
							if(web.professorId == $info.sender) {
88
								$(this).find('.thistime').text(commenTime($info.sendTime)).end().find(".h3Font").text($info.cnt);
89
								readed.call($(this), $id, $info.sendTime);
90
								mui.fire(web, "newId", {
91
									rd: $info.cnt,
92
									sendTime: $info.sendTime
93
								});
94
							} else {
95
								$(this).find(".icon-messagenew").show().end().find('.mui-badge').text(Number($(this).find(".mui-badge").text()) + 1).end().find('.thistime').text(commenTime($info.sendTime)).end().find(".h3Font").text($info.cnt);
96
								var web3 = plus.webview.getLaunchWebview();
97
								mui.fire(web3, "newId", {
98
									rd: 1
99
								});
100
								toNum();
101
							}
102
						} else {
103
							toNum();
104
							$(this).find(".icon-messagenew").show().end().find('.mui-badge').text(Number($(this).find(".mui-badge").text()) + 1).end().find('.thistime').text(commenTime($info.sendTime)).end().find(".h3Font").text($info.cnt);
105
							var web3 = plus.webview.getLaunchWebview();
106
							mui.fire(web3, "newId", {
107
								rd: 1
108
							});
109
110
						}
111
						if($(this).index() != 0) {
112
							$(this).remove().clone().prependTo($('#consultList'));
113
						}
114
					}
115
				})
116
117
				if(cf) {
118
119
					var str1 = '<li class="mui-table-view-cell" data-id="' + $info.sender + '" data-time="' + $info.sendTime + '">' +
120
						'<div class="mui-slider-handle"><div class="madiaHead useHead" style="background-image:url(../images/default-photo.jpg)"><span class="mui-icon  icon-messagenew"><span class="mui-badge">1</span></span></div>' +
121
						'<div class="madiaInfo">' +
122
						'<div class="h1Font mui-ellipsis">' +
123
						'<span class="userName"></span>' +
124
						'<span class="authicon "></span>' +
125
						'<span class="thistime">' + commenTime($info.sendTime) + '</span>' +
126
						'</div>' +
127
						'<div class="h3Font mui-ellipsis">' + $info.cnt + '</div>' +
128
						'</div></div><div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red">删除</a></div>' +
129
						'</li>'
130
					var $info1 = $(str1)
131
					$("#consultList").prepend($info1);
132
					var web1 = plus.webview.getWebviewById("weChat.html");
133
					if(web1) {
134
						if(web1.professorId == $info.sender) {
135
							mui.fire(web1, "newId", {
136
								rd: $info.cnt,
137
								sendTime: $info.sendTime
138
							});
139
							readed.call($info1, $info.sender, $info.sendTime);
140
						}
141
					}
142
					userInformation($info.sender, $info1)
143
					var web3 = plus.webview.getLaunchWebview();
144
							mui.fire(web3, "newId", {
145
								rd: 1
146
							});
147
				}
148
			}
149
			ws.onclose = function() {
150
151
			}
152
		}
55 153
		window.addEventListener("newId", function(event) {
56
			messageList();
154
			messageList(false);
57 155
		})
58 156
59
		function messageList() {
157
		function messageList(bole) {
60 158
			mui.ajax(baseUrl + '/ajax/webMsg/idx/qm', {
61 159
				data: {
62 160
					"id": userid
63 161
				},
162
				async: bole,
64 163
				dataType: 'json', //服务器返回json格式数据
65 164
				type: 'GET', //HTTP请求类型
66 165
				timeout: 10000, //超时时间设置为10秒;
67 166
				traditional: true, //传数组必须加这个
68 167
				success: function(data) {
69
					
168
70 169
					if(data.success) {
71 170
						$("#consultList").html("");
72 171
						var $data = data.data;
@ -103,18 +202,22 @@ mui.ready(function() {
103 202
			var elem = this;
104 203
			var li = elem.parentNode.parentNode;
105 204
			mui.confirm('确认删除该会话?', btnArray, function(e) {
106
				if(e.index == 1) {
205
				if(e.index == 0) {
107 206
					mui.ajax(baseUrl + '/ajax/webMsg/disable/show', {
108 207
						"type": "post",
109 208
						"async": true,
110 209
						"data": {
111
							owner:userid,
112
							actor:li.getAttribute("data-id")
210
							owner: userid,
211
							actor: li.getAttribute("data-id")
113 212
						},
114 213
						"context": this,
115 214
						"success": function(data) {
116 215
							if(data.success) {
117 216
								li.parentNode.removeChild(li);
217
								var web3 = plus.webview.getLaunchWebview();
218
							mui.fire(web3, "newId", {
219
								rd: 3
220
							});
118 221
							}
119 222
						},
120 223
						"error": function() {
@ -135,7 +238,7 @@ mui.ready(function() {
135 238
				"type": "get",
136 239
				"async": true,
137 240
				"success": function(data) {
138
					
241
139 242
					if(data.success && data.data) {
140 243
						$itemlist.find(".userName").text(data.data.name);
141 244
						if(data.data.hasHeadImage == 1) {
@ -150,105 +253,30 @@ mui.ready(function() {
150 253
				}
151 254
			});
152 255
		}
153
		ws.onmessage = function(a) {
154
			var fol = true;
155
			var $info = JSON.parse(a.data);
156
			
157
			var li = $("#consultList").find("li");
158
			var cf = 1;
159
			$.each(li, function() {
160
				var $id = $(this).attr("data-id");
161
				if($info.sender == $id) {
162
					cf = 0;
163
					if($(this).index() != 0) {
164
						$(this).remove().clone().prependTo($('#consultList'));
165
					}
166 256
167
					var web = plus.webview.getWebviewById("weChat.html");
168
169
					if(web) {
170
						if(web.professorId == $info.sender) {
171
							$(this).find('.thistime').text(commenTime($info.sendTime)).end().find(".h3Font").text($info.cnt);
172
							readed.call($(this), $id, $info.sendTime);
173
							mui.fire(web, "newId", {
174
								rd: $info.cnt,
175
								sendTime: $info.sendTime
176
							});
177
						} else {
178
							$(this).find(".icon-messagenew").show().end().find('.mui-badge').text(Number($(this).find(".mui-badge").text()) + 1).end().find('.thistime').text(commenTime($info.sendTime)).end().find(".h3Font").text($info.cnt);
179
							var web3=plus.webview.getLaunchWebview();
180
							mui.fire(web3, "newId", {
181
								rd: 1
182
							});
183
						}
184
					} else {
185
						$(this).find(".icon-messagenew").show().end().find('.mui-badge').text(Number($(this).find(".mui-badge").text()) + 1).end().find('.thistime').text(commenTime($info.sendTime)).end().find(".h3Font").text($info.cnt);
186
						var web3=plus.webview.getLaunchWebview();
187
							mui.fire(web3, "newId", {
188
								rd: 1
189
							});
190
					}
191
192
				}
193
			})
194
195
			if(cf) {
196
197
				var str1 = '<li class="mui-table-view-cell" data-id="' + $info.sender + '" data-time="' + $info.sendTime + '">' +
198
					'<div class="mui-slider-handle"><div class="madiaHead useHead" style="background-image:url(../images/default-photo.jpg)"><span class="mui-icon  icon-messagenew"><span class="mui-badge">1</span></span></div>' +
199
					'<div class="madiaInfo">' +
200
					'<div class="h1Font mui-ellipsis">' +
201
					'<span class="userName"></span>' +
202
					'<span class="authicon "></span>' +
203
					'<span class="thistime">' + commenTime($info.sendTime) + '</span>' +
204
					'</div>' +
205
					'<div class="h3Font mui-ellipsis">' + $info.cnt + '</div>' +
206
					'</div></div><div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red">删除</a></div>' +
207
					'</li>'
208
				var $info1 = $(str1)
209
				$("#consultList").prepend($info1);
210
				var web1 = plus.webview.getWebviewById("weChat.html");
211
				if(web1.professorId == $info.sender) {
212
					mui.fire(web1, "newId", {
213
						rd: $info.cnt,
214
						sendTime: $info.sendTime
215
					});
216
					readed.call($info1, $info.sender, $info.sendTime);
217
				}
218
				userInformation($info.sender, $info1)
219
220
			}
221
		}
222
		ws.onclose = function() {
223
224
		}
225 257
		mui("#consultList").on("tap", "li", function() {
226 258
			var opId = this.getAttribute("data-id");
227
			var oTimeStr = this.getAttribute("data-time") //
228
			if($(this).find(".icon-messagenew").css("display") == "block") {
229
				
230
				var web3=plus.webview.getLaunchWebview();
231
							mui.fire(web3, "newId", {
232
								rd: 2,
233
								ct:$(this).find(".mui-badge").text()
234
							});
259
			var oTimeStr = this.getAttribute("data-time");
260
			console.log($(this).find(".icon-messagenew").css("display"))
261
			if($(this).find(".icon-messagenew").css("display") == "block" || $(this).find(".icon-messagenew").css("display") == "inline-block") {
235 262
				readed.call($(this), opId, oTimeStr);
263
			} else {
264
				mui.openWindow({
265
					url: '../html/weChat.html',
266
					id: 'weChat.html',
267
					show: {
268
						autoShow: true,
269
						aniShow: "slide-in-right",
270
					},
271
					extras: {
272
						professorId: opId
273
					}
274
				})
236 275
			}
237
			mui.openWindow({
238
				url: '../html/weChat.html',
239
				id: 'weChat.html',
240
				show: {
241
					autoShow: true,
242
					aniShow: "slide-in-right",
243
				},
244
				extras: {
245
					professorId: opId
246
				}
247
			})
276
248 277
		})
249 278
		//消息制为已读
250 279
		function readed(pId, timeStr) {
251
			//alert(1)
252 280
			mui.ajax(baseUrl + '/ajax/webMsg/readed', {
253 281
				"type": "post",
254 282
				"async": true,
@ -261,6 +289,17 @@ mui.ready(function() {
261 289
				"success": function(data) {
262 290
					if(data.success) {
263 291
						this.find(".icon-messagenew").hide().end().find(".mui-badge").text(0);
292
						mui.openWindow({
293
							url: '../html/weChat.html',
294
							id: 'weChat.html',
295
							show: {
296
								autoShow: true,
297
								aniShow: "slide-in-right",
298
							},
299
							extras: {
300
								professorId: pId
301
							}
302
						})
264 303
					}
265 304
				},
266 305
				"error": function() {

+ 2 - 1
app/js/login.js

@ -122,7 +122,8 @@ mui.ready(function() {
122 122
						
123 123
						var consultPage = plus.webview.getWebviewById('consultlistNew.html');
124 124
						mui.fire(consultPage, 'logined', {
125
							id: userId
125
							id: userId,
126
							rd:1
126 127
						});	
127 128
					} else {
128 129
						plus.nativeUI.toast("帐号和密码不匹配,请检查后重试", toastStyle);

+ 21 - 1
app/js/public/base.js

@ -511,4 +511,24 @@ function client1() {
511 511
		}
512 512
	});
513 513

514
}
514
}
515
 function toNum() {
516
						mui.ajax(baseUrl + '/ajax/webMsg/unReadedCount', {
517
							"data": {
518
								id: plus.storage.getItem('userid')
519
							},
520
							"type": "get",
521
							"async": true,
522
							"context": this,
523
							"success": function(data) {
524
								if(data.success) {	
525
									plus.runtime.setBadgeNumber(data.data);
526
									 var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
527
            								GeTuiSdk.setBadge(data.data);
528
								}
529
							},
530
							"error": function() {
531
								plus.nativeUI.toast("服务器链接超时", toastStyle);
532
							}
533
						});
534
					}