")
111 | }
112 | },
113 |
114 | // 机器自动答复
115 | rebotReply : function(message){
116 | $("#msgShow").append("
"+message+"
");
117 | },
118 | // 广告回复
119 | adReply : function(message){
120 | $("#msgShow").append("
"+message+"
");
121 | $("#msgShow").append("
"+new Date().Format("yyyy-MM-dd hh:mm:ss")+"开始沟通
");
122 | },
123 | send : function(){
124 | var sendObj = $('#msgInput').children("div").children("p");
125 | if(editor.txt.html().trim()!=""){
126 | $("#msgShow").append("
")
127 | _websocket.send(sendObj.html());
128 | editor.txt.clear();
129 | }
130 | consumerSocket.moveCursorEnd();
131 | },
132 |
133 | initEmotion: function(){
134 | var a = [];
135 | for (var i = 1; i < 76; i++) {
136 | var temp = {};
137 | temp.alt="";
138 | temp.src="img/emotion/arclist/"+i+".gif";
139 | a.push(temp);
140 | }
141 | return a;
142 | }
143 |
144 | }
145 |
146 | // ================================================浏览器标题消息提示开始==========================================
147 | var isWindowFocus = true;
148 | function focusin() { isWindowFocus=true;}
149 | function focusout() { isWindowFocus=false;}
150 | // 注册焦点变化监听器
151 | if ("onfocusin" in document){// for IE
152 | document.onfocusin = focusin;
153 | document.onfocusout = focusout;
154 | } else {
155 | window.onblur = focusout;
156 | window.onfocus= focusin;
157 | }
158 |
159 | var flag = true;
160 | function flashTitle(){
161 | // 仅窗口不在焦点时闪烁title,回到焦点时停止闪烁并将title恢复正常
162 | if(isWindowFocus){// 当前处于焦点
163 | document.title="在线咨询";
164 | return;// 退出循环
165 | }
166 |
167 | if(flag){
168 | document.title="【您有新的消息】";
169 | flag = false;
170 | }else{
171 | document.title="【 】";
172 | flag = true;
173 | }
174 | setTimeout("flashTitle()",10); // 循环
175 | }
176 | // ================================================浏览器标题消息提示结束==========================================
177 |
178 |
179 | Date.prototype.Format = function (fmt) {
180 | var o = {
181 | "M+": this.getMonth() + 1, // 月份
182 | "d+": this.getDate(), // 日
183 | "h+": this.getHours(), // 小时
184 | "m+": this.getMinutes(), // 分
185 | "s+": this.getSeconds(), // 秒
186 | "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
187 | "S": this.getMilliseconds() // 毫秒
188 | };
189 | if (/(y+)/.test(fmt))
190 | fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
191 | for (var k in o)
192 | if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
193 | return fmt;
194 | }
195 |
--------------------------------------------------------------------------------
/src/main/resources/static/js/page/customerSocket.js:
--------------------------------------------------------------------------------
1 | var _websocket = null;
2 | // 当前聊天用户sessionId
3 | var selectedSessionId = null;
4 | // 当前聊天用户数
5 | var consumerlength = 0;
6 |
7 | var editor = null;
8 |
9 | $(function() {
10 | customerSocket.init();
11 | })
12 |
13 | var customerSocket = {
14 |
15 | init : function(){
16 | customerSocket.page();
17 | customerSocket.socket();
18 | },
19 |
20 | page : function(){
21 | win_width = $(document).width();
22 | win_height = $(document).height();
23 | $("#content").height(win_height - 70);
24 | $("#content_right").width(win_width - $("#content_left").outerWidth());
25 | $("#content_right_top").height($("#content_right").height()-300);
26 |
27 | $(window).resize(function(){
28 | $("#content").height($(window).height() - 70);
29 | $("#content_right").width($(document).width() - $("#content_left").outerWidth());
30 | $("#content_right_top").height($("#content_right").height()-300);
31 | });
32 |
33 | $(document).keydown(function(event) {
34 | if (event.keyCode == 13) {
35 | event.preventDefault();
36 | customerSocket.send();
37 | }
38 | });
39 |
40 | customerSocket.emotion();
41 | },
42 |
43 | emotion : function(){
44 | var E = window.wangEditor
45 | editor = new E('#input_menu','#msgInput');
46 | editor.customConfig.menus = [
47 | 'emoticon',
48 | 'fontName',
49 | 'fontSize',
50 | 'bold',
51 | 'italic',
52 | 'underline',
53 | 'foreColor',
54 | 'image'
55 | ];
56 | editor.customConfig.uploadImgShowBase64 = true;
57 | editor.customConfig.emotions = [{
58 | title: '表情',
59 | type: 'image',
60 | content: customerSocket.initEmotion()
61 | }];
62 | editor.customConfig.onfocus = function () {
63 | customerSocket.readMessage();
64 | };
65 | editor.create();
66 | },
67 |
68 | initEmotion: function(){
69 | var a = [];
70 | for (var i = 1; i < 76; i++) {
71 | var temp = {};
72 | temp.alt="";
73 | temp.src="img/emotion/arclist/"+i+".gif";
74 | a.push(temp);
75 | }
76 | return a;
77 | },
78 |
79 | socket : function() {
80 |
81 | if ('WebSocket' in window) {
82 | _websocket = new WebSocket("ws://10.101.2.214:8080/websocket/customer/null");
83 | } else {
84 | alert("当前浏览器不支持WebSocket")
85 | }
86 |
87 | // 连接发生错误时回调
88 | _websocket.onerror = function(event) {
89 | console.log(event.data);
90 | };
91 |
92 | // 建立连接时回调
93 | _websocket.onopen = function(event) {
94 |
95 | }
96 |
97 | // 接收到消息时回调
98 | _websocket.onmessage = function(event) {
99 | flashTitle();
100 | customerSocket.recevie(event.data);
101 | customerSocket.moveCursorEnd();
102 | }
103 |
104 | // 连接关闭时回调
105 | _websocket.onclose = function(event) {
106 | //alert("连接已关闭")
107 | }
108 | },
109 | moveCursorEnd : function(){// 移动光标到最低端
110 | $("#content_right_top").children("div:visible").children("div")[[$("#content_right_top").children("div:visible").children("div").length-1]].scrollIntoView();
111 | },
112 | recevie : function(data){
113 | var json = JSON.parse(data);
114 | if (json.messageType==2) {// 下线消息
115 | customerSocket.offlineConsumer(json);
116 | } else {// 输出消息
117 | customerSocket.addConsumerList(json);
118 | }
119 | },
120 |
121 | send : function(){
122 | var sendObj = $('#msgInput').children("div").children("p");
123 | if(editor.txt.html()!=""){
124 | customerSocket.showMessageTab(sendObj.html(),selectedSessionId);
125 | _websocket.send(JSON.stringify({
126 | "sessionId" : selectedSessionId,
127 | "message" : sendObj.html()
128 | }));
129 | editor.txt.clear();
130 | }
131 | customerSocket.moveCursorEnd();
132 | },
133 |
134 | addConsumerList:function(json){
135 | if (!($("#list_div_" + json.sessionId).length > 0)){//客户列表去重
136 | consumerlength++;// 记录当前聊天用户数
137 | if($("#content_left").find("div").length>0){
138 | $("#content_left").append("
编号"+json.sessionId+"用户");
139 | }else{
140 | $("#content_left").append("
编号"+json.sessionId+"用户");
141 | }
142 | $("#list_div_"+json.sessionId).append("
");
143 | }
144 | customerSocket.recevieMessageTab(json);
145 | },
146 |
147 | recevieMessageTab : function(json){
148 | var html = "";
149 |
150 | if($("#msg_div_"+json.sessionId).length>0){
151 | html += "
";
152 | html += "
"+json.message+"
"
153 | html += "
";
154 | $("#msg_div_"+json.sessionId).append(html);
155 | }else{
156 | if(consumerlength==1){
157 | html += "
";
158 | selectedSessionId = json.sessionId;
159 | }else{
160 | html += "
";
161 | }
162 | html += "
";
163 | html += "
"+json.message+"
"
164 | html += "
";
165 | html += "
";
166 | $("#content_right_top").append(html);
167 | }
168 |
169 | // 设置信息数和消息提示
170 | var old_m = $("#list_div_" + json.sessionId).attr("msg_num");
171 | var new_m = parseInt(old_m) + 1;
172 | $("#list_div_" + json.sessionId).attr("msg_num",new_m);
173 | customerSocket.messageTip(json);
174 | },
175 |
176 | //设置消息提示
177 | messageTip:function(json){
178 | $("#msgTip_"+json.sessionId).show();
179 | $("#msgTip_"+json.sessionId).html($("#list_div_" + json.sessionId).attr("msg_num"));
180 | },
181 |
182 | // 在客户列表点击用户
183 | clickConsumer:function(sessionId,obj){
184 | selectedSessionId = sessionId;
185 | // tab页设置
186 | $("#content_right_top").children("div").hide();
187 | $("#msg_div_"+sessionId).show();
188 | // 客户列表设置
189 | $("#content_left").children("div").removeClass("selected");
190 | $(obj).addClass("selected");
191 |
192 | customerSocket.readMessage(sessionId);
193 | },
194 |
195 | // 鼠标移到列表上,显示删除ICO
196 | showRemoveIco :function(session_id,obj){
197 | $("#label_remove_"+session_id).show();
198 | },
199 | // 鼠标移到列表上,隐藏删除ICO
200 | hideRemoveIco :function(session_id,obj){
201 | $("#label_remove_"+session_id).hide();
202 | },
203 |
204 | // 删除列表用户
205 | deleteConsumerList : function(session_id,obj){
206 | $("#list_div_"+session_id).remove();
207 | $("#msg_div_"+session_id).remove();
208 |
209 | $("#content_left").children("div:first").addClass("selected");
210 | $("#content_right_top").children("div:first").show();
211 | event.stopPropagation();
212 | },
213 |
214 | // 消息已读,去除红点提示
215 | readMessage : function(sessionId) {
216 | if(sessionId){
217 | $("#msgTip_"+sessionId).hide();
218 | $("#list_div_" + sessionId).attr("msg_num",0);
219 | }else{
220 | $("#msgTip_"+selectedSessionId).hide();
221 | $("#list_div_" + selectedSessionId).attr("msg_num",0);
222 | }
223 | },
224 |
225 | // 用户下线消息处理:1.图像置灰 2.在列表中往后排
226 | offlineConsumer : function(json){
227 |
228 | },
229 |
230 | // 客服自己发送的消息显示在tab页面上
231 | showMessageTab : function(message,consumerSessionId){
232 | var html = "";
233 | html += "
";
234 | html += "
"+message+"
"
235 | html += "
";
236 | $("#msg_div_"+consumerSessionId).append(html);
237 | }
238 |
239 | }
240 |
241 |
242 | //================================================浏览器标题消息提示开始==========================================
243 | var isWindowFocus = true;
244 | function focusin() { isWindowFocus=true;}
245 | function focusout() { isWindowFocus=false;}
246 | //注册焦点变化监听器
247 | if ("onfocusin" in document){//for IE
248 | document.onfocusin = focusin;
249 | document.onfocusout = focusout;
250 | } else {
251 | window.onblur = focusout;
252 | window.onfocus= focusin;
253 | }
254 |
255 | var flag = true;
256 | function flashTitle(){
257 | //仅窗口不在焦点时闪烁title,回到焦点时停止闪烁并将title恢复正常
258 | if(isWindowFocus){//当前处于焦点
259 | document.title="客服";
260 | return;//退出循环
261 | }
262 |
263 | if(flag){
264 | document.title="【您有新的消息】";
265 | flag = false;
266 | }else{
267 | document.title="【 】";
268 | flag = true;
269 | }
270 | setTimeout("flashTitle()",10); //循环
271 | }
272 | //================================================浏览器标题消息提示结束==========================================
273 |
274 |
275 | Date.prototype.Format = function (fmt) {
276 | var o = {
277 | "M+": this.getMonth() + 1, // 月份
278 | "d+": this.getDate(), // 日
279 | "h+": this.getHours(), // 小时
280 | "m+": this.getMinutes(), // 分
281 | "s+": this.getSeconds(), // 秒
282 | "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
283 | "S": this.getMilliseconds() // 毫秒
284 | };
285 | if (/(y+)/.test(fmt))
286 | fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
287 | for (var k in o)
288 | if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
289 | return fmt;
290 | }
--------------------------------------------------------------------------------
/src/main/resources/static/js/page/index.js:
--------------------------------------------------------------------------------
1 | $(function() {
2 |
3 | })
4 |
5 | var _index = {
6 |
7 | CloseAd : function() {// 关闭广告推送
8 | $.ajax({
9 | url : "/contorAd",
10 | dataType : "json",
11 | success : function(data) {
12 | if (JSON.parse(data)) {
13 | $("#ad").text("close Ad");
14 | } else {
15 | $("#ad").text("open Ad");
16 | }
17 | }
18 | })
19 | },
20 | CloseAuto : function() {// 关闭自动回复
21 | $.ajax({
22 | url : "/contorAuto",
23 | dataType : "json",
24 | success : function(data) {
25 | if (JSON.parse(data)) {
26 | $("#auto").text("close Reply");
27 | } else {
28 | $("#auto").text("open Reply");
29 | }
30 | }
31 | })
32 | },
33 | setInfo : function(type) {// 设置信息:自动回复/广告
34 | if (type == 1) {// 广告
35 | window.location.href = "/editAd";
36 | } else {// 自动回复
37 | window.location.href = "/editReply";
38 | }
39 | },
40 | }
--------------------------------------------------------------------------------
/src/main/resources/static/js/socket.js:
--------------------------------------------------------------------------------
1 | /**
2 | * socket
3 | */
4 |
5 | var _websocket = null;
6 |
7 | var _socket = {
8 | init : function(url) {
9 | if ('WebSocket' in window) {
10 | _websocket = new WebSocket(url);
11 | } else {
12 | alert("当前浏览器不支持WebSocket")
13 | }
14 |
15 | // 连接发生错误时回调
16 | _websocket.onerror = function(event) {
17 |
18 | };
19 |
20 | // 建立连接时回调
21 | _websocket.onopen = function(event) {
22 |
23 | }
24 |
25 | // 接收到消息时回调
26 | _websocket.onmessage = function(event) {
27 | var json = JSON.parse(event.data);
28 | // 输出event.data信息到页面
29 | $('#text').append(json.message).append('\n');
30 |
31 | $('#sessionIdList').append(
32 | "
");
34 | }
35 |
36 | // 连接关闭时回调
37 | _websocket.onclose = function(event) {
38 | // 调用websocket.close()或关闭页面时
39 | }
40 | },
41 | send : function() {
42 | _websocket.send($('#text').val());
43 | }
44 | }
--------------------------------------------------------------------------------
/src/main/resources/static/js/wangEditor.min.js:
--------------------------------------------------------------------------------
1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.wangEditor=t()}(this,function(){"use strict";function e(e){var t=void 0;return t=document.createElement("div"),t.innerHTML=e,t.children}function t(e){return!!e&&(e instanceof HTMLCollection||e instanceof NodeList)}function n(e){var n=document.querySelectorAll(e);return t(n)?n:[n]}function i(o){if(o){if(o instanceof i)return o;this.selector=o;var A=o.nodeType,r=[];9===A?r=[o]:1===A?r=[o]:t(o)||o instanceof Array?r=o:"string"==typeof o&&(o=o.replace("/\n/mg","").trim(),r=0===o.indexOf("<")?e(o):n(o));var c=r.length;if(!c)return this;var a=void 0;for(a=0;a
/gm,">").replace(/"/gm,""").replace(/(\r\n|\r|\n)/g,"
")}function s(e){return"function"==typeof e}function l(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function d(e,t){var n=this,i=e.editor;this.menu=e,this.opt=t;var A=o(''),r=t.$title,c=void 0;r&&(c=r.html(),c=O(i,c),r.html(c),r.addClass("w-e-dp-title"),A.append(r));var a=t.list||[],s=t.type||"list",l=t.onClick||$,d=o('');A.append(d),a.forEach(function(e){var t=e.$elem,A=t.html();A=O(i,A),t.html(A);var r=e.value,c=o('');t&&(c.append(t),d.append(c),c.on("click",function(e){l(r),n.hideTimeoutId=setTimeout(function(){n.hide()},0)}))}),A.on("mouseleave",function(e){n.hideTimeoutId=setTimeout(function(){n.hide()},0)}),this.$container=A,this._rendered=!1,this._show=!1}function u(e){var t=this;this.editor=e,this.$elem=o(''),this.type="droplist",this._active=!1,this.droplist=new d(this,{width:100,$title:o("设置标题
"),type:"list",list:[{$elem:o("H1
"),value:""},{$elem:o("H2
"),value:""},{$elem:o("H3
"),value:""},{$elem:o("H4
"),value:""},{$elem:o("H5
"),value:""},{$elem:o("
正文
"),value:""}],onClick:function(e){t._command(e)}})}function h(e){var t=this;this.editor=e,this.$elem=o('
'),this.type="droplist",this._active=!1,this.droplist=new d(this,{width:160,$title:o("字号
"),type:"list",list:[{$elem:o('x-small'),value:"1"},{$elem:o('small'),value:"2"},{$elem:o("normal"),value:"3"},{$elem:o('large'),value:"4"},{$elem:o('x-large'),value:"5"},{$elem:o('xx-large'),value:"6"}],onClick:function(e){t._command(e)}})}function p(e){var t=this;this.editor=e,this.$elem=o(''),this.type="droplist",this._active=!1;var n=e.config,i=n.fontNames||[];this.droplist=new d(this,{width:100,$title:o("字体
"),type:"list",list:i.map(function(e){return{$elem:o(''+e+""),value:e}}),onClick:function(e){t._command(e)}})}function f(e,t){this.menu=e,this.opt=t}function m(e){this.editor=e,this.$elem=o(''),this.type="panel",this._active=!1}function g(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function w(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function v(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function E(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function b(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function B(e){var t=this;this.editor=e,this.$elem=o(''),this.type="droplist",this._active=!1,this.droplist=new d(this,{width:120,$title:o("设置列表
"),type:"list",list:[{$elem:o(' 有序列表'),value:"insertOrderedList"},{$elem:o(' 无序列表'),value:"insertUnorderedList"}],onClick:function(e){t._command(e)}})}function y(e){var t=this;this.editor=e,this.$elem=o(''),this.type="droplist",this._active=!1,this.droplist=new d(this,{width:100,$title:o("对齐方式
"),type:"list",list:[{$elem:o(' 靠左'),value:"justifyLeft"},{$elem:o(' 居中'),value:"justifyCenter"},{$elem:o(' 靠右'),value:"justifyRight"}],onClick:function(e){t._command(e)}})}function C(e){var t=this;this.editor=e,this.$elem=o(''),this.type="droplist";var n=e.config,i=n.colors||[];this._active=!1,this.droplist=new d(this,{width:120,$title:o("文字颜色
"),type:"inline-block",list:i.map(function(e){return{$elem:o(''),value:e}}),onClick:function(e){t._command(e)}})}function x(e){var t=this;this.editor=e,this.$elem=o(''),this.type="droplist";var n=e.config,i=n.colors||[];this._active=!1,this.droplist=new d(this,{width:120,$title:o("背景色
"),type:"inline-block",list:i.map(function(e){return{$elem:o(''),value:e}}),onClick:function(e){t._command(e)}})}function I(e){this.editor=e,this.$elem=o(''),this.type="click",this._active=!1}function Q(e){this.editor=e,this.$elem=o(''),this.type="panel",this._active=!1}function M(e){this.editor=e,this.$elem=o(''),this.type="panel",this._active=!1}function S(e){this.editor=e,this.$elem=o(''),this.type="panel",this._active=!1}function k(e){this.editor=e,this.$elem=o(''),this.type="panel",this._active=!1}function D(e){this.editor=e;var t=c("w-e-img");this.$elem=o(''),e.imgMenuId=t,this.type="panel",this._active=!1}function _(e){this.editor=e,this.menus={}}function N(e){var t=e.clipboardData||e.originalEvent&&e.originalEvent.clipboardData,n=void 0;return n=null==t?window.clipboardData&&window.clipboardData.getData("text"):t.getData("text/plain"),a(n)}function F(e,t,n){var i=e.clipboardData||e.originalEvent&&e.originalEvent.clipboardData,o=void 0,A=void 0;if(null==i?o=window.clipboardData&&window.clipboardData.getData("text"):(o=i.getData("text/plain"),A=i.getData("text/html")),!A&&o&&(A=""+a(o)+"
"),A){var r=A.split("