Authored by zzzzzzz

获取10条记录完成

1 'use strict'; 1 'use strict';
2 2
3 const orderModel = require('../../home/models/order'); 3 const orderModel = require('../../home/models/order');
  4 +const crypto = global.yoho.crypto;
  5 +const indexModel = require('../../home/models/index');
  6 +const imApi = global.yoho.ImAPI;
4 7
5 exports.page = (req, res, next) => { 8 exports.page = (req, res, next) => {
6 - res.locals.module = 'service';  
7 - res.locals.page = 'chat';  
8 - res.locals.pageStyle = 'service-chat';  
9 - res.locals.width750 = true;  
10 -  
11 - res.render('chat/index'); 9 + res.render('chat/index', {
  10 + module: 'service',
  11 + page: 'chat',
  12 + pageStyle: 'service-chat',
  13 + width750: true,
  14 + encrypteduid: crypto.encryption('yoho9646abcdefgh', req.user.uid + '' || '0'),
  15 + });
12 }; 16 };
13 17
14 exports.getOrders = (req, res, next) => { 18 exports.getOrders = (req, res, next) => {
@@ -25,3 +29,24 @@ exports.getOrders = (req, res, next) => { @@ -25,3 +29,24 @@ exports.getOrders = (req, res, next) => {
25 }); 29 });
26 }).catch(next); 30 }).catch(next);
27 }; 31 };
  32 +
  33 +exports.userinfo = (req, res, next) => {
  34 + indexModel.myDetails(req.user.uid || 0).then(result => {
  35 + let ret = {
  36 + head: result.head_ico,
  37 + nickname: result.nickname,
  38 + };
  39 +
  40 + res.json(ret);
  41 + }).catch(next);
  42 +};
  43 +
  44 +exports.msghistory = (req, res, next) => {
  45 + console.log(req.query);
  46 + imApi.get('/api/conversationMessage/pageList', {
  47 + encryptedUid: req.query.encryptedUid,
  48 + method: ''
  49 + }).then(result => {
  50 + res.json(result);
  51 + });
  52 +};
@@ -16,6 +16,8 @@ const chatQa = require(`${cRoot}/chatQa`); // 问题搜索列表页 @@ -16,6 +16,8 @@ const chatQa = require(`${cRoot}/chatQa`); // 问题搜索列表页
16 // Your controller here 16 // Your controller here
17 router.get('/im/', chat.page); 17 router.get('/im/', chat.page);
18 router.get('/getOrders', chat.getOrders); 18 router.get('/getOrders', chat.getOrders);
  19 +router.get('/userinfo', chat.userinfo);
  20 +router.get('/msghistory', chat.msghistory);
19 21
20 router.get('/chatQaList', chatQa.qaList); // 问题搜索列表页 22 router.get('/chatQaList', chatQa.qaList); // 问题搜索列表页
21 router.get('/qaSearch', chatQa.qaSearch); // 问题搜索页 23 router.get('/qaSearch', chatQa.qaSearch); // 问题搜索页
@@ -56,4 +56,6 @@ @@ -56,4 +56,6 @@
56 56
57 {{> chat-comment}} 57 {{> chat-comment}}
58 {{> leave-msg}} 58 {{> leave-msg}}
59 -{{> order-list}}  
  59 +{{> order-list}}
  60 +
  61 +<input type="hidden" id="encrypteduid" value="{{encrypteduid}}">
