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; }
///
/// 是否有权限
///
///
///
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;
///
/// 刷新当前用户权限
///
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>();
}
catch
{
}
}
}
}