问题描述:
没有使用单点登录。
多个应用集成到一个门户中,但是多个tomcat应用时,portal中的session管理使用shiro,当不同应用通过菜单跳转时,每个菜单新进入时,进行登录授权,当离线时,用户登出,多个应用没有完全登出,存储session缓存问题。
解决方案:
使用 'onbeforeunload' 事件,当页面刷新或离开时,处理用户登出问题,清除session缓存问题。
代码:
/**
* 页面跳出当前系统时调用,页面F5刷新也会调用
* @param event
*/
window.onbeforeunload = function(event) {
/*
event.target.activeElement
刷新时, activeElement为 body
跳转离开页面是 activeElement为 a 标签
*/
var targetUrl = event.target.activeElement.href;
if(targetUrl!=undefined && targetUrl.indexOf("?")>0){
targetUrl = targetUrl.substring(0,targetUrl.indexOf("?"));
}
if(targetUrl == undefined){
console.log("刷新")
}else {
console.log("跳转")
AjaxService.fetch({
url: '../do/user/logout'
}, 'globalLoading')
.success(function (data) {
if(data.resultCode.slice(-4) === '0000'){
window.sessionStorage.clear();
}
});
}
};
代码中使用event.target.activeElement.href判断页面是刷新还是跳转。当页面刷新时,event.target.activeElement属性下是<body>,当页面跳转时,点击菜单时,event.target.activeElement属性是<a>,这样通过event.target.activeElement.href是否有值来区分页面是刷新还是跳转来处理不同的业务逻辑。