diff --git a/src/admin/Bootstrap.Admin/Components/PaginationBase.cs b/src/admin/Bootstrap.Admin/Components/PaginationBase.cs new file mode 100644 index 00000000..8e7b0c32 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Components/PaginationBase.cs @@ -0,0 +1,53 @@ +using Bootstrap.Admin.Extensions; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System; +using System.Threading.Tasks; + +namespace Bootstrap.Admin.Components +{ + /// + /// 分页组件基类 + /// + public class PaginationBase : ComponentBase + { + /// + /// 获得/设置 页码总数 + /// + [Parameter] + public int PageCount { get; set; } = 0; + + /// + /// + /// + [Parameter] + public int PageIndex { get; set; } = 1; + + /// + /// + /// + [Inject] + protected IJSRuntime? JSRuntime { get; set; } + + /// + /// + /// + public Action? ClickPageCallback { get; set; } + + /// + /// + /// + protected void MovePrev() + { + if (PageIndex > 1) ClickPageCallback?.Invoke(PageIndex - 1); + } + + /// + /// + /// + protected void MoveNext() + { + if (PageIndex < PageCount) ClickPageCallback?.Invoke(PageIndex + 1); + } + } +} diff --git a/src/admin/Bootstrap.Admin/Components/TableBase.cs b/src/admin/Bootstrap.Admin/Components/TableBase.cs new file mode 100644 index 00000000..c903b107 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Components/TableBase.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Collections.Generic; + +namespace Bootstrap.Admin.Components +{ + /// + /// 表格组件类 + /// + public class TableBase : ComponentBase + { + /// + /// + /// + [Inject] + protected IJSRuntime? JSRuntime { get; set; } + + /// + /// + /// + [Parameter] + public string Id { get; set; } = ""; + + /// + /// + /// + [Parameter] + public RenderFragment? TableHeader { get; set; } + + /// + /// + /// + [Parameter] + public RenderFragment? RowTemplate { get; set; } + + /// + /// + /// + [Parameter] + public RenderFragment? TableFooter { get; set; } + + /// + /// + /// + [Parameter] + public IEnumerable Items { get; set; } = new TItem[0]; + + /// + /// 数据 + /// + [Parameter] + public int ItemsCount { get; set; } = 0; + } +} diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor index a54886c4..b2e906d3 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor @@ -21,7 +21,7 @@
- +
@@ -47,7 +47,21 @@ 查询结果
-
+ + + + + + + + + + + + + +
字典标签字典名称字典代码字典分类@context.Category@context.Name@context.Code@context.Define
+
@@ -102,5 +116,45 @@ @code { + [Parameter] + public IEnumerable Items { get; set; } = new BootstrapDict[0]; + [Parameter] + public int ItemsCount { get; set; } = 0; + + [Parameter] + public int PageCount { get; set; } = 0; + + [Parameter] + public int PageIndex { get; set; } = 1; + + protected int PageItem { get; set; } = 20; + + protected Pagination? Pagination { get; set; } + + protected override void OnInitialized() + { + Query(1); + } + + protected override void OnAfterRender(bool firstRender) + { + if (firstRender && Pagination != null) Pagination.ClickPageCallback = pageIndex => + { + if (pageIndex != PageIndex) + { + Query(pageIndex); + StateHasChanged(); + } + }; + } + + protected void Query(int pageIndex) + { + var data = DataAccess.DictHelper.RetrieveDicts(); + ItemsCount = data.Count(); + Items = data.Skip((pageIndex - 1) * PageItem).Take(PageItem); + PageCount = (int)Math.Ceiling(data.Count() * 1.0d / PageItem); + PageIndex = pageIndex; + } } diff --git a/src/admin/Bootstrap.Admin/Shared/Pagination.razor b/src/admin/Bootstrap.Admin/Shared/Pagination.razor new file mode 100644 index 00000000..dec82908 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Shared/Pagination.razor @@ -0,0 +1,19 @@ +@inherits PaginationBase + + + +@code { + +} diff --git a/src/admin/Bootstrap.Admin/Shared/PaginationItem.razor b/src/admin/Bootstrap.Admin/Shared/PaginationItem.razor new file mode 100644 index 00000000..ff14c1e3 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Shared/PaginationItem.razor @@ -0,0 +1,29 @@ +
  • + +@code { + /// + /// + /// + [Parameter] + public bool Active { get; set; } + + /// + /// + /// + [CascadingParameter] + public Pagination? Pagination { get; set; } + + /// + /// + /// + [Parameter] + public int PageIndex { get; set; } = 0; + + /// + /// + /// + protected void ClickPage() + { + Pagination?.ClickPageCallback?.Invoke(PageIndex); + } +} diff --git a/src/admin/Bootstrap.Admin/Shared/Table.razor b/src/admin/Bootstrap.Admin/Shared/Table.razor new file mode 100644 index 00000000..5f809126 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Shared/Table.razor @@ -0,0 +1,21 @@ +@typeparam TItem +@inherits TableBase + + + + @TableHeader + + + @foreach (var item in Items) + { + @RowTemplate?.Invoke(item) + } + + + @TableFooter + +
    + +@code { + +} diff --git a/src/admin/Bootstrap.Admin/_Imports.razor b/src/admin/Bootstrap.Admin/_Imports.razor index 17d9d84d..52455905 100644 --- a/src/admin/Bootstrap.Admin/_Imports.razor +++ b/src/admin/Bootstrap.Admin/_Imports.razor @@ -13,6 +13,7 @@ @using Microsoft.AspNetCore.Mvc @using Microsoft.Extensions.Configuration @using Microsoft.JSInterop +@using Longbow.Web.Mvc @using System.Linq @using System.Net @using System.Net.Http diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css index faedfdbd..3205ffd1 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css +++ b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css @@ -1,20 +1,16 @@ -nav { - margin-bottom: 10px; +.nav-link-bar { + border: 1px solid #dee2e6; + border-top-left-radius: 0.25rem; + border-top-right-radius: 0.25rem; + padding: 0.5rem 1rem; + background-color: #fff; } - nav .nav-link-bar { - border: 1px solid #dee2e6; - border-top-left-radius: 0.25rem; - border-top-right-radius: 0.25rem; - padding: 0.5rem 1rem; - background-color: #fff; - } +nav .dropdown .nav-link-close.dropdown-toggle:after { + display: none; +} - nav .dropdown .nav-link-close.dropdown-toggle:after { - display: none; - } - -.dropdown-item, .nav-tabs .nav-link .fa, .nav-link, .nav-link-bar { +.dropdown-item, .nav-tabs .nav-link .fa, .nav-link, .nav-link-bar, .page-link { cursor: pointer; } @@ -62,3 +58,12 @@ .nav-link-close { padding: 0.5rem 1rem; } + +.table th, .table td { + padding: 0.5rem; +} + +.pagination-bar { + flex: 1 1 auto; + margin-bottom: 1rem; +}