田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
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
/**
 * 检查客户端会话是否超时
 */
layui.define(['layer','util'],function(exports){
    var CheckSession = function(){
        this.moduleKey='vciWebCheckSession';
        this.basePath=path;
        this.url={
            checkSwitch:'/webSessionController/getClientSessionInterval',
            checkIdleTime:'/webSessionController/checkIdleTime',
            clearSessionRemind:'/webSessionController/clearSessionRemind',
            clearFinishDownloadUUID:'/webSessionController/clearFinishDownloadUUID'
        };
        this.getContent = function(){
            return "";
        };
        this.init = function(){//执行扫描
            var that = this;
            $(document).mousemove(function(e){
                if( !window.clearRemindTime) {
                    that.clearSessionRemind();
                }
            });
            $(document).keydown(function (e) {
                if(!window.clearRemindTime){
                    that.clearSessionRemind();
                }
            });
            $webUtil.copyConfig(that,that.moduleKey);
           that.initCheckTimeout();
        };
        this.initCheckTimeout = function(){
            var that = this;
            $webUtil.post(that.url.checkSwitch,{},function(result){
                if(result.success ){
                    //说明要检测
                    if(result.obj && result.obj*1>=10) {
                        window.checkIdleTimeUrl = that.url.checkIdleTime;
                        if(window.checkIntervalId ){
                            window.clearInterval( window.checkIntervalId);
                        }
                        window.checkIntervalId = window.setInterval(that.checkIdleInterval, result.obj * 1 * 1000);
                    }
                }else{
                    if(result.noLogin){
                        layui.vciWebCheckSession.showTimeOutMsg(result.msg);
                    }else{
                        if($webUtil.isNotNull(result.msg)){
                            $webUtil.showErrorMsg("访问系统出现了异常,因为:" + result.msg + ";您可以刷新页面再试");
                        }
                    }
                }
            },{},that.basePath,false,true,true);
        };
        this.checkIdleInterval = function () {//开始扫描
            var that = this;
            window.remindTime = 0;
            $webUtil.postForCheckId(that.checkIdleTimeUrl,{},function(result){
                if(!result.success){
                    //说明已经出问题了
                    if(result.noLogin){
                        //说明已经断开连接了
                        layui.vciWebCheckSession.showTimeOutMsg(result.msg);
                    }else{
                        $webUtil.showErrorMsg("访问系统出现了异常,因为:" + result.msg + ";您可以刷新页面再试");
                    }
                }else {
                    if(result.code =="finishDownloadFile" && $webUtil.isNotNull(result.msg)){
                        //说明有文件下载完成了
                        var finishUUIDS = result.msg.split(",");
                        var removeUUIDs= [];
                        for(var i = 0 ; i < finishUUIDS.length ;i ++){
                            var finishUUID = finishUUIDS[i];
                            if($webUtil.isNotNull(finishUUID) && $("#" +finishUUID )){
                                $("#" +finishUUID ).remove();
                                removeUUIDs.push(finishUUID);
                            }
                        }
                        if(removeUUIDs.length>0){
                            $webUtil.postForCheckId(layui.vciWebCheckSession.url.clearFinishDownloadUUID,{removeUUID:removeUUIDs.join(",")},function(){},function () {
 
                            },that.basePath);
                        }
                    }
                    if(result.obj*1>0){
                        window.clearRemindTime = false;
                        window.clearInterval( window.checkIntervalId);
                        layui.vciWebCheckSession.showRemindSession(result.obj*1);
                    }
                }
            },function(result){
 
            },layui.vciWebCheckSession.backPath);
        };
        this.showTimeOutMsg = function(msg){//显示超时
            window.clearInterval( window.checkIntervalId);
            if($webUtil.isSso()){
                $webUtil.showErrorMsg("您需要重新到" + $webUtil.getSsoinfo() + "登录系统,因为:" + msg);
            }else{
                $webUtil.showConfirmMsg("您需要重新登录系统,因为:" + msg + ";点击确定后可以输入密码立即重新登录",function(){
                    portal.relogin(function () {
                        layui.vciWebCheckSession.init();
                    });
                },function(){
                    window.location.href="index.html";
                });
            }
        };
        this.showRemindSession=function(remindTime){
            var that = this;
            var alertHtmlId = $("#clientSessionRemind_tips");
            if( window.clearRemindTime ){
                return false;
            }
            remindTime = parseInt(remindTime);
            if(remindTime < 1000){
                window.clearRemindTime = true;
                window.clearInterval( window.checkIntervalId);
                var alertHtmlId = $("#clientSessionRemind_tips");
                alertHtmlId.hide();
                that.showTimeOutMsg("会话已经超时");
            }else{
                var remindTimeStr = "";
                //都按照分钟计算
                var min = remindTime/60/1000;
                if(min < 1){
                    //说明只有秒了
                    remindTimeStr = parseInt(remindTime/1000) + '秒';
                }else{
                    min =  parseInt(min);
                    var secend = (remindTime-60*1000*min)/1000;
                    secend = parseInt(secend);
                    remindTimeStr = min + "分钟" + (secend>0?(secend + "秒"):"");
                }
                alertHtmlId.find("label").html(remindTimeStr);
                alertHtmlId.show();
                window.remindTime = remindTime;
                if( window.clearRemindTime ){
                    return false;
                }
                window.setTimeout(that.showRemindSessionSecend,1000);
            }
        };
        this.showRemindSessionSecend = function(){
            layui.vciWebCheckSession.showRemindSession(window.remindTime -1000);
        };
        this.clearSessionRemind =function(){
            var that = this;
            window.clearRemindTime = true;
            window.clearInterval( window.checkIntervalId);
            $webUtil.post(that.url.clearSessionRemind,{},function (result) {
                var alertHtmlId = $("#clientSessionRemind_tips");
                alertHtmlId.hide();
                that.init();
            },function (result) {
                var alertHtmlId = $("#clientSessionRemind_tips");
                alertHtmlId.hide();
                that.init();
            });
        };
    };
    var checkSession = new CheckSession();
    exports("vciWebCheckSession",checkSession);
});