using Admin.Core.IService; using Admin.Core.Model; using Aucma.Scada.UI.Models; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using log4net; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Aucma.Scada.UI.ViewModel { public partial class RecordViewModel : ObservableObject { private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(RecordViewModel)); private readonly ISysUserInfoServices? _sysUserInfoService; public RecordViewModel() { _sysUserInfoService = App.ServiceProvider.GetService(); } private String search = String.Empty; public String Search { get => search; set => SetProperty(ref search, value); } private ObservableCollection gridModelList; //前端使用的属性 public ObservableCollection GridModelList { get => gridModelList; set => SetProperty(ref gridModelList, value); } #region 查询事件 /// /// 查询事件 /// [RelayCommand] public async void Query() { var models = await _sysUserInfoService.QueryAsync(); if (!string.IsNullOrEmpty(Search)) { models = models.Where(x => x.UserName.Contains(Search)).ToList(); } GridModelList = new ObservableCollection(); if (models != null) { models.ForEach( arg => { GridModelList.Add(arg); } ); } } #endregion #region 重置 /// /// 重置 /// [RelayCommand] public void Reset() { Search = String.Empty; this.Query(); } #endregion } }