fs-danaus
2022-12-21 e98f5c54f11448bb649ad62db9761406ed77210f
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
var wsOnTimers=null;
var layerMaintenanceIndex=null;
function initWebsocket(hostUrl,userCode,dbId,sessionId,userType) {
//  初始化weosocket
    var userFromType=1;
    if(userType!=undefined) userFromType=userType;
    var localHostUrl =  hostUrl; 
    var localUserCode = userCode ;
    var localDbId = dbId;
    var localSessionId = sessionId ;
    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;
        }
      }
 
      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==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);
}