登录用户超时注销、登录日志记录

This commit is contained in:
Administrator
2026-08-28 14:12:02 +08:00
parent 11142481a8
commit 6dfac6d986
9 changed files with 87 additions and 9 deletions
+3 -2
View File
@@ -101,8 +101,9 @@ namespace LargeSquareOne
// AlarmType = isError ? "错误".Translated() : "信息".Translated(),
// Operater = CommonMethods.currentAdmin.LoginName
//});
string opeType = isError ? "错误" : "信息";
string logInfo = $"操作时间: {CurrentTime}, 操作类型: {opeType}, 操作信息: {info}";
LogHelper.Instance.WriteLog(logInfo, ConstValue.USER_LOG);
}
/// <summary>
+27
View File
@@ -94,6 +94,11 @@ namespace LargeSquareOne
}
};
Application.AddMessageFilter(new InputMessageFilter(() =>
{
lastActivityTime = DateTime.Now;
}));
// 双缓冲全覆盖
this.DoubleBuffered = true;
InitializeOptimizedControlStyles();
@@ -178,6 +183,9 @@ namespace LargeSquareOne
}
}
private DateTime lastActivityTime;
private System.Windows.Forms.Timer idleTimer;
// 定时器初始化优化
private void InitializeTimersOptimized()
{
@@ -192,6 +200,21 @@ namespace LargeSquareOne
storeTimer.Elapsed += StoreTimer_Elapsed;
storeTimer.AutoReset = true;
storeTimer.Start();
// 定时退出当前用户
idleTimer = new System.Windows.Forms.Timer();
idleTimer.Interval = 1000;
idleTimer.Tick += (s, e) =>
{
if ((DateTime.Now - lastActivityTime).TotalMinutes >= 1)
{
idleTimer.Stop();
// 处理用户超时
this.BeginInvoke(new Action(() => LoginLocalOut()));
}
};
idleTimer.Start();
}
@@ -902,6 +925,9 @@ namespace LargeSquareOne
updateTimer?.Dispose();
storeTimer?.Dispose();
idleTimer?.Stop();
storeTimer?.Dispose();
if (ControlCenter.Instance != null)
{
ControlCenter.Instance.DisconnectAllPlcs(); // 假设存在断开PLC的方法
@@ -1266,6 +1292,7 @@ namespace LargeSquareOne
CommonMethods.AddOPLog(false, "退出成功".Translated() + "," + "退出用户".Translated() + $":{CommonMethods.currentAdmin?.LoginName}," + "权限".Translated() + $":{CommonMethods.currentAdmin?.LoginLevel}");
LogHelper.Instance.WriteLog("用户".Translated() + $":{CommonMethods.currentAdmin?.LoginName} - " + "退出".Translated());
CommonMethods.LoginOut = true;
CommonMethods.IsLoginOk = false;
}
/// <summary>