Authored by zzzzzzz

获取10条记录完成

'use strict';
const orderModel = require('../../home/models/order');
const crypto = global.yoho.crypto;
const indexModel = require('../../home/models/index');
const imApi = global.yoho.ImAPI;
exports.page = (req, res, next) => {
res.locals.module = 'service';
res.locals.page = 'chat';
res.locals.pageStyle = 'service-chat';
res.locals.width750 = true;
res.render('chat/index');
res.render('chat/index', {
module: 'service',
page: 'chat',
pageStyle: 'service-chat',
width750: true,
encrypteduid: crypto.encryption('yoho9646abcdefgh', req.user.uid + '' || '0'),
});
};
exports.getOrders = (req, res, next) => {
... ... @@ -25,3 +29,24 @@ exports.getOrders = (req, res, next) => {
});
}).catch(next);
};
exports.userinfo = (req, res, next) => {
indexModel.myDetails(req.user.uid || 0).then(result => {
let ret = {
head: result.head_ico,
nickname: result.nickname,
};
res.json(ret);
}).catch(next);
};
exports.msghistory = (req, res, next) => {
console.log(req.query);
imApi.get('/api/conversationMessage/pageList', {
encryptedUid: req.query.encryptedUid,
method: ''
}).then(result => {
res.json(result);
});
};
... ...
... ... @@ -16,6 +16,8 @@ const chatQa = require(`${cRoot}/chatQa`); // 问题搜索列表页
// Your controller here
router.get('/im/', chat.page);
router.get('/getOrders', chat.getOrders);
router.get('/userinfo', chat.userinfo);
router.get('/msghistory', chat.msghistory);
router.get('/chatQaList', chatQa.qaList); // 问题搜索列表页
router.get('/qaSearch', chatQa.qaSearch); // 问题搜索页
... ...
... ... @@ -56,4 +56,6 @@
{{> chat-comment}}
{{> leave-msg}}
{{> order-list}}
\ No newline at end of file
{{> order-list}}
<input type="hidden" id="encrypteduid" value="{{encrypteduid}}">
\ No newline at end of file
... ...
... ... @@ -14,17 +14,18 @@ module.exports = {
appVersion: '5.1.0', // 调用api的版本
port: 6001,
siteUrl: '//m.yohobuy.com',
assetUrl: '//localhost:5001',
assetUrl: '//172.16.6.136:5001',
domains: {
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/'
api: 'http://api-test3.yohops.com:9999/',
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'
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/'
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/'
},
subDomains: {
host: '.m.yohobuy.com',
... ...
... ... @@ -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());
... ...
... ... @@ -7,7 +7,7 @@
class Tip {
constructor(msg) {
this.uname = msg || '';
this.msg = msg || '';
}
offLine() {
... ...
... ... @@ -50,7 +50,7 @@
}
.chat-comment {
display: inline-block;
display: none;
position: absolute;
top: 0;
right: 30px;
... ...