...
|
...
|
@@ -53,6 +53,7 @@ let customerService = { |
|
|
|
|
|
// 历史消息分页
|
|
|
let msgHistory = {
|
|
|
conversationId: '', // 会话id
|
|
|
endTime: null,
|
|
|
curCount: 0,
|
|
|
totalCount: null
|
...
|
...
|
@@ -621,10 +622,6 @@ var chat = { |
|
|
_drawMSG: function(viewData, cusAction = null) {
|
|
|
let chatWin = this.$chatWin[0];
|
|
|
|
|
|
if (!$.isArray(viewData)) {
|
|
|
viewData = [viewData];
|
|
|
}
|
|
|
|
|
|
// console.log(viewData);
|
|
|
let $html = $(this.messageT(viewData));
|
|
|
|
...
|
...
|
@@ -690,22 +687,41 @@ var chat = { |
|
|
let records = result.records || [];
|
|
|
|
|
|
|
|
|
records.reverse();
|
|
|
// records.reverse();
|
|
|
|
|
|
let $docFragment = $(document.createDocumentFragment());
|
|
|
|
|
|
records.forEach(chatMessage => {
|
|
|
records.forEach((chatMessage, index, arr) => {
|
|
|
let nextChat = records[index + 1];
|
|
|
let data = self.buildViewData(chatMessage); //eslint-disable-line
|
|
|
|
|
|
if (data) {
|
|
|
arr.push(data);
|
|
|
let conversationId = chatMessage.conversationId;
|
|
|
let timstamp = Math.ceil(chatMessage.sendTime / 1000); // 原来是微妙 转换成毫秒
|
|
|
let $html = self._drawMSG(data);
|
|
|
|
|
|
$docFragment.prepend($html);
|
|
|
|
|
|
if (index === 0 && !msgHistory.conversationId) {
|
|
|
msgHistory.conversationId = conversationId;
|
|
|
}
|
|
|
|
|
|
if (
|
|
|
nextChat &&
|
|
|
(nextChat.conversationId !== msgHistory.conversationId)
|
|
|
) {
|
|
|
$docFragment.prepend(time(timstamp).show());
|
|
|
msgHistory.conversationId = nextChat.conversationId;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
});
|
|
|
|
|
|
self._drawMSG(arr, function($html) {
|
|
|
self.$historyLoader.after($html);
|
|
|
});
|
|
|
self.$historyLoader.after($docFragment);
|
|
|
|
|
|
|
|
|
if (records.length) {
|
|
|
msgHistory.endTime = records[0].sendTime;
|
|
|
msgHistory.endTime = records[records.length - 1].sendTime;
|
|
|
msgHistory.curCount += records.length;
|
|
|
}
|
|
|
|
...
|
...
|
|