提交 | 用户 | age
|
0e86df
|
1 |
var wsOnTimers=null; |
F |
2 |
var layerMaintenanceIndex=null; |
6fe1e6
|
3 |
function initWebsocket(hostUrl,userCode,dbId,sessionId,userType) { |
a6a76f
|
4 |
// 初始化weosocket |
6fe1e6
|
5 |
var userFromType=1; |
F |
6 |
if(userType!=undefined) userFromType=userType; |
a6a76f
|
7 |
var localHostUrl = hostUrl; |
F |
8 |
var localUserCode = userCode ; |
|
9 |
var localDbId = dbId; |
|
10 |
var localSessionId = sessionId ; |
e98f5c
|
11 |
if(localUserCode==null||localUserCode==""||localUserCode=="null") localUserCode="temp_userCode_"+Math.random(); |
F |
12 |
if(localDbId==null||localDbId==""||localDbId=="null") localDbId=Math.floor(Math.random() * (10000 - 2000)) + 2000; |
|
13 |
if(localUserCode==null||localUserCode==""||localUserCode=="null") localUserCode="temp_session_"+Math.random(); |
6fe1e6
|
14 |
var info = '/ws/websocketMessage/'+localUserCode + '/'+ localDbId+'/' + localSessionId+'/'+userFromType ; |
a6a76f
|
15 |
var url = localHostUrl + info ; |
F |
16 |
websocket = new WebSocket(url); |
|
17 |
|
0e86df
|
18 |
websocket.onopen = function (e) { |
a6a76f
|
19 |
// 连接建立之后执行 |
0e86df
|
20 |
console.log('WebSocket连接成功'); |
F |
21 |
if(wsOnTimers!=null){ |
|
22 |
//console.log("onOpen-wsOnTimers:"+wsOnTimers); |
|
23 |
clearInterval(wsOnTimers); |
|
24 |
wsOnTimers=null; |
|
25 |
} |
a6a76f
|
26 |
} |
F |
27 |
|
|
28 |
websocket.onerror = function (e) { |
0e86df
|
29 |
/* timeron=setInterval(function () { |
F |
30 |
//这里会定时3秒执行一次,直到成功为止,条件是timeron==null; |
|
31 |
if(timeron!=null) { |
|
32 |
console.log(timeron + ',onError,30秒后重连', e); |
|
33 |
initWebsocket(localHostUrl, localUserCode, localDbId, localSessionId, userType); |
|
34 |
} |
|
35 |
}, 30000);*/ |
a6a76f
|
36 |
}; |
F |
37 |
|
|
38 |
websocket.onclose = function (e) { |
0e86df
|
39 |
wsOnTimers=setInterval(function () { |
F |
40 |
//这里会定时3秒执行一次,直到成功为止,条件是timeron==null; |
|
41 |
if(wsOnTimers!=null) { |
|
42 |
console.log(wsOnTimers + ',onClose,10秒后重连', e); |
|
43 |
initWebsocket(localHostUrl, localUserCode, localDbId, localSessionId, userType); |
|
44 |
} |
|
45 |
}, 10000); |
|
46 |
// console.log("wsOnTimers:"+wsOnTimers); |
a6a76f
|
47 |
}; |
F |
48 |
|
|
49 |
|
|
50 |
// 接收消息 |
|
51 |
websocket.onmessage = function (e) { |
6fe1e6
|
52 |
var json= JSON.parse(e.data); |
e98f5c
|
53 |
if(json.info.msgType==6014||json.info.msgType==6015){ |
6fe1e6
|
54 |
//重定向到登录页面 |
c86295
|
55 |
setTimeout(function (){ |
F |
56 |
location="/login.jsp"; |
|
57 |
},500); |
|
58 |
|
6fe1e6
|
59 |
}else if(json.info.msgType==6002){ |
F |
60 |
//右下角弹窗 |
c86295
|
61 |
//console.log('接收消息', json); |
F |
62 |
popMessage(json.info.msg); |
0e86df
|
63 |
}else if(json.info.msgType==6999){ |
F |
64 |
//显示维护界面 |
|
65 |
if(layerMaintenanceIndex==null) { |
|
66 |
layerMaintenanceIndex = layer.open({ |
|
67 |
title: '系统维护', |
|
68 |
type: 0, |
|
69 |
resize: false, |
|
70 |
area: ['800px', '600px'], |
|
71 |
btn: null, |
|
72 |
// closeBtn: 0, |
|
73 |
// cancel: function(){ |
|
74 |
// layerMaintenanceIndex=null; |
|
75 |
// }, |
|
76 |
content: '<img style="width: 800px" src="/images/maintenance.jpg">' |
|
77 |
}); |
|
78 |
} |
|
79 |
}else if(json.info.msgType==6998){ |
|
80 |
//关闭维护界面 |
|
81 |
if(layerMaintenanceIndex!=null){ |
|
82 |
layer.close(layerMaintenanceIndex); |
|
83 |
layerMaintenanceIndex=null; |
|
84 |
} |
6fe1e6
|
85 |
} |
F |
86 |
// console.log('接收消息', json); |
a6a76f
|
87 |
} |
c86295
|
88 |
} |
F |
89 |
var popflag=false; |
|
90 |
function popMessage(message){ |
|
91 |
var json=JSON.parse(message); |
|
92 |
var message6002=""; |
|
93 |
var colt=0; |
|
94 |
var zong=1; |
|
95 |
for(var i=0;i<json.length;i++){ |
|
96 |
|
|
97 |
if(json[i]["isPublicUser"]==1){ |
|
98 |
funB6003(json[i]); |
|
99 |
}else{ |
|
100 |
message6002+=getMessage6002(json[i],colt,zong); |
|
101 |
colt++; |
|
102 |
zong++; |
|
103 |
} |
|
104 |
} |
d9236e
|
105 |
if(message6002!="") { |
F |
106 |
funB6002(message6002); |
|
107 |
} |
c86295
|
108 |
} |
F |
109 |
function messageToString(obj) { |
|
110 |
if(obj==null) |
|
111 |
return ""; |
|
112 |
else |
|
113 |
return obj+""; |
|
114 |
} |
|
115 |
function getMessage6002(entity,colt,zong) { |
|
116 |
var message=""; |
|
117 |
var Bcolor=""; |
|
118 |
var messagetxt =entity["messagetxt"].replaceAll("(\\n|\\r|(\\r\\n)|(\u0085)|(\u2028)|(\u2029))",""); |
|
119 |
if (colt % 2 == 0) { |
|
120 |
Bcolor = "background:#FFFFFF;"; |
|
121 |
} else { |
|
122 |
Bcolor = "background:#DDDDDD;"; |
|
123 |
} |
|
124 |
if (entity["formid"] != undefined) { |
|
125 |
message="<div style=" + Bcolor + "><a id="+entity["messid"]+" style=line-height:15pt;cursor:pointer;text-decoration:underline; onClick=funcLink('"+entity["formid"]+"','"+entity["formtype"]+"','"+messageToString(entity["origfields"]).replace("'", "")+"','"+messageToString(entity["linkfields"]).replace("'", "")+"','"+entity["linkmode"]+"','"+messageToString(entity["self_datafields"])+"','"+messageToString(entity["link_datafields"])+"','"+"','"+messageToString(entity["efilter"]).replace("'", "\\'")+"','"+"','"+"','"+"','"+"','"+"','"+entity["messid"]+",message');>"+zong + ": "+messagetxt+"</a></div>"; |
|
126 |
} else if (entity["url"]!=undefined&&entity["url"]!="") { |
|
127 |
var url = ""; |
|
128 |
if (entity["url"].indexOf("http://")<0) { |
|
129 |
url = "http://" + entity["url"]; |
|
130 |
} else { |
|
131 |
url = entity["url"]; |
|
132 |
} |
|
133 |
message="<div style=" + Bcolor + "><a style=line-height:15pt;cursor:pointer;text-decoration:underline; onClick=window.open('"+url+"')>"+zong + ": "+messagetxt+"</a></div>"; |
|
134 |
} else { |
|
135 |
message="<div style=" + Bcolor + "><a id="+entity["messid"]+" style=line-height:15pt;" + Bcolor + "cursor:pointer;>"+zong + ": "+messagetxt+"</a></div>"; |
|
136 |
} |
|
137 |
return message; |
|
138 |
} |
|
139 |
function funB6002(message){ |
|
140 |
var init = $.cookie(userCode); |
|
141 |
if(init==null){ |
|
142 |
$.cookie(userCode,popflag); |
|
143 |
} |
|
144 |
if( $.cookie(userCode)=="false"){ |
|
145 |
$.messagerTip.lays(300, 220); |
|
146 |
$.messagerTip.show(0, message); |
|
147 |
popflag= $("input[name='isTip']").is(":checked"); |
|
148 |
$.cookie(userCode,popflag,{expires: 1}) |
|
149 |
} |
|
150 |
} |
|
151 |
function funB6003(json) { |
|
152 |
var messageType = json["messagetype"] ; |
|
153 |
var myMessages = json["messagetxt"] ; |
|
154 |
myMessages = myMessages.replace(/\t/g," "); |
|
155 |
//替换所有的换行符 |
|
156 |
myMessages = myMessages.replace(/\r\n/g,"<br>") |
|
157 |
myMessages = myMessages.replace(/\n/g,"<br>"); |
|
158 |
//替换所有的空格(中文空格、英文空格都会被替换) |
|
159 |
myMessages = myMessages.replace(/\s/g," "); |
|
160 |
myMessages +="<br/><br/><hr/>" ; |
|
161 |
myMessages += json["createusername"] + " " |
|
162 |
+ json["createtime"] ; |
|
163 |
openToast(myMessages,json["topic"],messageType); |
a6a76f
|
164 |
} |