DeviceManager/DeviceRepairAndOptimization/GlobalInfo.cs
2024-06-04 01:21:11 +08:00

70 lines
2.1 KiB
C#

using DeviceRepair.Models;
using DeviceRepair.Utils;
using System;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DeviceRepairAndOptimization
{
public static class GlobalInfo
{
public static UserInfoModel CurrentUser { get; set; }
/// <summary>
/// 是否有权限
/// </summary>
/// <param name="AuthString"></param>
/// <returns></returns>
public static bool HasRole(string AuthString)
{
if (CurrentUser == null || CurrentUser.AuthItems == null)
return false;
return CurrentUser.AuthItems.Any(x => x.AuthCode.Equals(AuthString, StringComparison.CurrentCultureIgnoreCase));
}
private static HeaderModel _OperationInfo;
public static HeaderModel OperationInfo
{
get
{
if (_OperationInfo == null)
{
_OperationInfo = new HeaderModel();
_OperationInfo.ClientMac = ComputerHelper.GetMacAddress;
_OperationInfo.ClientName = ComputerHelper.GetComputerName;
_OperationInfo.IPAddress = ComputerHelper.GetIPAddress;
_OperationInfo.Operator = CurrentUser.AutoID;
_OperationInfo.OperatorName = CurrentUser.LoginCode;
}
return _OperationInfo;
}
}
public static string token = "";
public static Form _RootForm;
/// <summary>
/// 刷新当前用户权限
/// </summary>
public static void RefreshAuths()
{
try
{
// 更新当前用户权限
APIResponseData apiResponseData = Biz.UserManager.Instance.GetUserAuthsByUserID(CurrentUser?.AutoID ?? 0);
if (!apiResponseData.IsSuccess)
throw new Exception(apiResponseData.Message);
CurrentUser.AuthItems = apiResponseData.ToDeserializeObject<List<AuthModel>>();
}
catch
{
}
}
}
}