Authored by 陈轩

fix

{{#each .}}
<div class="msg-wrap {{style from}}" data-uuid={{uuid}}>
<img src="{{avatar}}" alt="" class="head-icon">
<div class="chat-info">
{{#data}}
{{> (lookup .. 'type')}}
{{/data}}
<div class="chat-info clearfix">
{{#with data}}
{{> (lookup .. 'type')}}
{{/with}}
<i class="msg-status iconfont"></i>
</div>
</div>
{{/each}}
... ... @@ -12,7 +13,7 @@
{{!--inline partails--}}
{{#*inline 'order'}}
<div class="chat-order">
<div class="msg-content msg-order">
<img src="{{imgSrc}}">
<div class="order-info">
<span class="label">订单号: </span><span>{{orderCode}}</span><br>
... ... @@ -24,17 +25,16 @@
{{/inline}}
{{#*inline 'text'}}
<div class="chat-txt">
{{#sending}}
<div class="msg-content msg-txt">
{{!--{{#sending}}
<i class="send-status send-loading">!</i>
{{/sending}}
{{/sending}}--}}
<span>{{{content}}}</span>
</div>
{{/inline}}
{{#*inline 'picture'}}
<div class="chat-pic">
<i class="send-fail">!</i>
<div class="msg-content msg-pic">
<span class="image">
<img src="{{content}}" alt="" class="chat-image">
</span>
... ... @@ -45,10 +45,4 @@
<div class="chat-voice">
TODO
</div>
{{/inline}}
{{#*inline 'system'}}
<div class="">
</div>
{{/inline}}
\ No newline at end of file
... ...
... ... @@ -5,22 +5,13 @@
'use strict';
import {
time
} from './time';
import {
tip
} from './tip';
import {
RatingView,
LeaveMSGView,
OrderListView
} from './view';
import {time} from './time';
import {RatingView, LeaveMSGView, OrderListView } from './view';
var socket = require('./socket-chat'),
socketConf = require('./socket-config'),
cmEntity = socketConf.conversationMessage,
lastTimeShow = 0;
socketConf = require('./socket-config');
var cmEntity = socketConf.conversationMessage;
const chatBox = $('#chat-window'),
encryptedUid = $('#encrypteduid').val();
... ... @@ -38,12 +29,15 @@ const resizeFooter = () => {
chatBox[0].scrollTop = chatBox[0].scrollHeight;
};
// 配置
const msgTypeMap = {
1: 'text',
2: 'picture',
10: 'order'
};
let lastServiceType = 'robot';
let lastMSGTime = null;
var userAvatar = socketConf.defaultUserHead;
... ... @@ -53,10 +47,6 @@ var chat = {
$netTip: null,
msgArr: [],
state: {
lastMSGTime: ''
},
$ratingView: $('#chat-comment'),
... ... @@ -142,8 +132,9 @@ var chat = {
content: $.trim(event.target.value)
}
};
console.log(content)
self.sendMSG(content);
event.target.value = '';
}
});
... ... @@ -165,7 +156,7 @@ var chat = {
conversationId: cmEntity.conversationId,
});
}).on('rating-success', function(e, data) {
append(tip(`您对我们的服务评价为:${data}`).onLine());
self._sysInfo(`您对我们的服务评价为:${data}`);
resizeFooter();
});
... ... @@ -230,7 +221,6 @@ var chat = {
let $msg = this._drawMSG(msg);
this.msgArr.push($msg);
socket.send(JSON.stringify(cmEntity));
return this;
... ... @@ -317,18 +307,31 @@ var chat = {
break;
// 系统消息
case allTypes.OFFLINE: break;
case allTypes.TRANSFER: break;
case allTypes.MANUAL_SERVICE: break;
case allTypes.CS_CHANGE_STATE: break;
// ------------------------------------------
// 1. 客服进入
case allTypes.CS_ENTER:
this.sysInfo('客服小YO正在为您服务');
break;
case allTypes.OFFLINE:
this.sysInfo('TODO');
break;
case allTypes.TRANSFER:
this.sysInfo('TODO');
break;
case allTypes.MANUAL_SERVICE:
this.sysInfo('TODO');
break;
case allTypes.CS_CHANGE_STATE:
this.sysInfo('TODO');
break;
default: break;
}
return this;
},
/**
* 订单消息
* 对话消息
* @param 【object|array] viewData 订单消息模版数据
*/
_drawMSG: function(viewData) {
... ... @@ -341,6 +344,7 @@ var chat = {
console.log(viewData);
let $html = $(this.messageT(viewData));
this.checkTime();
$html.appendTo(this.$chatWin);
chatWin.scrollTop = chatWin.scrollHeight;
... ... @@ -348,6 +352,32 @@ var chat = {
},
/**
* 系统消息
*/
_sysInfo: function(msg) {
let $chatWin = this.$chatWin;
let chatWin = $chatWin[0];
if (msg) {
msg = `<div class="change-mm">
<span class="leave-msg">${msg}</span>
</div>`;
} else {
msg = `<div class="leave-msg-wraper">
<span class="leave-msg">您可以选择<a href="javascript:;" data-trigger="leave-msg">留言</a>,客服会以短信形式回复您</span>
</div>`;
}
this.checkTime();
$chatWin.append(msg);
chatWin.scrollTop = chatWin.scrollHeight;
},
checkTime: $.noop,
/**
* method: 根据网络状态 处理动作
* @param {boolean} isSick
*/
... ... @@ -388,6 +418,13 @@ var chat = {
switchService: function(type) {
this.renderHeader(type);
if (type === 'human') {
cmEntity.type = socketConf.recType.MANUAL_SERVICE;
socket.send(JSON.stringify(cmEntity));
} else {
//TODO 切换rebot
}
},
/**
... ... @@ -422,51 +459,8 @@ var chat = {
// 刚进入提示
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'),
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!客服');
}
},
// 用户发消息
handleCusMsg: function(rec, msgType, message) {
// 消去状态
},
// 客服发消息
handleCsMsg: function(rec, msgType, message) {
let cfg = {
style: 'recevied-msg',
avatar: cmEntity.userHead,
};
if (msgType === 2) {
cfg.type = 'picture';
cfg.data = {
src: message.content,
};
} else {
cfg.type = 'text';
cfg.data = {
msg: message.content,
};
}
this._drawMSG(cfg);
resizeFooter();
self._sysInfo();
self._sysInfo(message.content);
}
};
... ... @@ -497,3 +491,4 @@ $('#chat-window').on('click', '.chat-image', function() {
window.$ = $;
window.chat = chat;
window.cmEntity = cmEntity
... ...
... ... @@ -40,7 +40,7 @@ var config = {
sessionId: '',
encryptedUid: 0,
userHead: '//img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif', // 用户头像
userName: '18551982892', // 用户账号
userName: '', // 用户账号
csId: 0,
type: 1,
serviceSortId: 0,
... ...
... ... @@ -11,13 +11,6 @@
position: relative;
overflow: hidden;
span {
display: inline-block;
padding: 25px 35px;
font-size: 28px;
word-break: break-all;
border-radius: 10px;
}
span.image {
padding: 15px;
... ... @@ -29,6 +22,26 @@
}
}
.msg-content {
display: inline-block;
padding: 25px 35px;
font-size: 28px;
word-break: break-all;
border-radius: 10px;
&.msg-txt {
}
&.msg-pic {
}
&.msg-order {
}
}
.fake-img-wrap {
display: none;
position: fixed;
... ... @@ -56,9 +69,9 @@
}
.send-msg {
text-align: right;
span {
.msg-content {
float: right;
margin: 0 12px 0 0;
background: #fff;
color: #444;
... ... @@ -84,33 +97,46 @@
}
.send-status {
}
.msg-status {
float: right;
display: inline-block;
height: 30px;
width: 30px;
height: 34px;
width: 34px;
margin-right: 10px;
font-size: 28px;
line-height: 30px;
line-height: 34px;
text-align: center;
color: transparent;
border-radius: 50%;
}
.send-fail {
background: #ff575c;
color: #fff;
&.send-fail .msg-status{
color: #ff575c;
&:after {
content: '\e61f'
}
}
.send-loading {
&.send-loading .msg-status{
color: transparent;
background-image: resolve("service/chat/loading.gif");
background-size: 100% 100%;
}
}
.send-msg-status {
}
.recevied-msg {
.head-icon {
float: left;
}
span {
.msg-content {
margin: 0 0 0 10px;
background: #888;
color: #fff;
... ... @@ -131,7 +157,7 @@
}
}
.chat-order {
.msg-order {
padding: 25px 35px;
background: #fff;
margin: 0 12px 0 0;
... ...