From 9484a6e598b2e1b88d1576b609fed6e9f2aa3bb5 Mon Sep 17 00:00:00 2001 From: Argo Window10 Date: Thu, 28 Nov 2019 17:50:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=86=E9=A1=B5=E6=A0=8F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=AF=8F=E9=A1=B5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/PaginationBase.cs | 39 +++++++++++++++---- .../Bootstrap.Admin/Pages/Admin/Dicts.razor | 28 ++++++++----- .../Bootstrap.Admin/Shared/Pagination.razor | 29 +++++++++----- 3 files changed, 70 insertions(+), 26 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Components/PaginationBase.cs b/src/admin/Bootstrap.Admin/Components/PaginationBase.cs index 8e7b0c32..646f4a96 100644 --- a/src/admin/Bootstrap.Admin/Components/PaginationBase.cs +++ b/src/admin/Bootstrap.Admin/Components/PaginationBase.cs @@ -1,8 +1,6 @@ -using Bootstrap.Admin.Extensions; -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System; -using System.Threading.Tasks; namespace Bootstrap.Admin.Components { @@ -18,7 +16,19 @@ namespace Bootstrap.Admin.Components public int PageCount { get; set; } = 0; /// - /// + /// 获得/设置 每页显示数据数量 + /// + [Parameter] + public int PageItems { get; set; } = 20; + + /// + /// 获得/设置 数据总数 + /// + [Parameter] + public int ItemsCount { get; set; } = 0; + + /// + /// 获得/设置 当前页码 /// [Parameter] public int PageIndex { get; set; } = 1; @@ -32,14 +42,19 @@ namespace Bootstrap.Admin.Components /// /// /// - public Action? ClickPageCallback { get; set; } + public Action ClickPageCallback { get; set; } = new Action(i => { }); + + /// + /// + /// + public Action PageItemsChangeCallback { get; set; } = new Action(() => { }); /// /// /// protected void MovePrev() { - if (PageIndex > 1) ClickPageCallback?.Invoke(PageIndex - 1); + if (PageIndex > 1) ClickPageCallback(PageIndex - 1); } /// @@ -47,7 +62,17 @@ namespace Bootstrap.Admin.Components /// protected void MoveNext() { - if (PageIndex < PageCount) ClickPageCallback?.Invoke(PageIndex + 1); + if (PageIndex < PageCount) ClickPageCallback(PageIndex + 1); + } + + /// + /// + /// + /// + protected void ClickItem(int pageItems) + { + PageItems = pageItems; + PageItemsChangeCallback(); } } } diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor index 344b0355..a6f12c24 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor @@ -60,7 +60,7 @@ @context.Define - +
@@ -129,8 +129,6 @@ protected Select? DictCate { get; set; } - protected int PageItem { get; set; } = 20; - protected Pagination? Pagination { get; set; } protected override void OnInitialized() @@ -140,14 +138,22 @@ protected override void OnAfterRender(bool firstRender) { - if (firstRender && Pagination != null) Pagination.ClickPageCallback = pageIndex => + if (firstRender && Pagination != null) { - if (pageIndex != PageIndex) + Pagination.ClickPageCallback = pageIndex => { - Query(pageIndex); + if (pageIndex != PageIndex) + { + Query(pageIndex); + StateHasChanged(); + } + }; + Pagination.PageItemsChangeCallback = () => + { + Query(1); StateHasChanged(); - } - }; + }; + } } protected void Query(int pageIndex) @@ -155,8 +161,10 @@ var data = DataAccess.DictHelper.RetrieveDicts(); if (!string.IsNullOrEmpty(DictCate?.SelectedItem?.Value)) data = data.Where(d => d.Define.ToString() == DictCate?.SelectedItem?.Value); ItemsCount = data.Count(); - Items = data.Skip((pageIndex - 1) * PageItem).Take(PageItem); - PageCount = (int)Math.Ceiling(data.Count() * 1.0d / PageItem); + + var pageItems = Pagination?.PageItems ?? 20; + Items = data.Skip((pageIndex - 1) * pageItems).Take(pageItems); + PageCount = (int)Math.Ceiling(data.Count() * 1.0d / pageItems); PageIndex = pageIndex; } } diff --git a/src/admin/Bootstrap.Admin/Shared/Pagination.razor b/src/admin/Bootstrap.Admin/Shared/Pagination.razor index dec82908..5bdd322e 100644 --- a/src/admin/Bootstrap.Admin/Shared/Pagination.razor +++ b/src/admin/Bootstrap.Admin/Shared/Pagination.razor @@ -1,18 +1,29 @@ @inherits PaginationBase - + @code {