fs-danaus
2023-07-04 44407f607a99f6041249c170c9a6655873848c0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
var wsOnTimers=null;
var layerMaintenanceIndex=null;
var reloginIndex=null;
function initWebsocket(hostUrl,userCode,dbId,sessionId,userType,isColseLayer) {
//  初始化weosocket
    var userFromType=1;
    if(userType!=undefined) userFromType=userType;
    var localHostUrl =  hostUrl; 
    var localUserCode = userCode ;
    var localDbId = dbId;
    var localSessionId = sessionId ;
    var colseLayer=isColseLayer;
    if(localUserCode==null||localUserCode==""||localUserCode=="null") localUserCode="temp_userCode_"+Math.random();
    if(localDbId==null||localDbId==""||localDbId=="null") localDbId=Math.floor(Math.random() * (10000 - 2000)) + 2000;
    if(localUserCode==null||localUserCode==""||localUserCode=="null") localUserCode="temp_session_"+Math.random();
    var info = '/ws/websocketMessage/'+localUserCode + '/'+ localDbId+'/' + localSessionId+'/'+userFromType ;
    var url = localHostUrl + info ;
    websocket = new WebSocket(url);
    
    websocket.onopen = function (e) {
        //  连接建立之后执行
        console.log('WebSocket连接成功');
        if(wsOnTimers!=null){
            //console.log("onOpen-wsOnTimers:"+wsOnTimers);
            clearInterval(wsOnTimers);
            wsOnTimers=null;
        }
        if(colseLayer==true){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        }
      }
 
      websocket.onerror = function (e) {
         /* timeron=setInterval(function () {
              //这里会定时3秒执行一次,直到成功为止,条件是timeron==null;
              if(timeron!=null) {
                  console.log(timeron + ',onError,30秒后重连', e);
                  initWebsocket(localHostUrl, localUserCode, localDbId, localSessionId, userType);
              }
          }, 30000);*/
        };
 
        websocket.onclose = function (e) {
            wsOnTimers=setInterval(function () {
                //这里会定时3秒执行一次,直到成功为止,条件是timeron==null;
                if(wsOnTimers!=null) {
                    console.log(wsOnTimers + ',onClose,10秒后重连', e);
                    initWebsocket(localHostUrl, localUserCode, localDbId, localSessionId, userType);
                }
                }, 10000);
           // console.log("wsOnTimers:"+wsOnTimers);
        };
      
 
      // 接收消息
      websocket.onmessage = function (e) {
            var json= JSON.parse(e.data);
            if(json.info.msgType==6014||json.info.msgType==6015){
                //重定向到登录页面
                setTimeout(function (){
                    location="/login.jsp";
                },500);
 
            }else if(json.info.msgType==6016){
              //重定向到登录页面
               /* $.messager.show("提示", "您的账户已在其他设备浏览器登录,点击确定后返回登录页面", "info", function () {
                    location="/login.jsp";
                });*/
                layer.open({
                    title: '提示'
                    ,content: json.info.msg
                    ,closeBtn:0
                    ,yes: function(index, layero){
                        //do something
                        layer.close(index); //如果设定了yes回调,需进行手工关闭
                        location="/login.jsp";
                    }
                });
 
            }else if(json.info.msgType==6017){
                if(reloginIndex==null) {
                    reloginIndex = layui.layer.open({
                        type: 2,
                        area: ['400px', '200px'],
                        closeBtn: 0,
                        isOutAnim: false,
                        title: [json.info.msg, 'font-size:18px;text-align:center;padding:0px'],
                        resize: false,
                        fixed: false,
                        content: '/reloadsession.jsp?userCode=' + userCode,
                        move: false,
                        success: function (layero, index) {
 
                        }
                    });
                }
            }else if(json.info.msgType==6002){
                //右下角弹窗
                //console.log('接收消息', json);
                popMessage(json.info.msg);
            }else if(json.info.msgType==6999){
                //显示维护界面
                if(layerMaintenanceIndex==null) {
                    layerMaintenanceIndex = layer.open({
                        title: '系统维护',
                        type: 0,
                        resize: false,
                        area: ['800px', '600px'],
                        btn: null,
                       // closeBtn: 0,
                       // cancel: function(){
                       //     layerMaintenanceIndex=null;
                       // },
                        content: '<img style="width: 800px" src="/images/maintenance.jpg">'
                    });
                }
            }else if(json.info.msgType==6998){
                //关闭维护界面
                if(layerMaintenanceIndex!=null){
                    layer.close(layerMaintenanceIndex);
                    layerMaintenanceIndex=null;
                }
            }
          //console.log('接收消息', json);
      }
}
var popflag=false;
function popMessage(message){
    var json=JSON.parse(message);
    var message6002="";
    var colt=0;
    var zong=1;
    for(var i=0;i<json.length;i++){
 
        if(json[i]["isPublicUser"]==1){
            funB6003(json[i]);
        }else{
            message6002+=getMessage6002(json[i],colt,zong);
             colt++;
             zong++;
        }
    }
    if(message6002!="") {
        funB6002(message6002);
    }
}
function messageToString(obj) {
    if(obj==null)
        return "";
    else
        return obj+"";
}
function getMessage6002(entity,colt,zong) {
    var message="";
    var Bcolor="";
        var messagetxt =entity["messagetxt"].replaceAll("(\\n|\\r|(\\r\\n)|(\u0085)|(\u2028)|(\u2029))","");
        if (colt % 2 == 0) {
            Bcolor = "background:#FFFFFF;";
        } else {
            Bcolor = "background:#DDDDDD;";
        }
        if (entity["formid"] != undefined) {
            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>";
        } else if (entity["url"]!=undefined&&entity["url"]!="") {
            var url = "";
            if (entity["url"].indexOf("http://")<0) {
                url = "http://" + entity["url"];
            } else {
                url = entity["url"];
            }
            message="<div style=" + Bcolor + "><a style=line-height:15pt;cursor:pointer;text-decoration:underline;  onClick=window.open('"+url+"')>"+zong + ":  "+messagetxt+"</a></div>";
        } else {
            message="<div style=" + Bcolor + "><a id="+entity["messid"]+" style=line-height:15pt;" + Bcolor + "cursor:pointer;>"+zong + ":  "+messagetxt+"</a></div>";
        }
    return message;
}
function funB6002(message){
    var init = $.cookie(userCode);
    if(init==null){
        $.cookie(userCode,popflag);
    }
    if( $.cookie(userCode)=="false"){
        $.messagerTip.lays(300, 220);
        $.messagerTip.show(0, message);
        popflag= $("input[name='isTip']").is(":checked");
        $.cookie(userCode,popflag,{expires: 1})
    }
}
function funB6003(json) {
    var messageType = json["messagetype"] ;
    var myMessages = json["messagetxt"]  ;
    myMessages = myMessages.replace(/\t/g,"&nbsp;&nbsp;");
    //替换所有的换行符
    myMessages = myMessages.replace(/\r\n/g,"<br>")
    myMessages = myMessages.replace(/\n/g,"<br>");
    //替换所有的空格(中文空格、英文空格都会被替换)
    // myMessages = myMessages.replace(/\s/g,"&nbsp;");
    myMessages +="<br/><br/><hr/>" ;
    myMessages += json["createusername"] + "&nbsp;&nbsp;"
        + json["createtime"] ;
    openToast(myMessages,json["topic"],messageType);
}