Authored by 陈轩

fix

... ... @@ -12,6 +12,7 @@ exports.page = (req, res, next) => {
page: 'chat',
pageStyle: 'service-chat',
width750: true,
imServer: global.yoho.config.domains.imserver,
encrypteduid: crypto.encryption('yoho9646abcdefgh', req.user.uid + '' || '0'),
});
};
... ...
... ... @@ -35,7 +35,7 @@
<p class="menu-name">拍照</p>
</div>
<div class="icon-wrap photo">
<input type="file" class="upload-img" style="position: absolute;right: -3px;top: -3px;z-index: 999;" accept="image/*">
<input type="file" name="filename" class="upload-img" style="position: absolute;right: -3px;top: -3px;z-index: 999;" accept="image/*">
<div class="icon"></div>
<p class="menu-name">相册</p>
</div>
... ... @@ -43,10 +43,10 @@
<div class="icon"></div>
<p class="menu-name">订单</p>
</div>
<div class="icon-wrap broad-order" data-trigger="order-list" data-param="international">
{{!--<div class="icon-wrap broad-order" data-trigger="order-list" data-param="international">
<div class="icon"></div>
<p class="menu-name">境外订单</p>
</div>
</div>--}}
</div>
</footer>
</div>
... ... @@ -56,3 +56,4 @@
{{> chat/order-list}}
<input type="hidden" id="encrypteduid" value="{{encrypteduid}}">
<input type="hidden" id="js-im" name="im-server" value="{{imServer}}">
\ No newline at end of file
... ...
... ... @@ -20,7 +20,8 @@ module.exports = {
service: 'http://service-test3.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
imApi: 'http://192.168.102.18:60101/api'
imApi: 'http://192.168.102.18:60101/api',
imserver: 'http://192.168.102.18:60201/imserver-web'
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
... ...
... ... @@ -35,9 +35,7 @@
{{#*inline 'picture'}}
<div class="msg-content msg-pic">
<span class="image">
<img src="{{content}}" alt="" class="chat-image">
</span>
<img src="{{content}}" alt="" class="image chat-image">
</div>
{{/inline}}
... ...
... ... @@ -36,6 +36,7 @@ const msgTypeMap = {
10: 'order'
};
const imServerURL= $('#js-im').val();
let lastServiceType = 'robot';
let lastMSGTime = null;
... ... @@ -87,7 +88,9 @@ var chat = {
let actions = {
onMessage: function(event) {
let received = JSON.parse(event.data);
console.log(received);
console.log('onMessage:');
console.table(received);
// update 会话id
cmEntity.conversationId = received.newConversationId > 0 ?
... ... @@ -166,8 +169,11 @@ var chat = {
window.addEventListener('offline', function() {
self._networkSick(true);
self.$chat.toggleClass('online', false);
});
// window.addEventListener('beforeunload', function() {});
// TODO
},
... ... @@ -194,6 +200,8 @@ var chat = {
msg.uid = uuid;
cmEntity.uuid = uuid;
cmEntity.type = socketConf.recType.CU_SEND;
switch (msg.type) {
case 'order':
arr = [
... ... @@ -297,6 +305,15 @@ var chat = {
var uuid = rec.uuid;
var viewData;
// 服务状态: 离线
if (
recType === allTypes.OFFLINE ||
recType === allTypes.OP_LEAVE ||
(recType === allTypes.MANUAL_SERVICE && msgType === 0)
) {
this.$chat.toggleClass('online', false);
}
switch (recType) {
// 客服消息
... ... @@ -310,16 +327,20 @@ var chat = {
// ------------------------------------------
// 1. 客服进入
case allTypes.CS_ENTER:
this.$chat.toggleClass('online', true);
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');
if (message.type === 0) { // 没有在线客服
this.$header.find('.js-service-txt').text('YOHO客服');
this.$chatWin.append(time(Date.now()).show());
this._sysInfo();
}
break;
case allTypes.CS_CHANGE_STATE:
this._sysInfo('TODO');
... ... @@ -341,7 +362,7 @@ var chat = {
viewData = [viewData];
}
console.log(viewData);
// console.log(viewData);
let $html = $(this.messageT(viewData));
this.checkTime();
... ... @@ -438,12 +459,8 @@ var chat = {
right: '<span data-action="change-human">人工客服</span>'
},
human: {
title: '<i class="chat-status"></i><span>YOHO!客服</span>',
title: '<i class="chat-status"></i><span class="js-service-txt">正在连接...</span>',
right: '<span data-trigger="rating">评价</span>'
},
link: {
title: '正在连接...',
right: ''
}
};
... ... @@ -474,6 +491,39 @@ $('.menu-trigger').on('click', function() {
resizeFooter();
});
let $upload = $('.upload-img');
$upload.on('change', function() {
var input = event.target;
var files = input.files;
var formData = new FormData();
formData.append('files', [files[0]]);
$.ajax({
type: 'POST',
url: `${imServerURL}/imServerURL`,
data: formData,
processData: false, // 告诉jQuery不要去处理发送的数据
contentType: false
}).done(function(res) {
if (res.code === 200) {
console.log(res)
// chat.sendMSG({
// type: 'picture',
// data: {
// content: Todo
// }
// });
}
})
.fail(function(res) {
chat._sysInfo('图片太大了')
});
});
// 图片放大
$('#chat-window').on('click', '.chat-image', function() {
... ...
... ... @@ -54,7 +54,8 @@ function sendMsg(msg) {
return;
}
if (socket.readyState === WebSocket.OPEN) {
console.log(msg);
console.log('websocket send: ');
console.table(JSON.parse(msg));
socket.send(msg);
} else {
console.log('The socket is not open.');
... ...
... ... @@ -107,4 +107,11 @@
.chat-page-hide {
transform: translate3d(100%, 0, 0);
}
/* 客服在线 */
.online {
.chat-status {
background-color: #4cd964;
}
}
}
... ...