...
|
...
|
@@ -17,7 +17,8 @@ var socket = require('./socket-chat'), |
|
|
socketConf = require('./socket-config'),
|
|
|
cmEntity = socketConf.conversationMessage;
|
|
|
|
|
|
const chatBox = $('#chat-window');
|
|
|
const chatBox = $('#chat-window'),
|
|
|
encryptedUid = $('#encrypteduid').val();
|
|
|
|
|
|
const append = (html) => {
|
|
|
chatBox.append(html);
|
...
|
...
|
@@ -39,26 +40,54 @@ var chat = { |
|
|
init: function() {
|
|
|
const self = this;
|
|
|
|
|
|
socket.init(Object.assign(socketConf, {
|
|
|
onMessage: function(e) {
|
|
|
var received = JSON.parse(e.data);
|
|
|
console.log(received);
|
|
|
cmEntity.conversationId = received.newConversationId > 0 ?
|
|
|
received.newConversationId :
|
|
|
received.conversationId;
|
|
|
|
|
|
gg = new Customer(cmEntity.userHead);
|
|
|
mm = new Employee(cmEntity.userHead);
|
|
|
// 保存过程中信息
|
|
|
self.getMessage(received);
|
|
|
}
|
|
|
}));
|
|
|
socketConf.conversationMessage.encryptedUid = encryptedUid;
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/service/userinfo',
|
|
|
}).then(function(result) {
|
|
|
// 获取用户信息
|
|
|
gg = new Customer(result.head || cmEntity.userHead);
|
|
|
mm = new Employee(cmEntity.userHead);
|
|
|
self.fetchHistoryMsg(function() {
|
|
|
socket.init(Object.assign(socketConf, {
|
|
|
onMessage: function(e) {
|
|
|
var received = JSON.parse(e.data);
|
|
|
console.log(received);
|
|
|
cmEntity.conversationId = received.newConversationId > 0 ?
|
|
|
received.newConversationId :
|
|
|
received.conversationId;
|
|
|
|
|
|
self.getMessage(received);
|
|
|
}
|
|
|
}));
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 获取10条历史记录
|
|
|
fetchHistoryMsg: function() {
|
|
|
const self = this;
|
|
|
|
|
|
var data = {
|
|
|
encryptedUid: encryptedUid,
|
|
|
};
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/service/msghistory',
|
|
|
data: data,
|
|
|
success: function(result) {
|
|
|
if (result && result.code === 200) {
|
|
|
for (let item of result.data) {
|
|
|
self.getMessage(item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
// 处理收到的消息
|
|
|
getMessage: function(rec) {
|
|
|
var tipTpl,
|
|
|
recType = rec.type,
|
|
|
var recType = rec.type,
|
|
|
message = rec.message,
|
|
|
msgType = message.type,
|
|
|
allTypes = socketConf.recType;
|
...
|
...
|
@@ -88,10 +117,10 @@ var chat = { |
|
|
|
|
|
break;
|
|
|
|
|
|
// case allTypes.CS_SEND:
|
|
|
// // 处理客服消息
|
|
|
// handleCsMsg(rec, msgType, message);
|
|
|
// break;
|
|
|
case allTypes.CS_SEND:
|
|
|
// 处理客服消息
|
|
|
this.handleCsMsg(rec, msgType, message);
|
|
|
break;
|
|
|
|
|
|
// case allTypes.EVAL_INVITE:
|
|
|
// // 客服发起
|
...
|
...
|
@@ -104,17 +133,10 @@ var chat = { |
|
|
// csChatting(message);
|
|
|
// break;
|
|
|
|
|
|
// case allTypes.OFFLINE:
|
|
|
// tipTpl =
|
|
|
// `<div class="list-item">
|
|
|
// <p class="push-tip">
|
|
|
// <span class="tip">
|
|
|
// ${message.content}
|
|
|
// <a class="red-tip reconnect">连线客服</a>
|
|
|
// </span>
|
|
|
// </p>
|
|
|
// </div>`;
|
|
|
// break;
|
|
|
case allTypes.OFFLINE:
|
|
|
append(time(Date.now()).show());
|
|
|
append(tip().offLine());
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
...
|
...
|
@@ -123,19 +145,22 @@ var chat = { |
|
|
},
|
|
|
|
|
|
// 刚进入提示
|
|
|
enterSuccess: function() {
|
|
|
enterSuccess: function(message) {
|
|
|
append(time(Date.now()).show());
|
|
|
append(tip().offLine());
|
|
|
append(tip(message.content).onLine());
|
|
|
},
|
|
|
|
|
|
// 连线人工客服
|
|
|
linkSuccess: function(type, message) {
|
|
|
var status = $('.chat-status'),
|
|
|
name = $('.service-name');
|
|
|
name = $('.service-name'),
|
|
|
comment = $('.chat-comment');
|
|
|
|
|
|
if (type === 2 || type === 3) {
|
|
|
status.css('background', '#85be4a');
|
|
|
name.text('YOHO!客服');
|
|
|
comment.css('display', 'inline-block');
|
|
|
append(tip(message.content).onLine());
|
|
|
} else {
|
|
|
name.text('YOHO!客服');
|
...
|
...
|
@@ -150,6 +175,16 @@ var chat = { |
|
|
append(gg.sendMsg(message.content, true));
|
|
|
}
|
|
|
resizeFooter();
|
|
|
},
|
|
|
|
|
|
// 客服发消息
|
|
|
handleCsMsg: function(rec, msgType, message) {
|
|
|
if (msgType === 2) {
|
|
|
append(mm.sendImg(message.content));
|
|
|
} else {
|
|
|
append(mm.sendMsg(message.content));
|
|
|
}
|
|
|
resizeFooter();
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -167,8 +202,7 @@ const sendMsg = function(type, content) { |
|
|
}
|
|
|
};
|
|
|
|
|
|
// 客户端接受消息
|
|
|
|
|
|
// 聊天区发送信息
|
|
|
$('.text-in').on('keydown', function(e) {
|
|
|
if (e.keyCode === 13) {
|
|
|
sendMsg(1, $(this).val());
|
...
|
...
|
|