Authored by 陈轩

save

... ... @@ -48,7 +48,10 @@ exports.fetchImHistory = (uid, pageSize, startTime, endTime) => {
val && (params[key] = val);
});
return ImAPI.get('/api/conversationMessage/pageList', params);
return ImAPI.get('/api/conversationMessage/pageList', params)
.then(result => {
return _.get(result, 'data', []);
}, () => []);
};
/**
... ...
<div class="msg-wrap {{style}}">
{{#each .}}
<div class="msg-wrap {{style from}}" data-uuid={{uuid}}>
<img src="{{avatar}}" alt="" class="head-icon">
<div class="chat-info">
{{#data}}
... ... @@ -6,6 +7,7 @@
{{/data}}
</div>
</div>
{{/each}}
{{!--inline partails--}}
... ... @@ -22,11 +24,11 @@
{{/inline}}
{{#*inline 'text'}}
<div class="chat-txt" uuid={{uuid}}>
<div class="chat-txt">
{{#sending}}
<i class="send-status send-loading">!</i>
{{/sending}}
<span>{{{msg}}}</span>
<span>{{{content}}}</span>
</div>
{{/inline}}
... ... @@ -34,7 +36,7 @@
<div class="chat-pic">
<i class="send-fail">!</i>
<span class="image">
<img src="{{src}}" alt="" class="chat-image">
<img src="{{content}}" alt="" class="chat-image">
</span>
</div>
{{/inline}}
... ...
module.exports = function(data) {
var style = '';
switch (data) {
case 'customer': style = 'send-msg'; break;
case 'employee':
case 'rebot':
style= 'recevied-msg';
break;
}
return style;
};
... ...
... ... @@ -40,12 +40,20 @@ const resizeFooter = () => {
chatBox[0].scrollTop = chatBox[0].scrollHeight;
};
const msgTypeMap = {
1: 'text',
2: 'picture',
10: 'order'
};
var chat = {
$chat: null,
$chatWin: null,
$netTip: null,
msgArr: [],
state: {
lastMSGTime: ''
},
... ... @@ -120,6 +128,20 @@ var chat = {
})
.on('click.orderList', '[data-trigger=order-list]', function() {
self.orderListView.trigger('show.OderListView');
})
.on('click.chat.switchServer', '[data-action=change-human]', function(){
self.switchService('human');
})
.on('keydown.chat.sendText', '.text-in', function(event) {
if (event.which === 13) {
let content = {
data: {
content: $.trim(event.target.value)
}
};
self.sendMSG(content);
}
});
... ... @@ -157,6 +179,7 @@ var chat = {
chat.sendMSG({
type: 'order',
data: {
data: '123123',
imgSrc: '123123123123',
orderCode: '123123123123',
cost: '123123123123',
... ... @@ -167,33 +190,136 @@ var chat = {
*
*/
sendMSG: function(msg) {
this._drawMSG(msg);
if (!msg || !msg.data) {
return;
}
let data = msg.data;
let uuid = Date.now();
let arr;
msg.type = msg.type || 'text';
msg.uid = uuid;
cmEntity.uuid = uuid;
switch (msg.type) {
case 'order': // 订单消息
case 'order':
arr = [
'单号:', data.orderCode,
'金额: ', '¥' + data.cost,
'下单时间: ', data.createTime,
'状态: ', data.orderStatus
];
cmEntity.message.type = 10;
cmEntity.message.content = arr;
break;
case 'pic': // 图片消息
case 'picture':
cmEntity.message.content = data.content;
cmEntity.message.type = 2;
break;
case 'voice': // 语音消息
case 'text':
default:
cmEntity.message.type = 1;
cmEntity.message.content = data.content;
}
// TODO 时间
let $msg = this._drawMSG(msg);
this.msgArr.push($msg);
socket.send(JSON.stringify(cmEntity));
return this;
},
/**
* 处理 conversationMessage, 生成 渲染用的数据
*/
buildViewData: function(cm) {
var viewData = {};
var message = cm.message;
var allTypes = socketConf.recType;
switch (cm.type) {
case allTypes.CU_SEND:
viewData.from = 'customer';
break;
case allTypes.CS_SEND:
viewData.from = 'employee';
break;
default: // 文字消息
case allTypes.ROBOT_SEND:
viewData.from = 'rebot';
break;
default:
return null;
}
switch (message.type) {
case 1:
viewData.type = msgTypeMap[1];
viewData.data = {
content: message.content
};
break;
case 2:
viewData.type = msgTypeMap[2];
viewData.data = {
content: message.content
};
break;
case 10:
viewData.type = msgTypeMap[10];
viewData.data = {
orderCode: message.content[1],
cost: message.content[3],
createTime: message.content[5],
orderStatus: message.content[7],
};
break;
default:
return null;
}
return viewData;
},
/**
* 处理 接收到的信息
*/
handleReceiveMSG: function(rec) {
var recType = rec.type,
message = rec.message,
msgType = message.type,
allTypes = socketConf.recType;
var uuid = rec.uuid;
switch (recType) {
}
return this;
},
/**
* 订单消息
* @param object viewData 订单消息模版数据
* @param 【object|array] viewData 订单消息模版数据
*/
_drawMSG: function(viewData) {
let chatWin = this.$chatWin[0];
let html = this.messageT(viewData);
let $html = $(this.messageT(viewData));
this.$chatWin.append(html);
$html.appendTo(this.$chatWin);
chatWin.scrollTop = chatWin.scrollHeight;
return $html;
},
/**
... ... @@ -219,31 +345,17 @@ var chat = {
url: '/service/msghistory',
data: data,
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);
var arr = [];
result.forEach(message => {
let data = self.buildViewData(message);
if (data) {
arr.push(data);
}
}
});
self._drawMSG(arr);
cb();
}
});
... ... @@ -278,76 +390,6 @@ var chat = {
return this;
},
/**
* 处理 接收到的信息
*/
handleReceiveMSG: function(rec) {
var recType = rec.type,
message = rec.message,
msgType = message.type,
allTypes = socketConf.recType;
switch (recType) {
case allTypes.ENTER:
this.enterSuccess(message);
resizeFooter();
break;
case allTypes.LINK_SUCCESS:
this.linkSuccess(msgType, message);
break;
case allTypes.CU_SEND:
this.handleCusMsg(rec, msgType, message);
break;
// case allTypes.BREAK_TIME:
// breakCountdown(message);
// break;
case allTypes.ROBOT_SEND:
rec.csName = rec.csName || '客服机器人';
this._drawMSG({
type: 'text',
style: 'recevied-msg',
avatar: cmEntity.userHead,
data: {
msg: message.content,
}
});
resizeFooter();
break;
case allTypes.CS_SEND:
// 处理客服消息
this.handleCsMsg(rec, msgType, message);
break;
// case allTypes.EVAL_INVITE:
// // 客服发起
// processInfo.promoter = 2;
// showEvalModal();
// break;
// case allTypes.CS_CHATTING:
// // 正在人工会话
// csChatting(message);
// break;
case allTypes.OFFLINE:
append(time(Date.now()).show());
append(tip().offLine());
break;
default:
break;
}
},
// 刚进入提示
enterSuccess: function(message) {
append(time(Date.now()).show());
... ... @@ -401,49 +443,6 @@ var chat = {
chat.init();
// 用户发送消息
const sendMsg = function(type, content) {
let cfg = {
style: 'send-msg',
avatar: cmEntity.userHead,
};
if (!content) {
return;
} else {
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));
}
};
// 聊天区发送信息
$('.text-in').on('keydown', function(e) {
if (e.keyCode === 13) {
sendMsg(1, $(this).val());
$(this).val('');
}
});
// 触发菜单
$('.menu-trigger').on('touchend', function() {
let $menu = $('.menu');
... ...