authentication.js 1.39 KB
(function($,contextPath){
	window.authentication=true;
	var logoutEvent=function(){
		layer.open({
			type:1,
			title:false,
			content:'\
				<div style="padding:50px;width:100%;height:100%;">\
					<p style="text-align:center;">\
						<span class="glyphicon glyphicon-exclamation-sign" style="font-size:40px;color:gray;"></span>\
					</p>\
					<p style="text-align:center;margin-top:30px;">\
						由于刚刚的操作,您的登录帐号已发生变化,请注意使用!\
					</p>\
				</div>',
			area:['400px','250px'],
			btn:'我知道了',
			btnAlign:'c',
			yes:function(index,layero){
				window.location.assign(contextPath)
				layer.close(index);
			},
			cancel: function(index){ 
				window.location.assign(contextPath)
			},
			success: function(layero, index){
				$(layero).find('.layui-layer-btn').css('text-align','center');
			}
		}); 
	}
	var connection=function(){
		if(window.authentication===false)return;
		var xmlhttp=new XMLHttpRequest();
		xmlhttp.open('GET',contextPath+'/authentication?t=' + Math.random(),true);
		xmlhttp.send();
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				if(xmlhttp.responseText&&xmlhttp.responseText.indexOf('data:reconnection')!=-1){
					connection();
				}else{
					window.authentication=false;
					if(window._isOwner)return;
					logoutEvent();
				}
		    }
		}
	};
	connection();
})(jQuery,_contextPath)