Authored by 李奇

代码优化

@@ -29,7 +29,7 @@ const getClientData = (type, encryptedUid, imgSize) => { @@ -29,7 +29,7 @@ const getClientData = (type, encryptedUid, imgSize) => {
29 .then(res => { 29 .then(res => {
30 let history = res[1].data; 30 let history = res[1].data;
31 let hasHistory = history && history.length > 0 || false; 31 let hasHistory = history && history.length > 0 || false;
32 - let csSetting = res[0].data.config; 32 + let csSetting = res[0].data && res[0].data.config;
33 33
34 csSetting.windowLogo = csSetting.windowLogo.replace(regExp, logoSize); 34 csSetting.windowLogo = csSetting.windowLogo.replace(regExp, logoSize);
35 csSetting.qrCode = csSetting.qrCode.replace(regExp, qcSize); 35 csSetting.qrCode = csSetting.qrCode.replace(regExp, qcSize);
@@ -29,13 +29,9 @@ module.exports = { @@ -29,13 +29,9 @@ module.exports = {
29 29
30 search: 'http://192.168.102.216:8080/yohosearch/', 30 search: 'http://192.168.102.216:8080/yohosearch/',
31 31
32 - // imSocket: 'ws://socket.yohobuy.com:10240',  
33 - // imCs: 'http://im.yohobuy.com/api',  
34 - // imServer: 'http://im.yohobuy.com/server'  
35 -  
36 - imSocket: 'ws://imsocket.yohobuy.com:10000',  
37 - imCs: 'http://imhttp.yohobuy.com/api',  
38 - imServer: 'http://imhttp.yohobuy.com/server' 32 + imSocket: 'ws://socket.yohobuy.com:10240',
  33 + imCs: 'http://im.yohobuy.com/api',
  34 + imServer: 'http://im.yohobuy.com/server'
39 }, 35 },
40 subDomains: { 36 subDomains: {
41 host: '.yohobuy.com', 37 host: '.yohobuy.com',
  1 +<div class="list-item guest">
  2 + <img src="{{csHead}}" class="avatar">
  3 + <div class="item-detail">
  4 + <span class="time">{{csName}} {{sendTimeShort}}</span>
  5 + <div class="msg-bubble">
  6 + <div>{{{newContent}}}</div>
  7 + </div>
  8 + </div>
  9 +</div>
  1 +<div class="list-item host">
  2 + <img src="{{userHead}}" class="avatar">
  3 + <div class="item-detail">
  4 + <span class="time">{{userName}} {{sendTimeShort}}</span>
  5 + <div class="msg-bubble">
  6 + <div>{{{newContent}}}</div>
  7 + </div>
  8 + </div>
  9 +</div>
  1 +{{#if isDouble}}
  2 + <div class="dis-row">
  3 + <span class="type" data-id="{{id1}}" data-content="{{id1Content}}">
  4 + {{id1Content}}
  5 + </span>
  6 + <span class="type" data-id="{{id2}}" data-content="{{id2Content}}">
  7 + {{id2Content}}
  8 + </span>
  9 + </div>
  10 +{{else}}
  11 + <div class="dis-row">
  12 + <span class="type" data-id="{{id}}" data-content="{{idContent}}">
  13 + {{idContent}}
  14 + </span>
  15 + </div>
  16 +{{/if}}
  1 +<div class="list-item guest">
  2 + <img src="{{assetsPrefix}}/img/service/robot-avatar.png" class="avatar">
  3 + <div class="item-detail">
  4 + <span class="time">{{csName}} {{sendTimeShort}}</span>
  5 + <div class="msg-bubble">
  6 + <div>{{{newContent}}}</div>
  7 + </div>
  8 + </div>
  9 +</div>
  1 +<div class="list-item">
  2 + <p class="push-tip">
  3 + <span class="tip">
  4 + {{{content}}}
  5 + </span>
  6 + </p>
  7 +</div>
@@ -26,6 +26,7 @@ var allRTs, @@ -26,6 +26,7 @@ var allRTs,
26 hasMore = true, 26 hasMore = true,
27 titleInterval, 27 titleInterval,
28 $html = $('html'), 28 $html = $('html'),
  29 + $window = $(window),
29 $document = $(document), 30 $document = $(document),
30 $msgList = $('.msg-list'), 31 $msgList = $('.msg-list'),
31 docTitle = document.title, 32 docTitle = document.title,
@@ -42,6 +43,12 @@ var allRTs, @@ -42,6 +43,12 @@ var allRTs,
42 $assetsPrefix = $('input[name=assetsPrefix]'), 43 $assetsPrefix = $('input[name=assetsPrefix]'),
43 $panelMainBody = $('.panel-main .main-body'); 44 $panelMainBody = $('.panel-main .main-body');
44 45
  46 +var tipTpl = require('hbs/service/tip.hbs'),
  47 + csTpl = require('hbs/service/cs-msg.hbs'),
  48 + cusTpl = require('hbs/service/cus-msg.hbs'),
  49 + robotTpl = require('hbs/service/robot-msg.hbs'),
  50 + disTpl = require('hbs/service/discontent-row.hbs');
  51 +
45 var processInfo = { 52 var processInfo = {
46 scrollLoad: false, 53 scrollLoad: false,
47 manual: false, 54 manual: false,
@@ -53,8 +60,8 @@ var key, @@ -53,8 +60,8 @@ var key,
53 urls = { 60 urls = {
54 makeEval: '/evalute/saveEvalute', 61 makeEval: '/evalute/saveEvalute',
55 leaveMsg: '/leavemessage/saveLeavemessage', 62 leaveMsg: '/leavemessage/saveLeavemessage',
56 - evalReason: '/evalute/queryReasonByConversationId',  
57 - msgHistory: '/conversationMessage/pageList' 63 + msgHistory: '/conversationMessage/pageList',
  64 + evalReason: '/evalute/queryReasonByConversationId'
58 }; 65 };
59 66
60 require('bootstrap'); 67 require('bootstrap');
@@ -99,25 +106,31 @@ function pageInit() { @@ -99,25 +106,31 @@ function pageInit() {
99 } 106 }
100 107
101 /** 108 /**
  109 + * 添加新的消息
  110 + */
  111 + function msgAppend(dom) {
  112 + $msgList.append(dom);
  113 + $panelMainBody.scrollTop($panelMainBody[0].scrollHeight);
  114 + }
  115 +
  116 + /**
102 * 表情设置 117 * 表情设置
103 * @param e 118 * @param e
104 */ 119 */
105 function setEmoji(e) { 120 function setEmoji(e) {
106 - var i,  
107 - len,  
108 - pos, 121 + var pos,
109 start, 122 start,
110 end, 123 end,
111 newVal, 124 newVal,
112 - emojiText,  
113 textDom, 125 textDom,
  126 + emojiText,
114 tag = $(e.target), 127 tag = $(e.target),
115 area = $('.msg-area'), 128 area = $('.msg-area'),
116 val = area.val(), 129 val = area.val(),
117 emojiId = tag.data('id'), 130 emojiId = tag.data('id'),
118 comp = $('.emoji-component'); 131 comp = $('.emoji-component');
119 132
120 - for (i = 0, len = emojiMap.length; i < len; i++) { 133 + for (var i = 0, len = emojiMap.length; i < len; i++) {
121 if (emojiMap[i].file === emojiId.toString()) { 134 if (emojiMap[i].file === emojiId.toString()) {
122 emojiText = emojiMap[i].text; 135 emojiText = emojiMap[i].text;
123 } 136 }
@@ -142,25 +155,17 @@ function pageInit() { @@ -142,25 +155,17 @@ function pageInit() {
142 155
143 /** 156 /**
144 * 系统通知 157 * 系统通知
145 - * @param type 通知类型  
146 - * @param msg 具体消息 158 + * @param tip 具体消息
147 */ 159 */
148 - function systemTip(type, msg) {  
149 - var tip, liHtml;  
150 -  
151 - var tipMap = {}; 160 + function systemTip(tip) {
  161 + var dom;
152 162
153 - if (type) {  
154 - tip = tipMap[type];  
155 - } else {  
156 - tip = msg;  
157 - }  
158 -  
159 - liHtml = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">' + tip + '</span>\n </p>\n </div>'; 163 + dom = tipTpl({
  164 + content: tip
  165 + });
160 166
161 // 添加消息 167 // 添加消息
162 - $msgList.append(liHtml);  
163 - $panelMainBody.scrollTop($panelMainBody[0].scrollHeight); 168 + msgAppend(dom);
164 } 169 }
165 170
166 /** 171 /**
@@ -186,7 +191,7 @@ function pageInit() { @@ -186,7 +191,7 @@ function pageInit() {
186 var $area = $('.msg-area'), 191 var $area = $('.msg-area'),
187 msg = $area.val().trim(); 192 msg = $area.val().trim();
188 193
189 - // 发送前共通处理清除计时器和title提示 194 + // 发送前共通处理
190 beforeSendMsg(); 195 beforeSendMsg();
191 196
192 if (!msgContent) { 197 if (!msgContent) {
@@ -260,7 +265,7 @@ function pageInit() { @@ -260,7 +265,7 @@ function pageInit() {
260 */ 265 */
261 function csChatting(message) { 266 function csChatting(message) {
262 // 系统通知 267 // 系统通知
263 - systemTip('', message.newContent); 268 + systemTip(message.newContent);
264 } 269 }
265 270
266 /** 271 /**
@@ -271,49 +276,35 @@ function pageInit() { @@ -271,49 +276,35 @@ function pageInit() {
271 socketChat.close(); 276 socketChat.close();
272 277
273 // 系统通知 278 // 系统通知
274 - systemTip('', message.content); 279 + systemTip(message.content);
275 } 280 }
276 281
277 /** 282 /**
278 * 留言 283 * 留言
279 */ 284 */
280 function leaveMsg() { 285 function leaveMsg() {
281 - var lMsg = $('#leaveMsg'),  
282 - txt = lMsg.find('textarea');  
283 -  
284 - lMsg.find('.leave-msg-tip').addClass('hide');  
285 - txt.val(''); 286 + var $lm = $('#leaveMsg'),
  287 + $ta = $lm.find('textarea');
286 288
287 - lMsg.modal({ 289 + $lm.find('.leave-msg-tip').addClass('hide');
  290 + $ta.val('');
  291 + $lm.modal({
288 show: true 292 show: true
289 }); 293 });
290 } 294 }
291 295
292 /** 296 /**
293 - *校验评价输入内容是否为空  
294 - */  
295 - $('#leaveMsg').find('textarea').bind('change', function() {  
296 - var lMsg = $('#leaveMsg'),  
297 - val = $(this).val();  
298 -  
299 - if (val === '') {  
300 - lMsg.find('.leave-msg-tip').removeClass('hide');  
301 - } else {  
302 - lMsg.find('.leave-msg-tip').addClass('hide');  
303 - }  
304 - });  
305 -  
306 - /**  
307 * 成功进入在线客服 297 * 成功进入在线客服
  298 + * @param message 消息对象
308 */ 299 */
309 function enterSuccess(message) { 300 function enterSuccess(message) {
310 - var $iconMs = $('.icon.manual-service'); 301 + var $ms = $('.icon.manual-service');
311 302
312 // 系统通知 303 // 系统通知
313 - systemTip('', message.content); 304 + systemTip(message.content);
314 305
315 - // 进入成功显示人工客服  
316 - $iconMs.show(); 306 + // 显示人工客服
  307 + $ms.show();
317 } 308 }
318 309
319 /** 310 /**
@@ -329,44 +320,53 @@ function pageInit() { @@ -329,44 +320,53 @@ function pageInit() {
329 MANUAL_SERVICE = 2, 320 MANUAL_SERVICE = 2,
330 ADMIN_MANUAL_SERVICE = 3; 321 ADMIN_MANUAL_SERVICE = 3;
331 322
332 - var liHtml, 323 + var dom,
  324 + tipText,
333 $iconEval = $('.icon.evaluate'), 325 $iconEval = $('.icon.evaluate'),
334 $iconMs = $('.icon.manual-service'); 326 $iconMs = $('.icon.manual-service');
335 327
336 switch (msgType) { 328 switch (msgType) {
337 329
338 - case OUT_SERVICE:  
339 - // 0是没上班  
340 - liHtml = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">' + message.content + '\u60A8\u4E5F\u53EF\u4EE5\u9009\u62E9<a class="leave-msg">\u7559\u8A00</a></span>\n </p>\n </div>'; 330 + case OUT_SERVICE: // 0是没上班
  331 + tipText = message.content +
  332 + '您也可以选择<a class="leave-msg">留言</a>';
  333 + dom = tipTpl({
  334 + content: tipText
  335 + });
341 break; 336 break;
342 337
343 - case LINE_UP:  
344 - // 1是需要排队  
345 - liHtml = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">\n ' + message.content + '\u60A8\u4E5F\u53EF\u4EE5\u9009\u62E9<a class="leave-msg">\u7559\u8A00</a>\uFF01\n </span>\n </p>\n </div>'; 338 + case LINE_UP: // 1是需要排队
  339 + tipText = message.content +
  340 + '您也可以选择<a class="leave-msg">留言</a>';
  341 + dom = tipTpl({
  342 + content: tipText
  343 + });
346 344
347 // 隐藏人工 345 // 隐藏人工
348 $iconMs.hide(); 346 $iconMs.hide();
349 break; 347 break;
350 348
351 - case MANUAL_SERVICE:  
352 - // 2是接入人工成功  
353 - liHtml = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">' + message.content + '</span>\n </p>\n </div>'; 349 + case MANUAL_SERVICE: // 2是接入人工成功
  350 + tipText = message.content;
  351 + dom = tipTpl({
  352 + content: tipText
  353 + });
354 354
355 // 接入人工客服需要评价 355 // 接入人工客服需要评价
356 processInfo.manual = true; 356 processInfo.manual = true;
357 -  
358 // 显示评价&隐藏人工 357 // 显示评价&隐藏人工
359 $iconEval.show(); 358 $iconEval.show();
360 $iconMs.hide(); 359 $iconMs.hide();
361 break; 360 break;
362 361
363 - case ADMIN_MANUAL_SERVICE:  
364 - // 3是管理员分配客服成功  
365 - liHtml = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">' + message.content + '</span>\n </p>\n </div>'; 362 + case ADMIN_MANUAL_SERVICE: // 3是管理员分配客服成功
  363 + tipText = message.content;
  364 + dom = tipTpl({
  365 + content: tipText
  366 + });
366 367
367 // 接入人工客服需要评价 368 // 接入人工客服需要评价
368 processInfo.manual = true; 369 processInfo.manual = true;
369 -  
370 // 显示评价&隐藏人工 370 // 显示评价&隐藏人工
371 $iconEval.show(); 371 $iconEval.show();
372 $iconMs.hide(); 372 $iconMs.hide();
@@ -377,8 +377,7 @@ function pageInit() { @@ -377,8 +377,7 @@ function pageInit() {
377 } 377 }
378 378
379 // 添加消息 379 // 添加消息
380 - liHtml && $msgList.append(liHtml);  
381 - liHtml && $panelMainBody.scrollTop($panelMainBody[0].scrollHeight); 380 + msgAppend(dom);
382 } 381 }
383 382
384 /** 383 /**
@@ -399,7 +398,7 @@ function pageInit() { @@ -399,7 +398,7 @@ function pageInit() {
399 * @private 398 * @private
400 */ 399 */
401 function handleCusMsg(rec, msgType, message) { 400 function handleCusMsg(rec, msgType, message) {
402 - var liHtml; 401 + var dom;
403 402
404 message.newContent = emojiPrefix(message.newContent); 403 message.newContent = emojiPrefix(message.newContent);
405 404
@@ -413,10 +412,14 @@ function pageInit() { @@ -413,10 +412,14 @@ function pageInit() {
413 message.newContent = '<img class="img-msg" src="' + message.content + '">'; 412 message.newContent = '<img class="img-msg" src="' + message.content + '">';
414 } 413 }
415 414
416 - liHtml = '<div class="list-item host">\n <img src="' + rec.userHead + '" class="avatar">\n <div class="item-detail">\n <span class="time">' + rec.userName + ' ' + rec.sendTimeShort + '</span>\n <div class="msg-bubble">\n <div>' + message.newContent + '</div>\n </div>\n </div>\n </div>'; 415 + dom = cusTpl({
  416 + userHead: rec.userHead,
  417 + userName: rec.userName,
  418 + sendTimeShort: rec.sendTimeShort,
  419 + newContent: message.newContent
  420 + });
417 421
418 - $msgList.append(liHtml);  
419 - $panelMainBody.scrollTop($panelMainBody[0].scrollHeight); 422 + msgAppend(dom);
420 } 423 }
421 424
422 /** 425 /**
@@ -424,12 +427,18 @@ function pageInit() { @@ -424,12 +427,18 @@ function pageInit() {
424 * @private 427 * @private
425 */ 428 */
426 function breakCountdown(message) { 429 function breakCountdown(message) {
427 - var liHtml; 430 + var dom,
  431 + tip;
428 432
429 - liHtml = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">\n ' + message.content + '\n <span class="countdown"></span>\n </span>\n </p>\n </div>'; 433 + tip = message.content +
  434 + '<span class="countdown"></span>';
430 435
431 - $msgList.append(liHtml);  
432 - $panelMainBody.scrollTop($panelMainBody[0].scrollHeight); 436 + dom = tipTpl({
  437 + content: tip
  438 + });
  439 +
  440 + // 消息添加
  441 + msgAppend(dom);
433 442
434 // 倒计时信息 443 // 倒计时信息
435 countdown(message.newContent, $('.tip .countdown')); 444 countdown(message.newContent, $('.tip .countdown'));
@@ -440,17 +449,21 @@ function pageInit() { @@ -440,17 +449,21 @@ function pageInit() {
440 * @private 449 * @private
441 */ 450 */
442 function handleCsMsg(rec, msgType, message) { 451 function handleCsMsg(rec, msgType, message) {
443 -  
444 - var liHtml; 452 + var dom;
445 453
446 message.newContent = emojiPrefix(message.newContent); 454 message.newContent = emojiPrefix(message.newContent);
447 if (msgType === 2) { 455 if (msgType === 2) {
448 message.newContent = '<img class="img-msg" src="' + message.content + '">'; 456 message.newContent = '<img class="img-msg" src="' + message.content + '">';
449 } 457 }
450 - liHtml = '<div class="list-item guest">\n <img src="' + rec.csHead + '" class="avatar">\n <div class="item-detail">\n <span class="time">' + rec.csName + ' ' + rec.sendTimeShort + '</span>\n <div class="msg-bubble">\n <div>' + message.newContent + '</div>\n </div>\n </div>\n </div>';  
451 458
452 - $msgList.append(liHtml);  
453 - $panelMainBody.scrollTop($panelMainBody[0].scrollHeight); 459 + dom = csTpl({
  460 + csHead: rec.csHead,
  461 + csName: rec.csName,
  462 + sendTimeShort: rec.sendTimeShort,
  463 + newContent: message.newContent
  464 + });
  465 +
  466 + msgAppend(dom);
454 } 467 }
455 468
456 /** 469 /**
@@ -466,28 +479,31 @@ function pageInit() { @@ -466,28 +479,31 @@ function pageInit() {
466 479
467 // 评价原因 480 // 评价原因
468 function discontentHtml(len, data) { 481 function discontentHtml(len, data) {
469 - var i,  
470 - r,  
471 - html = '', 482 + var dom = '',
472 ceilRows = Math.ceil(len / 2), 483 ceilRows = Math.ceil(len / 2),
473 floorRows = Math.floor(len / 2); 484 floorRows = Math.floor(len / 2);
474 485
475 - if (ceilRows === floorRows) {  
476 - for (r = 1, i = 0; r <= ceilRows; r++) {  
477 -  
478 - html += '<div class="dis-row">\n <span class="type" data-id="' + data[i].id + '" data-content="' + data[i].content + '">\n ' + data[i].content + '\n </span>\n <span class="type" data-id="' + data[i + 1].id + '" data-content="' + data[i].content + '">\n ' + data[i + 1].content + '\n </span>\n </div>';  
479 - 486 + if (ceilRows >= floorRows) {
  487 + for (var r = 1, i = 0; r <= ceilRows; r++) {
  488 + dom += disTpl({
  489 + isDouble: true,
  490 + id1: data[i].id,
  491 + id1Content: data[i].content,
  492 + id2: data[i+1].id,
  493 + id2Content: data[i+1].content
  494 + });
480 i += 2; 495 i += 2;
481 } 496 }
482 - } else {  
483 - for (r = 1, i = 0; r <= ceilRows - 1; r++) {  
484 - html += '<div class="dis-row">\n <span class="type" data-id="' + data[i].id + '" data-content="' + data[i].content + '">\n ' + data[i].content + '\n </span>\n <span class="type" data-id="' + data[i + 1].id + '" data-content="' + data[i].content + '">\n ' + data[i + 1].content + '\n </span>\n </div>';  
485 - i += 2;  
486 - }  
487 - html += '<div class="dis-row">\n <span class="type" data-id="' + data[len - 1].id + '" data-content="' + data[i].content + '">\n ' + data[len - 1].content + '\n </span>\n </div>';  
488 } 497 }
489 498
490 - $evalModal.find('.discontent').empty().append(html); 499 + if(ceilRows > floorRows) {
  500 + dom += disTpl({
  501 + id: data[len-1].id,
  502 + idContent: data[len-1].content,
  503 + });
  504 + }
  505 +
  506 + $evalModal.find('.discontent').empty().append(dom);
491 } 507 }
492 508
493 // 拉取评价原因 509 // 拉取评价原因
@@ -519,13 +535,15 @@ function pageInit() { @@ -519,13 +535,15 @@ function pageInit() {
519 * 处理收到消息 535 * 处理收到消息
520 */ 536 */
521 function getMessage(rec) { 537 function getMessage(rec) {
522 - var tipTpl, 538 + var dom,
  539 + tipContent,
523 recType = rec.type, 540 recType = rec.type,
524 message = rec.message, 541 message = rec.message,
525 msgType = message.type, 542 msgType = message.type,
526 isHidden = tab.tabIsHidden(), 543 isHidden = tab.tabIsHidden(),
527 allTypes = socketConf.recType; 544 allTypes = socketConf.recType;
528 545
  546 +
529 console.log('客户收到消息!', rec); 547 console.log('客户收到消息!', rec);
530 548
531 // 删除上个定时器 549 // 删除上个定时器
@@ -561,11 +579,15 @@ function pageInit() { @@ -561,11 +579,15 @@ function pageInit() {
561 579
562 case allTypes.ROBOT_SEND: 580 case allTypes.ROBOT_SEND:
563 rec.csName = rec.csName || '客服机器人'; 581 rec.csName = rec.csName || '客服机器人';
564 - tipTpl = '<div class="list-item guest">\n <img src="' + assetsPrefix + '/img/service/robot-avatar.png" class="avatar">\n <div class="item-detail">\n <span class="time">' + rec.csName + ' ' + rec.sendTimeShort + '</span>\n <div class="msg-bubble">\n <div>' + message.newContent + '</div>\n </div>\n </div>\n </div>'; 582 + dom = robotTpl({
  583 + assetsPrefix: assetsPrefix,
  584 + csName: rec.csName,
  585 + sendTimeShort: rec.sendTimeShort,
  586 + newContent: message.newContent
  587 + });
565 break; 588 break;
566 589
567 case allTypes.CS_SEND: 590 case allTypes.CS_SEND:
568 - // 处理客服消息  
569 handleCsMsg(rec, msgType, message); 591 handleCsMsg(rec, msgType, message);
570 break; 592 break;
571 593
@@ -578,17 +600,19 @@ function pageInit() { @@ -578,17 +600,19 @@ function pageInit() {
578 break; 600 break;
579 601
580 case allTypes.CS_CHATTING: 602 case allTypes.CS_CHATTING:
581 - // 正在人工会话  
582 csChatting(message); 603 csChatting(message);
583 break; 604 break;
584 605
585 - // 对方离开  
586 case allTypes.OP_LEAVE: 606 case allTypes.OP_LEAVE:
587 csOffline(message); 607 csOffline(message);
588 break; 608 break;
589 609
590 case allTypes.OFFLINE: 610 case allTypes.OFFLINE:
591 - tipTpl = '<div class="list-item">\n <p class="push-tip">\n <span class="tip">\n ' + message.content + '\n <a class="red-tip reconnect">\u8FDE\u7EBF\u5BA2\u670D</a>\n </span>\n </p>\n </div>'; 611 + tipContent = message.content +
  612 + '<a class="red-tip reconnect">连线客服</a>';
  613 + dom = tipTpl({
  614 + content: tipContent
  615 + });
592 break; 616 break;
593 617
594 default: 618 default:
@@ -596,8 +620,8 @@ function pageInit() { @@ -596,8 +620,8 @@ function pageInit() {
596 620
597 } 621 }
598 622
599 - $msgList.append(tipTpl);  
600 - $panelMainBody.scrollTop($panelMainBody[0].scrollHeight); 623 + // 添加新消息到消息列表
  624 + dom && msgAppend(dom);
601 } 625 }
602 626
603 /** 627 /**
@@ -614,7 +638,9 @@ function pageInit() { @@ -614,7 +638,9 @@ function pageInit() {
614 var jsonString = e.data; 638 var jsonString = e.data;
615 var received = JSON.parse(jsonString); 639 var received = JSON.parse(jsonString);
616 640
617 - socketConfCM.conversationId = received.newConversationId !== 0 ? received.newConversationId : received.conversationId; 641 + socketConfCM.conversationId = received.newConversationId !== 0 ?
  642 + received.newConversationId :
  643 + received.conversationId;
618 644
619 // 保存会话id 645 // 保存会话id
620 window.setCookie('conversationId', socketConfCM.conversationId, {expires: 60 * 15}); 646 window.setCookie('conversationId', socketConfCM.conversationId, {expires: 60 * 15});
@@ -647,7 +673,7 @@ function pageInit() { @@ -647,7 +673,7 @@ function pageInit() {
647 var item, 673 var item,
648 heightBefore, 674 heightBefore,
649 heightAfter, 675 heightAfter,
650 - msgTpl = ''; 676 + dom = '';
651 677
652 msgList = msgList.reverse(); 678 msgList = msgList.reverse();
653 679
@@ -658,59 +684,54 @@ function pageInit() { @@ -658,59 +684,54 @@ function pageInit() {
658 endTime = msgList[0].sendTime; 684 endTime = msgList[0].sendTime;
659 685
660 if (hasMore) { 686 if (hasMore) {
661 - var _iteratorNormalCompletion = true;  
662 - var _didIteratorError = false;  
663 - var _iteratorError = undefined;  
664 -  
665 - try {  
666 - for (var _iterator = msgList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {  
667 - item = _step.value;  
668 -  
669 - item.message.newContent = emojiPrefix(item.message.newContent);  
670 - if (item.message.type === 2) {  
671 - item.message.newContent = ['<img class="img-msg" src="', item.message.newContent, '">'].join('');  
672 - }  
673 -  
674 - switch (item.type) {  
675 - case allRTs.CU_SEND:  
676 - // 用户头像处理  
677 - if (!item.userHead) {  
678 - item.userHead = assetsPrefix + socketConf.defaultUserHead;  
679 - }  
680 -  
681 - msgTpl += '<div class="list-item host">\n <img src="' + item.userHead + '" class="avatar">\n <div class="item-detail">\n <span class="time">' + item.userName + ' ' + item.sendTimeShort + '</span>\n <div class="msg-bubble">\n <div>' + item.message.newContent + '</div>\n </div>\n </div>\n </div>';  
682 - break;  
683 -  
684 - case allRTs.ROBOT_SEND:  
685 - item.csName = item.csName || '客服机器人';  
686 - msgTpl = '<div class="list-item guest">\n <img src="' + assetsPrefix + '/img/service/robot-avatar.png" class="avatar">\n <div class="item-detail">\n <span class="time">' + item.csName + ' ' + item.sendTimeShort + '</span>\n <div class="msg-bubble">\n <div>' + item.message.newContent + '</div>\n </div>\n </div>\n </div>';  
687 - break;  
688 -  
689 - case allRTs.CS_SEND:  
690 - msgTpl += '<div class="list-item guest">\n <img src="' + item.csHead + '" class="avatar">\n <div class="item-detail">\n <span class="time">' + item.csName + ' ' + item.sendTimeShort + '</span>\n <div class="msg-bubble">\n <div>' + item.message.newContent + '</div>\n </div>\n </div>\n </div>';  
691 - break;  
692 -  
693 - default:  
694 - break;  
695 - } 687 + for(var i = 0, len = msgList.length; i < len; i++) {
  688 + item = msgList[i];
  689 + item.message.newContent = emojiPrefix(item.message.newContent);
  690 + if (item.message.type === 2) {
  691 + item.message.newContent =
  692 + ['<img class="img-msg" src="', item.message.newContent, '">'].join('');
696 } 693 }
697 - } catch (err) {  
698 - _didIteratorError = true;  
699 - _iteratorError = err;  
700 - } finally {  
701 - try {  
702 - if (!_iteratorNormalCompletion && _iterator.return) {  
703 - _iterator.return();  
704 - }  
705 - } finally {  
706 - if (_didIteratorError) {  
707 - throw _iteratorError;  
708 - } 694 +
  695 + switch (item.type) {
  696 + case allRTs.CU_SEND:
  697 + if (!item.userHead) {
  698 + item.userHead = assetsPrefix + socketConf.defaultUserHead;
  699 + }
  700 + dom = cusTpl({
  701 + userHead: item.userHead,
  702 + userName: item.userName,
  703 + sendTimeShort: item.sendTimeShort,
  704 + newContent: item.message.newContent
  705 + });
  706 + break;
  707 +
  708 + case allRTs.ROBOT_SEND:
  709 + item.csName = item.csName || '客服机器人';
  710 + dom = robotTpl({
  711 + assetsPrefix: assetsPrefix,
  712 + csName: item.csName,
  713 + sendTimeShort: item.sendTimeShort,
  714 + newContent: item.message.newContent
  715 + });
  716 + break;
  717 +
  718 + case allRTs.CS_SEND:
  719 + dom = csTpl({
  720 + csHead: item.csHead,
  721 + csName: item.csName,
  722 + sendTimeShort: item.sendTimeShort,
  723 + newContent: item.message.newContent
  724 + });
  725 + break;
  726 +
  727 + default:
  728 + break;
709 } 729 }
  730 +
710 } 731 }
711 732
712 heightBefore = $msgList.height(); 733 heightBefore = $msgList.height();
713 - $msgList.prepend(msgTpl); 734 + $msgList.prepend(dom);
714 heightAfter = $msgList.height(); 735 heightAfter = $msgList.height();
715 $panelMainBody.scrollTop(heightAfter - heightBefore); 736 $panelMainBody.scrollTop(heightAfter - heightBefore);
716 } 737 }
@@ -731,7 +752,7 @@ function pageInit() { @@ -731,7 +752,7 @@ function pageInit() {
731 type: 'GET', 752 type: 'GET',
732 url: urls.msgHistory, 753 url: urls.msgHistory,
733 data: data, 754 data: data,
734 - success: function success(res) { 755 + success: function (res) {
735 if (res && res.code === 200) { 756 if (res && res.code === 200) {
736 hasMore && msgResolve(res.data); 757 hasMore && msgResolve(res.data);
737 $history.hide(); 758 $history.hide();
@@ -765,11 +786,22 @@ function pageInit() { @@ -765,11 +786,22 @@ function pageInit() {
765 786
766 // tab页title重置 787 // tab页title重置
767 tab.tabVisible(function() { 788 tab.tabVisible(function() {
768 - console.log('reset tab');  
769 document.title = docTitle; 789 document.title = docTitle;
770 clearInterval(titleInterval); 790 clearInterval(titleInterval);
771 }); 791 });
772 792
  793 + // 校验留言输入内容
  794 + $leaveMsg.find('textarea').bind('change', function() {
  795 + var $lm = $('#leaveMsg'),
  796 + val = $(this).val();
  797 +
  798 + if (val === '') {
  799 + $lm.find('.leave-msg-tip').removeClass('hide');
  800 + } else {
  801 + $lm.find('.leave-msg-tip').addClass('hide');
  802 + }
  803 + });
  804 +
773 // 提交留言 805 // 提交留言
774 $leaveMsg.find('.submit').click(function() { 806 $leaveMsg.find('.submit').click(function() {
775 var lMsg = $('#leaveMsg'), 807 var lMsg = $('#leaveMsg'),
@@ -845,7 +877,7 @@ function pageInit() { @@ -845,7 +877,7 @@ function pageInit() {
845 processInfo.savedEval = true; 877 processInfo.savedEval = true;
846 878
847 if (res && res.code === 200) { 879 if (res && res.code === 200) {
848 - socketConfCM.type = 10; // 评价后通知客服 880 + socketConfCM.type = allRTs.EVAL_NOTICE; // 评价后通知客服
849 socketConfCM.uuid = uuid.v4(); 881 socketConfCM.uuid = uuid.v4();
850 socketChat.send(socketConfCM); 882 socketChat.send(socketConfCM);
851 } 883 }
@@ -915,7 +947,7 @@ function pageInit() { @@ -915,7 +947,7 @@ function pageInit() {
915 res = res.result; 947 res = res.result;
916 if (res && res.code === 200) { 948 if (res && res.code === 200) {
917 // 上传成功后发送图片消息 949 // 上传成功后发送图片消息
918 - socketConfCM.type = 3; 950 + socketConfCM.type = allRTs.CU_SEND;
919 socketConfCM.message.content = res.data.filePath; 951 socketConfCM.message.content = res.data.filePath;
920 socketConfCM.message.type = 2; 952 socketConfCM.message.type = 2;
921 socketConfCM.uuid = uuid.v4(); 953 socketConfCM.uuid = uuid.v4();
@@ -1100,10 +1132,14 @@ function pageInit() { @@ -1100,10 +1132,14 @@ function pageInit() {
1100 1132
1101 // 消息图片放大显示 1133 // 消息图片放大显示
1102 $msgList.on('click', '.msg-bubble .img-msg', function(e) { 1134 $msgList.on('click', '.msg-bubble .img-msg', function(e) {
1103 - var msgZoomIn = $('.img-zoom-in');  
1104 -  
1105 - msgZoomIn.find('img').attr('src', $(e.target).attr('src'));  
1106 - msgZoomIn.fadeIn(); 1135 + var $et = $(e.target);
  1136 + var $zoom = $('.img-zoom-in');
  1137 + var $img = $zoom.find('img');
  1138 + var maxH = $window.height() - 100;
  1139 +
  1140 + $img.css('max-height', maxH);
  1141 + $img.attr('src', $et.attr('src'));
  1142 + $zoom.fadeIn();
1107 }); 1143 });
1108 1144
1109 $document.on('click', '.img-zoom-in', function() { 1145 $document.on('click', '.img-zoom-in', function() {
@@ -14,6 +14,7 @@ var config = { @@ -14,6 +14,7 @@ var config = {
14 MANUAL_SERVICE: 2, // 连线人工客服 14 MANUAL_SERVICE: 2, // 连线人工客服
15 CU_SEND: 3, // 用户发消息 15 CU_SEND: 3, // 用户发消息
16 BREAK_TIME: 5, // 断链倒计时 16 BREAK_TIME: 5, // 断链倒计时
  17 + EVAL_NOTICE: 10, // 评价后通知客服
17 ROBOT_SEND: 103, // 机器人消息 18 ROBOT_SEND: 103, // 机器人消息
18 TRANSFER: 1006, // 会话转移 19 TRANSFER: 1006, // 会话转移
19 CS_ENTER: 10001, // 客服进入 20 CS_ENTER: 10001, // 客服进入
@@ -21,10 +21,9 @@ @@ -21,10 +21,9 @@
21 img { 21 img {
22 position: relative; 22 position: relative;
23 display: block; 23 display: block;
24 - max-width: 500px;  
25 height: auto; 24 height: auto;
26 margin: 0 auto; 25 margin: 0 auto;
27 - margin-top: 100px; 26 + margin-top: 50px;
28 cursor: pointer; 27 cursor: pointer;
29 28
30 } 29 }