优化体验,当关闭多地登录,且被挤下时,给予用户提示,而不是直接跳转登录页

This commit is contained in:
thinkgem
2025-10-11 21:55:01 +08:00
parent e4d406b864
commit 28e5f18c4c
3 changed files with 29 additions and 10 deletions

View File

@@ -29,7 +29,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* 在线用户Controller
@@ -51,6 +53,7 @@ public class OnlineController extends BaseController{
* @param response
* @author ThinkGem
*/
@RequiresPermissions("user")
@RequestMapping(value = "count")
@ResponseBody
public Integer count(HttpServletRequest request, HttpServletResponse response) {
@@ -158,7 +161,7 @@ public class OnlineController extends BaseController{
if (pc instanceof PrincipalCollection){
Object pp = ((PrincipalCollection)pc).getPrimaryPrincipal();
if (pp instanceof LoginInfo){
LoginInfo loginInfo = ((LoginInfo)pp);
LoginInfo loginInfo = (LoginInfo)pp;
String key = loginInfo.getId()+"_"+loginInfo.getParam("deviceType", "pc");
onlineTickOutMap.put(key, StringUtils.EMPTY);
}

View File

@@ -11,7 +11,6 @@
data-mergeMsgLimit="${@Global.getConfig('sys.msg.mergeMsgLimit', '5')}"
data-mergeMsgTitle="${text('系统消息')}"
data-mergeMsgContent="${text('您有 {0\} 条新消息,由于消息太多,这里为您合并,请点击查看按钮看详情。')}"
data-loginTimeout="${text('您当前的会话已超时,请重新登录。')}"
data-pullMsgPollingInterval="1000*60"
data-showMsgCloseTimeout="1000*60"></ul>
</li>

View File

@@ -5,15 +5,32 @@
</a>
<script>
function refreshOnlineCount(){
$.get('${ctx}/sys/online/count?__notUpdateSession=true&__t='
+ new Date().getTime(), function(data){
if (!(data && data.result != 'login')){
if (window.rocInt) {
clearInterval(window.rocInt);
function ajaxCallback(data) {
if (data && data.message){
if (data.result == 'false' || data.result == 'login') {
if (window.rocInt) clearInterval(window.rocInt);
if (window.ppmInt) clearInterval(window.ppmInt);
}
js.confirm(data.message, function(){
location.reload(true);
});
}
try{$('#onlineCount').html(Number(data || 0))}catch(e){}
}
$.ajax({
url: ctx+'/sys/online/count?__notUpdateSession=true&__t=' + new Date().getTime(),
method: 'GET',
success: function(data) {
ajaxCallback(data);
},
error: function(jqXHR) {
try {
ajaxCallback(JSON.parse(jqXHR.responseText));
} catch (e) {
ajaxCallback({message: jqXHR.responseText});
}
}
try{$('#onlineCount').html(Number(data))}catch(e){}
})
});
}
refreshOnlineCount(); // 先执行一次
window.rocInt = setInterval(refreshOnlineCount, 180000); // 3分钟执行一次