@@ -14,17 +14,18 @@ module.exports = { @@ -14,17 +14,18 @@ module.exports = {
14 appVersion: '5.1.0', // 调用api的版本 14 appVersion: '5.1.0', // 调用api的版本
15 port: 6001, 15 port: 6001,
16 siteUrl: '//m.yohobuy.com', 16 siteUrl: '//m.yohobuy.com',
17 - assetUrl: '//localhost:5001', 17 + assetUrl: '//172.16.6.136:5001',
18 domains: { 18 domains: {
19 - // api: 'http://api-test3.yohops.com:9999/',  
20 - // service: 'http://service-test3.yohops.com:9999/',  
21 - // liveApi: 'http://testapi.live.yohops.com:9999/',  
22 - // singleApi: 'http://api-test3.yohops.com:9999/' 19 + api: 'http://api-test3.yohops.com:9999/',
  20 + service: 'http://service-test3.yohops.com:9999/',
  21 + liveApi: 'http://testapi.live.yohops.com:9999/',
  22 + singleApi: 'http://api-test3.yohops.com:9999/',
  23 + imApi: 'http://192.168.102.18:60101/api'
23 24
24 - api: 'http://api.yoho.cn/',  
25 - service: 'http://service.yoho.cn/',  
26 - liveApi: 'http://api.live.yoho.cn/',  
27 - singleApi: 'http://single.yoho.cn/' 25 + // api: 'http://api.yoho.cn/',
  26 + // service: 'http://service.yoho.cn/',
  27 + // liveApi: 'http://api.live.yoho.cn/',
  28 + // singleApi: 'http://single.yoho.cn/'
28 }, 29 },
29 subDomains: { 30 subDomains: {
30 host: '.m.yohobuy.com', 31 host: '.m.yohobuy.com',
@@ -17,7 +17,8 @@ var socket = require('./socket-chat'), @@ -17,7 +17,8 @@ var socket = require('./socket-chat'),
17 socketConf = require('./socket-config'), 17 socketConf = require('./socket-config'),
18 cmEntity = socketConf.conversationMessage; 18 cmEntity = socketConf.conversationMessage;
19 19
20 -const chatBox = $('#chat-window'); 20 +const chatBox = $('#chat-window'),
  21 + encryptedUid = $('#encrypteduid').val();
21 22
22 const append = (html) => { 23 const append = (html) => {
23 chatBox.append(html); 24 chatBox.append(html);
@@ -39,26 +40,54 @@ var chat = { @@ -39,26 +40,54 @@ var chat = {
39 init: function() { 40 init: function() {
40 const self = this; 41 const self = this;
41 42
42 - socket.init(Object.assign(socketConf, {  
43 - onMessage: function(e) {  
44 - var received = JSON.parse(e.data);  
45 - console.log(received);  
46 - cmEntity.conversationId = received.newConversationId > 0 ?  
47 - received.newConversationId :  
48 - received.conversationId;  
49 -  
50 - gg = new Customer(cmEntity.userHead);  
51 - mm = new Employee(cmEntity.userHead);  
52 - // 保存过程中信息  
53 - self.getMessage(received);  
54 - }  
55 - })); 43 + socketConf.conversationMessage.encryptedUid = encryptedUid;
  44 + $.ajax({
  45 + type: 'GET',
  46 + url: '/service/userinfo',
  47 + }).then(function(result) {
  48 + // 获取用户信息
  49 + gg = new Customer(result.head || cmEntity.userHead);
  50 + mm = new Employee(cmEntity.userHead);
  51 + self.fetchHistoryMsg(function() {
  52 + socket.init(Object.assign(socketConf, {
  53 + onMessage: function(e) {
  54 + var received = JSON.parse(e.data);
  55 + console.log(received);
  56 + cmEntity.conversationId = received.newConversationId > 0 ?
  57 + received.newConversationId :
  58 + received.conversationId;
  59 +
  60 + self.getMessage(received);
  61 + }
  62 + }));
  63 + });
  64 + });
56 }, 65 },
57 66
  67 + // 获取10条历史记录
  68 + fetchHistoryMsg: function() {
  69 + const self = this;
  70 +
  71 + var data = {
  72 + encryptedUid: encryptedUid,
  73 + };
  74 +
  75 + $.ajax({
  76 + type: 'GET',
  77 + url: '/service/msghistory',
  78 + data: data,
  79 + success: function(result) {
  80 + if (result && result.code === 200) {
  81 + for (let item of result.data) {
  82 + self.getMessage(item);
  83 + }
  84 + }
  85 + }
  86 + });
  87 + },
58 // 处理收到的消息 88 // 处理收到的消息
59 getMessage: function(rec) { 89 getMessage: function(rec) {
60 - var tipTpl,  
61 - recType = rec.type, 90 + var recType = rec.type,
62 message = rec.message, 91 message = rec.message,
63 msgType = message.type, 92 msgType = message.type,
64 allTypes = socketConf.recType; 93 allTypes = socketConf.recType;
@@ -88,10 +117,10 @@ var chat = { @@ -88,10 +117,10 @@ var chat = {
88 117
89 break; 118 break;
90 119
91 - // case allTypes.CS_SEND:  
92 - // // 处理客服消息  
93 - // handleCsMsg(rec, msgType, message);  
94 - // break; 120 + case allTypes.CS_SEND:
  121 + // 处理客服消息
  122 + this.handleCsMsg(rec, msgType, message);
  123 + break;
95 124
96 // case allTypes.EVAL_INVITE: 125 // case allTypes.EVAL_INVITE:
97 // // 客服发起 126 // // 客服发起
@@ -104,17 +133,10 @@ var chat = { @@ -104,17 +133,10 @@ var chat = {
104 // csChatting(message); 133 // csChatting(message);
105 // break; 134 // break;
106 135
107 - // case allTypes.OFFLINE:  
108 - // tipTpl =  
109 - // `<div class="list-item">  
110 - // <p class="push-tip">  
111 - // <span class="tip">  
112 - // ${message.content}  
113 - // <a class="red-tip reconnect">连线客服</a>  
114 - // </span>  
115 - // </p>  
116 - // </div>`;  
117 - // break; 136 + case allTypes.OFFLINE:
  137 + append(time(Date.now()).show());
  138 + append(tip().offLine());
  139 + break;
118 140
119 default: 141 default:
120 break; 142 break;
@@ -123,19 +145,22 @@ var chat = { @@ -123,19 +145,22 @@ var chat = {
123 }, 145 },
124 146
125 // 刚进入提示 147 // 刚进入提示
126 - enterSuccess: function() { 148 + enterSuccess: function(message) {
127 append(time(Date.now()).show()); 149 append(time(Date.now()).show());
128 append(tip().offLine()); 150 append(tip().offLine());
  151 + append(tip(message.content).onLine());
129 }, 152 },
130 153
131 // 连线人工客服 154 // 连线人工客服
132 linkSuccess: function(type, message) { 155 linkSuccess: function(type, message) {
133 var status = $('.chat-status'), 156 var status = $('.chat-status'),
134 - name = $('.service-name'); 157 + name = $('.service-name'),
  158 + comment = $('.chat-comment');
135 159
136 if (type === 2 || type === 3) { 160 if (type === 2 || type === 3) {
137 status.css('background', '#85be4a'); 161 status.css('background', '#85be4a');
138 name.text('YOHO!客服'); 162 name.text('YOHO!客服');
  163 + comment.css('display', 'inline-block');
139 append(tip(message.content).onLine()); 164 append(tip(message.content).onLine());
140 } else { 165 } else {
141 name.text('YOHO!客服'); 166 name.text('YOHO!客服');
@@ -150,6 +175,16 @@ var chat = { @@ -150,6 +175,16 @@ var chat = {
150 append(gg.sendMsg(message.content, true)); 175 append(gg.sendMsg(message.content, true));
151 } 176 }
152 resizeFooter(); 177 resizeFooter();
  178 + },
  179 +
  180 + // 客服发消息
  181 + handleCsMsg: function(rec, msgType, message) {
  182 + if (msgType === 2) {
  183 + append(mm.sendImg(message.content));
  184 + } else {
  185 + append(mm.sendMsg(message.content));
  186 + }
  187 + resizeFooter();
153 } 188 }
154 }; 189 };
155 190
@@ -167,8 +202,7 @@ const sendMsg = function(type, content) { @@ -167,8 +202,7 @@ const sendMsg = function(type, content) {
167 } 202 }
168 }; 203 };
169 204
170 -// 客户端接受消息  
171 - 205 +// 聊天区发送信息
172 $('.text-in').on('keydown', function(e) { 206 $('.text-in').on('keydown', function(e) {
173 if (e.keyCode === 13) { 207 if (e.keyCode === 13) {
174 sendMsg(1, $(this).val()); 208 sendMsg(1, $(this).val());
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 7
8 class Tip { 8 class Tip {
9 constructor(msg) { 9 constructor(msg) {
10 - this.uname = msg || ''; 10 + this.msg = msg || '';
11 } 11 }
12 12
13 offLine() { 13 offLine() {
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 } 50 }
51 51
52 .chat-comment { 52 .chat-comment {
53 - display: inline-block; 53 + display: none;
54 position: absolute; 54 position: absolute;
55 top: 0; 55 top: 0;
56 right: 30px; 56 right: 30px;