using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TouchSocket.Core; namespace SlnMesnac.WPF.ViewModel.Base { /// /// ViewModel抽象类:分页 /// public abstract partial class BaseViewModelAsPageQuery : ObservableObject { /// /// 当前页码 /// [ObservableProperty] public int currentPage = 1; /// /// 每页显示的行数 /// [ObservableProperty] public int pageSize = 10; /// /// 总条数 /// public int totalCount = 0; /// /// 总页数 /// [ObservableProperty] public int totalPages = 0; /// /// 首页 /// [RelayCommand] private void FirstPage() => ChangePage(1); /// /// 上一页 /// [RelayCommand] private void PreviousPage() => ChangePage(CurrentPage - 1); /// /// 下一页 /// [RelayCommand] private void NextPage() => ChangePage(CurrentPage + 1); /// /// 尾页 /// [RelayCommand] private void LastPage() => ChangePage(TotalPages); private void ChangePage(int newPage) { if (newPage >= 1 && newPage <= TotalPages) { CurrentPage = newPage; Query(); } } public abstract void Query(); } }