...
|
...
|
@@ -152,7 +152,7 @@ var chat = { |
|
|
.on('click.orderList', '[data-trigger=order-list]', function() {
|
|
|
self.orderListView.trigger('show.OderListView');
|
|
|
})
|
|
|
.on('click.chat.switchServer', '[data-action=change-human]', function(){
|
|
|
.on('click.chat.switchServer', '[data-action=change-human]', function() {
|
|
|
self.switchService('human');
|
|
|
})
|
|
|
.on('keydown.chat.sendText', '.text-in', function(event) {
|
...
|
...
|
@@ -221,8 +221,12 @@ var chat = { |
|
|
* data: object //消息数据
|
|
|
* }
|
|
|
*
|
|
|
* @param {boolean} noDraw 默认false 渲染并发送
|
|
|
*
|
|
|
* @return {jquery} $elem
|
|
|
*
|
|
|
*/
|
|
|
sendMSG: function(msg) {
|
|
|
sendMSG: function(msg, noDraw = false) {
|
|
|
if (!msg || !msg.data) {
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -265,13 +269,19 @@ var chat = { |
|
|
|
|
|
// TODO 时间
|
|
|
|
|
|
let $msg = this._drawMSG(msg);
|
|
|
!noDraw && this._drawMSG(msg);
|
|
|
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
|
|
|
return this;
|
|
|
},
|
|
|
|
|
|
sendPic: function() {
|
|
|
// 1. 渲染 dom, state loading
|
|
|
// 2. ajax done, show pic
|
|
|
// 2. ajax fail, show error
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 处理 conversationMessage, 生成 渲染用的数据
|
|
|
*/
|
...
|
...
|
@@ -342,7 +352,7 @@ var chat = { |
|
|
msgType = message.type,
|
|
|
allTypes = socketConf.recType;
|
|
|
|
|
|
var uuid = rec.uuid;
|
|
|
// var uuid = rec.uuid;
|
|
|
var viewData;
|
|
|
|
|
|
// 服务状态: 离线
|
...
|
...
|
@@ -442,8 +452,13 @@ var chat = { |
|
|
/**
|
|
|
* 对话消息
|
|
|
* @param 【object|array] viewData 订单消息模版数据
|
|
|
* @param {function} cusAction 自定义处理函数
|
|
|
* function ($html) {
|
|
|
* // $html 模版渲染出来的jquery
|
|
|
* // this ----> chat
|
|
|
* }
|
|
|
*/
|
|
|
_drawMSG: function(viewData) {
|
|
|
_drawMSG: function(viewData, cusAction = null) {
|
|
|
let chatWin = this.$chatWin[0];
|
|
|
|
|
|
if (!$.isArray(viewData)) {
|
...
|
...
|
@@ -454,8 +469,12 @@ var chat = { |
|
|
let $html = $(this.messageT(viewData));
|
|
|
|
|
|
this.checkTime();
|
|
|
$html.appendTo(this.$chatWin);
|
|
|
chatWin.scrollTop = chatWin.scrollHeight;
|
|
|
if (cusAction) {
|
|
|
cusAction.apply(this, [$html]);
|
|
|
} else {
|
|
|
$html.appendTo(this.$chatWin);
|
|
|
chatWin.scrollTop = chatWin.scrollHeight;
|
|
|
}
|
|
|
|
|
|
return $html;
|
|
|
},
|
...
|
...
|
@@ -497,7 +516,7 @@ var chat = { |
|
|
},
|
|
|
|
|
|
// 获取10条历史记录
|
|
|
fetchHistoryMsg: function(cb) {
|
|
|
fetchHistoryMsg: function() {
|
|
|
const self = this;
|
|
|
|
|
|
if (msgHistory.totalCount !== null && msgHistory.curCount >= msgHistory.totalCount) {
|
...
|
...
|
@@ -506,7 +525,7 @@ var chat = { |
|
|
|
|
|
return api.msghistory(uid, encryptedUid, msgHistory.endTime)
|
|
|
.done(function(result) {
|
|
|
if (!result || result.code !== 200) {
|
|
|
if (!result || result.code !== 200 || !result.data) {
|
|
|
return false;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -527,7 +546,9 @@ var chat = { |
|
|
}
|
|
|
});
|
|
|
|
|
|
self._drawMSG(arr);
|
|
|
self._drawMSG(arr, function($html) {
|
|
|
self.$historyLoader.after($html);
|
|
|
});
|
|
|
|
|
|
if (records.length) {
|
|
|
msgHistory.endTime = records[0].sendTime;
|
...
|
...
|
@@ -547,7 +568,8 @@ var chat = { |
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
this._sysInfo();
|
|
|
} else {
|
|
|
//TODO 切换rebot
|
|
|
|
|
|
// TODO 切换rebot
|
|
|
}
|
|
|
},
|
|
|
|
...
|
...
|
@@ -604,25 +626,44 @@ $upload.on('change', function() { |
|
|
formData.append('files[]', files[0]);
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: `${gDomains.imServer}/fileManage/uploadFile`,
|
|
|
data: formData,
|
|
|
processData: false, // 告诉jQuery不要去处理发送的数据
|
|
|
contentType: false
|
|
|
}).done(function(res) {
|
|
|
if (res.code === 200) {
|
|
|
chat.sendMSG({
|
|
|
type: 'picture',
|
|
|
data: {
|
|
|
content: res.data.filePath
|
|
|
}
|
|
|
});
|
|
|
var msg = {
|
|
|
type: 'picture',
|
|
|
from: 'customer',
|
|
|
avatar: userAvatar,
|
|
|
data: {
|
|
|
content: ''
|
|
|
}
|
|
|
})
|
|
|
.fail(function(res) {
|
|
|
chat._sysInfo('图片上传失败,请稍后再试');
|
|
|
});
|
|
|
};
|
|
|
var $elem = chat._drawMSG(msg);
|
|
|
|
|
|
|
|
|
var _action = function() {
|
|
|
$elem.removeClass('send-fail').addClass('send-loading');
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: `${gDomains.imServer}/fileManage/uploadFile`,
|
|
|
data: formData,
|
|
|
processData: false, // 告诉jQuery不要去处理发送的数据
|
|
|
contentType: false
|
|
|
})
|
|
|
.done(function(res) {
|
|
|
if (res.code === 200) {
|
|
|
$elem.removeClass('send-loading')
|
|
|
.find('.chat-image').attr('src', res.data.filePath);
|
|
|
|
|
|
chat.sendMSG(msg, true); // only send msg, no draw msg;
|
|
|
}
|
|
|
})
|
|
|
.fail(function() {
|
|
|
chat._sysInfo('图片上传失败,请稍后再试');
|
|
|
$elem
|
|
|
.removeClass('send-loading')
|
|
|
.addClass('send-fail')
|
|
|
.one('click', _action);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
_action();
|
|
|
});
|
|
|
|
|
|
|
...
|
...
|
@@ -642,4 +683,4 @@ $('#chat-window').on('click', '.chat-image', function() { |
|
|
|
|
|
window.$ = $;
|
|
|
window.chat = chat;
|
|
|
window.cmEntity = cmEntity; |
|
|
\ No newline at end of file |
|
|
window.cmEntity = cmEntity; |
...
|
...
|
|