...
|
...
|
@@ -12,10 +12,6 @@ import { |
|
|
tip
|
|
|
} from './tip';
|
|
|
import {
|
|
|
Customer,
|
|
|
Employee
|
|
|
} from './role';
|
|
|
import {
|
|
|
RatingView,
|
|
|
LeaveMSGView,
|
|
|
OrderListView
|
...
|
...
|
@@ -35,7 +31,6 @@ const append = (html) => { |
|
|
chatBox.append(html);
|
|
|
};
|
|
|
|
|
|
let gg, mm;
|
|
|
|
|
|
// 聊天调整footer位置
|
|
|
const resizeFooter = () => {
|
...
|
...
|
@@ -73,14 +68,13 @@ var chat = { |
|
|
|
|
|
this.bindEvents();
|
|
|
|
|
|
socketConf.conversationMessage.encryptedUid = encryptedUid;
|
|
|
cmEntity.encryptedUid = encryptedUid;
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/service/userinfo',
|
|
|
}).then(function(result) {
|
|
|
// 获取用户信息
|
|
|
gg = new Customer(result.head || cmEntity.userHead);
|
|
|
mm = new Employee(cmEntity.userHead);
|
|
|
cmEntity.userHead = result.head || cmEntity.userHead;
|
|
|
self.fetchHistoryMsg(function() {
|
|
|
self.bootSocket();
|
|
|
});
|
...
|
...
|
@@ -93,6 +87,7 @@ var chat = { |
|
|
let actions = {
|
|
|
onMessage: function(event) {
|
|
|
let received = JSON.parse(event.data);
|
|
|
console.log(received);
|
|
|
|
|
|
// update 会话id
|
|
|
cmEntity.conversationId = received.newConversationId > 0 ?
|
...
|
...
|
@@ -157,7 +152,7 @@ var chat = { |
|
|
* type: str //消息类型 see swtich msg.type
|
|
|
* data: object //消息数据
|
|
|
* }
|
|
|
*
|
|
|
*
|
|
|
* 测试数据:
|
|
|
chat.sendMSG({
|
|
|
type: 'order',
|
...
|
...
|
@@ -226,6 +221,26 @@ var chat = { |
|
|
success: function(result) {
|
|
|
if (result && result.code === 200) {
|
|
|
for (let item of result.data.reverse()) {
|
|
|
let cfg = {
|
|
|
style: 'send-msg',
|
|
|
avatar: cmEntity.userHead,
|
|
|
};
|
|
|
|
|
|
if (item.type === 3) {
|
|
|
if (item.message.type === 2) {
|
|
|
cfg.type = 'picture';
|
|
|
cfg.data = {
|
|
|
src: item.message.content,
|
|
|
};
|
|
|
} else {
|
|
|
cfg.type = 'text';
|
|
|
cfg.data = {
|
|
|
msg: item.message.content,
|
|
|
};
|
|
|
}
|
|
|
self._drawMSG(cfg);
|
|
|
continue;
|
|
|
}
|
|
|
self.handleReceiveMSG(item);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -294,7 +309,14 @@ var chat = { |
|
|
|
|
|
case allTypes.ROBOT_SEND:
|
|
|
rec.csName = rec.csName || '客服机器人';
|
|
|
append(mm.sendMsg(message.content));
|
|
|
this._drawMSG({
|
|
|
type: 'text',
|
|
|
style: 'recevied-msg',
|
|
|
avatar: cmEntity.userHead,
|
|
|
data: {
|
|
|
msg: message.content,
|
|
|
}
|
|
|
});
|
|
|
resizeFooter();
|
|
|
|
|
|
break;
|
...
|
...
|
@@ -351,21 +373,28 @@ var chat = { |
|
|
|
|
|
// 用户发消息
|
|
|
handleCusMsg: function(rec, msgType, message) {
|
|
|
if (msgType === 2) {
|
|
|
append(gg.sendImg(message.content, true));
|
|
|
} else {
|
|
|
append(gg.sendMsg(message.content, true));
|
|
|
}
|
|
|
resizeFooter();
|
|
|
// 消去状态
|
|
|
},
|
|
|
|
|
|
// 客服发消息
|
|
|
handleCsMsg: function(rec, msgType, message) {
|
|
|
let cfg = {
|
|
|
style: 'recevied-msg',
|
|
|
avatar: cmEntity.userHead,
|
|
|
};
|
|
|
|
|
|
if (msgType === 2) {
|
|
|
append(mm.sendImg(message.content));
|
|
|
cfg.type = 'picture';
|
|
|
cfg.data = {
|
|
|
src: message.content,
|
|
|
};
|
|
|
} else {
|
|
|
append(mm.sendMsg(message.content));
|
|
|
cfg.type = 'text';
|
|
|
cfg.data = {
|
|
|
msg: message.content,
|
|
|
};
|
|
|
}
|
|
|
this._drawMSG(cfg);
|
|
|
resizeFooter();
|
|
|
}
|
|
|
};
|
...
|
...
|
@@ -374,12 +403,35 @@ chat.init(); |
|
|
|
|
|
// 用户发送消息
|
|
|
const sendMsg = function(type, content) {
|
|
|
let cfg = {
|
|
|
style: 'send-msg',
|
|
|
avatar: cmEntity.userHead,
|
|
|
};
|
|
|
|
|
|
if (!content) {
|
|
|
return;
|
|
|
} else {
|
|
|
cmEntity.type = 3;
|
|
|
cmEntity.message.content = content;
|
|
|
if (type === 2) {
|
|
|
cfg.type = 'picture';
|
|
|
cfg.data = {
|
|
|
src: content,
|
|
|
sending: true,
|
|
|
uuid: Date.now(),
|
|
|
};
|
|
|
} else {
|
|
|
cfg.type = 'text';
|
|
|
cfg.data = {
|
|
|
msg: content,
|
|
|
sending: true,
|
|
|
uuid: Date.now(),
|
|
|
};
|
|
|
}
|
|
|
|
|
|
chat._drawMSG(cfg);
|
|
|
cmEntity.message.type = type || 1;
|
|
|
cmEntity.message.content = content;
|
|
|
cmEntity.type = 3;
|
|
|
cmEntity.uuid = cfg.data.uuid;
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
}
|
|
|
};
|
...
|
...
|
@@ -428,18 +480,6 @@ $('.menu-trigger').on('touchend', function() { |
|
|
$('.uploadifive-button').css('position', 'absolute');
|
|
|
});
|
|
|
|
|
|
// 评论
|
|
|
$('.chat-comment').on('touchend', function() {
|
|
|
let $comment = $('.comment'),
|
|
|
box = new RatingView($comment);
|
|
|
|
|
|
if ($comment.css('display') === 'none') {
|
|
|
$comment.show();
|
|
|
} else {
|
|
|
$comment.hide();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
// 图片放大
|
|
|
$('#chat-window').on('click', '.chat-image', function() {
|
...
|
...
|
|