/**
|
* 检查客户端会话是否超时
|
*/
|
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);
|
});
|