|
@@ -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());
|