...
|
...
|
@@ -15,6 +15,8 @@ var $ = require('yoho-jquery'), |
|
|
// 记录鼠标位置
|
|
|
var uid,
|
|
|
cmEntity,
|
|
|
endTime,
|
|
|
hasMore = true,
|
|
|
originConf,
|
|
|
encryptionUid,
|
|
|
cursorPosition,
|
...
|
...
|
@@ -40,7 +42,8 @@ var key, |
|
|
urls = {
|
|
|
makeEval: '/evalute/saveEvalute',
|
|
|
leaveMsg: '/leavemessage/saveLeavemessage',
|
|
|
evalReason: '/evalute/queryEvaluteReason'
|
|
|
evalReason: '/evalute/queryEvaluteReason',
|
|
|
msgHistory: '/conversationMessage/pageList'
|
|
|
};
|
|
|
|
|
|
require('bootstrap');
|
...
|
...
|
@@ -544,6 +547,92 @@ function getMessage(rec) { |
|
|
$panelMainBody.scrollTop($panelMainBody[0].scrollHeight);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 消息解析
|
|
|
* @param msgList
|
|
|
*/
|
|
|
function msgResolve(msgList) {
|
|
|
var item,
|
|
|
heightBefore,
|
|
|
heightAfter,
|
|
|
msgTpl = '';
|
|
|
|
|
|
msgList = msgList.reverse();
|
|
|
|
|
|
|
|
|
if (endTime === msgList[0].sendTime) {
|
|
|
hasMore = false;
|
|
|
}
|
|
|
|
|
|
endTime = msgList[0].sendTime;
|
|
|
|
|
|
if (hasMore) {
|
|
|
for (item of msgList) {
|
|
|
item.message.newContent = _emojiPrefix(item.message.newContent);
|
|
|
if (item.message.type === 2) {
|
|
|
item.message.newContent =
|
|
|
['<img class="msg-img" src="', item.message.newContent, '">'].join('');
|
|
|
}
|
|
|
|
|
|
// 客户自己的消息
|
|
|
if (item.type === 3) {
|
|
|
msgTpl +=
|
|
|
`<div class="list-item host">
|
|
|
<img src="${item.userHead}" class="avatar">
|
|
|
<div class="item-detail">
|
|
|
<span class="time">${item.userName} ${item.sendTimeShort}</span>
|
|
|
<div class="msg-bubble">
|
|
|
<div>${item.message.newContent}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>`;
|
|
|
|
|
|
// 客服消息
|
|
|
} else {
|
|
|
msgTpl +=
|
|
|
`<div class="list-item guest">
|
|
|
<img src="${item.csHead}" class="avatar">
|
|
|
<div class="item-detail">
|
|
|
<span class="time">${item.csName} ${item.sendTimeShort}</span>
|
|
|
<div class="msg-bubble">
|
|
|
<div>${item.message.newContent}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>`;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
heightBefore = $msgList.height();
|
|
|
$msgList.prepend(msgTpl);
|
|
|
heightAfter = $msgList.height();
|
|
|
$panelMainBody.scrollTop(heightAfter - heightBefore);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取历史聊天记录
|
|
|
*/
|
|
|
function fetchHistoryMsg() {
|
|
|
var data = {
|
|
|
uid: uid
|
|
|
};
|
|
|
|
|
|
if (endTime) {
|
|
|
data.endTime = endTime;
|
|
|
}
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: urls.msgHistory,
|
|
|
data: data,
|
|
|
success: function(res) {
|
|
|
if (res && res.code === 200) {
|
|
|
hasMore && msgResolve(res.data);
|
|
|
$('.about-his.has-his').hide();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 初始化socket连接
|
|
|
socketChat.init(Object.assign(socketConf, {
|
|
|
|
...
|
...
|
@@ -890,11 +979,13 @@ $('.img-zoom-in').on('click', function(e) { |
|
|
});
|
|
|
|
|
|
// 显示历史记录
|
|
|
$('.about-his.has-his').click(function(e) {
|
|
|
$(e.currentTarget).hide();
|
|
|
$('.list-item.his-msg').show();
|
|
|
$('.about-his.has-his').click(fetchHistoryMsg);
|
|
|
|
|
|
$panelMainBody.scrollTop($panelMainBody[0].scrollHeight);
|
|
|
// 滚动加载更多
|
|
|
$panelMainBody.scroll(function() {
|
|
|
var atTop = $panelMainBody.scrollTop() === 0;
|
|
|
|
|
|
atTop && hasMore && fetchHistoryMsg();
|
|
|
});
|
|
|
|
|
|
|
...
|
...
|
@@ -907,3 +998,4 @@ $('.about-his.has-his').click(function(e) { |
|
|
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|