using BPASmartClient.Business; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.Helper; using BPASmartClient.IoT; using DataVAPI.Tool.IOT; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace BPASmartClient.ViewModel { public class LogOrAlarmIOTViewModel : ObservableObject { #region 单一变量 private volatile static LogOrAlarmIOTViewModel _Instance; public static LogOrAlarmIOTViewModel GetInstance() => _Instance ?? (_Instance = new LogOrAlarmIOTViewModel()); private LogOrAlarmIOTViewModel() { Init(); } #endregion #region 变量 public string api = "https://bpa.black-pa.com:21527/datav/api/Log/QueryLogFile?DeviceName="; public string DataVApiAddress { set; get; } private ObservableCollection _LogModels; public ObservableCollection LogDataFile { get { return _LogModels; } set { if (_LogModels == value) return; _LogModels = value; OnPropertyChanged("LogDataFile"); } } #endregion #region Command public RelayCommand QueryCommand { get; set; } #endregion #region 函数 public void Init() { DataVApiAddress = InternetInfo.DataVApiAddress; LogDataFile = new ObservableCollection(); //查询 QueryCommand = new RelayCommand(() => { Res(); }); } public void Res() { if (DataVClient.GetInstance().DeviceDataV != null && DataVClient.GetInstance().DeviceDataV.deviceTable != null) { try { LogDataFile.Clear(); api = $"{DataVApiAddress}/api/Log/QueryLogFile?DeviceName={DataVClient.GetInstance().DeviceDataV.deviceTable.devicename}"; ; string json = HttpRequestHelper.HttpGetRequest(api, 1000); JsonMsg> jsonMsg = Tools.JsonToObjectTools>>(json); jsonMsg.obj?.data?.ForEach(file => { LogDataFile.Add(file); }); NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"查询成功,文件数{LogDataFile.Count}!"); } catch (Exception ex) { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"查询失败!"); } } } #endregion } public class FileModel : ObservableObject { public string downloadUrl { get; set; } public string fileId { get; set; } public string name { get; set; } public string size { get; set; } public string utcCreatedOn { get; set; } private Brush _foreground; public Brush foreground { get { return _foreground; } set { if (_foreground == value) return; _foreground = value; OnPropertyChanged("foreground"); } } public FileModel() { foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#21bb2e")); } } }