终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LogOrAlarmIOTViewModel.cs 3.8 KiB

il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using BPASmartClient.Business;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.Helper;
  5. using BPASmartClient.IoT;
  6. using DataVAPI.Tool.IOT;
  7. using Microsoft.Toolkit.Mvvm.ComponentModel;
  8. using Microsoft.Toolkit.Mvvm.Input;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Media;
  16. namespace BPASmartClient.ViewModel
  17. {
  18. public class LogOrAlarmIOTViewModel : ObservableObject
  19. {
  20. #region 单一变量
  21. private volatile static LogOrAlarmIOTViewModel _Instance;
  22. public static LogOrAlarmIOTViewModel GetInstance() => _Instance ?? (_Instance = new LogOrAlarmIOTViewModel());
  23. private LogOrAlarmIOTViewModel()
  24. {
  25. Init();
  26. }
  27. #endregion
  28. #region 变量
  29. public string api = "https://bpa.black-pa.com:21527/datav/api/Log/QueryLogFile?DeviceName=";
  30. public string DataVApiAddress { set; get; }
  31. private ObservableCollection<FileModel> _LogModels; public ObservableCollection<FileModel> LogDataFile
  32. {
  33. get
  34. {
  35. return _LogModels;
  36. }
  37. set
  38. {
  39. if (_LogModels == value)
  40. return;
  41. _LogModels = value;
  42. OnPropertyChanged("LogDataFile");
  43. }
  44. }
  45. #endregion
  46. #region Command
  47. public RelayCommand QueryCommand { get; set; }
  48. #endregion
  49. #region 函数
  50. public void Init()
  51. {
  52. DataVApiAddress = InternetInfo.DataVApiAddress;
  53. LogDataFile = new ObservableCollection<FileModel>();
  54. //查询
  55. QueryCommand = new RelayCommand(() =>
  56. {
  57. Res();
  58. });
  59. }
  60. public void Res()
  61. {
  62. if (DataVClient.GetInstance().DeviceDataV != null && DataVClient.GetInstance().DeviceDataV.deviceTable != null)
  63. {
  64. try
  65. {
  66. LogDataFile.Clear();
  67. api = $"{DataVApiAddress}/api/Log/QueryLogFile?DeviceName={DataVClient.GetInstance().DeviceDataV.deviceTable.devicename}"; ;
  68. string json = HttpRequestHelper.HttpGetRequest(api, 1000);
  69. JsonMsg<List<FileModel>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<FileModel>>>(json);
  70. jsonMsg.obj?.data?.ForEach(file =>
  71. {
  72. LogDataFile.Add(file);
  73. });
  74. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"查询成功,文件数{LogDataFile.Count}!");
  75. }
  76. catch (Exception ex)
  77. {
  78. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"查询失败!");
  79. }
  80. }
  81. }
  82. #endregion
  83. }
  84. public class FileModel : ObservableObject
  85. {
  86. public string downloadUrl { get; set; }
  87. public string fileId { get; set; }
  88. public string name { get; set; }
  89. public string size { get; set; }
  90. public string utcCreatedOn { get; set; }
  91. private Brush _foreground;
  92. public Brush foreground
  93. {
  94. get
  95. {
  96. return _foreground;
  97. }
  98. set
  99. {
  100. if (_foreground == value)
  101. return;
  102. _foreground = value;
  103. OnPropertyChanged("foreground");
  104. }
  105. }
  106. public FileModel()
  107. {
  108. foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#21bb2e"));
  109. }
  110. }
  111. }