WMS/HHWMS.Web/Views/Home/Index.cshtml

58 lines
2.0 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>layui.use('index')</script>
<script>
// 检查登录状态的函数
function checkLoginStatus() {
$.ajax({
url: '/Home/CheckLogin',
type: 'GET',
success: function(data) {
// 如果返回的数据包含Login,说明已被重定向到登录页
if (data && data.indexOf('Login') !== -1) {
// 清除定时器
if (window.loginCheckTimer) {
clearInterval(window.loginCheckTimer);
}
// 使用layer弹窗提示
layer.alert("您的账号已在其他设备登录,请重新登录", {
icon: 0,
title: "登录提示",
closeBtn: 0,
btn: ['确定'],
yes: function(index) {
layer.close(index);
// 重定向到登录页
window.location.href = '/Login/Login';
}
});
}
},
error: function(xhr) {
// 如果返回401或其他错误,直接跳转到登录页
window.location.href = '/Login/Login';
}
});
}
// 页面加载完成后开始检查
$(document).ready(function() {
// 存储定时器ID
window.loginCheckTimer = setInterval(function() {
checkLoginStatus();
}, 10000); // 每10秒检查一次
// 页面关闭时清除定时器
$(window).on('unload', function() {
if (window.loginCheckTimer) {
clearInterval(window.loginCheckTimer);
}
});
// 页面从隐藏状态变为可见时,立即检查一次
$(document).on('visibilitychange', function() {
if (document.visibilityState === 'visible') {
checkLoginStatus();
}
});
});
</script>