diff --git a/src/admin/Bootstrap.Admin/Components/SelectBase.cs b/src/admin/Bootstrap.Admin/Components/SelectBase.cs index a8a8ce50..91b23653 100644 --- a/src/admin/Bootstrap.Admin/Components/SelectBase.cs +++ b/src/admin/Bootstrap.Admin/Components/SelectBase.cs @@ -8,6 +8,12 @@ namespace Bootstrap.Admin.Components /// public class SelectBase : ComponentBase { + /// + /// + /// + [Parameter] + public string Id { get; set; } = ""; + /// /// /// @@ -25,6 +31,18 @@ namespace Bootstrap.Admin.Components /// public SelectItemBase? SelectedItem { get; set; } + /// + /// + /// + [Parameter] + public int SelectedValue { get; set; } + + /// + /// + /// + [Parameter] + public EventCallback SelectedValueChanged { get; set; } + /// /// /// diff --git a/src/admin/Bootstrap.Admin/Components/TableBase.cs b/src/admin/Bootstrap.Admin/Components/TableBase.cs index c903b107..588fe2b9 100644 --- a/src/admin/Bootstrap.Admin/Components/TableBase.cs +++ b/src/admin/Bootstrap.Admin/Components/TableBase.cs @@ -1,5 +1,7 @@ -using Microsoft.AspNetCore.Components; +using Bootstrap.Admin.Extensions; +using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; +using System; using System.Collections.Generic; namespace Bootstrap.Admin.Components @@ -15,12 +17,6 @@ namespace Bootstrap.Admin.Components [Inject] protected IJSRuntime? JSRuntime { get; set; } - /// - /// - /// - [Parameter] - public string Id { get; set; } = ""; - /// /// /// @@ -39,6 +35,12 @@ namespace Bootstrap.Admin.Components [Parameter] public RenderFragment? TableFooter { get; set; } + /// + /// + /// + [Parameter] + public bool ShowToolBar { get; set; } = true; + /// /// /// @@ -46,9 +48,20 @@ namespace Bootstrap.Admin.Components public IEnumerable Items { get; set; } = new TItem[0]; /// - /// 数据 + /// /// - [Parameter] - public int ItemsCount { get; set; } = 0; + public Action AddCallback { get; set; } = new Action(() => { }); + /// + /// + /// + public Action EditCallback { get; set; } = new Action(() => { }); + + /// + /// + /// + public void Delete() + { + + } } } diff --git a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs index 2b476ecc..a6c529ea 100644 --- a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs +++ b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs @@ -52,5 +52,12 @@ namespace Bootstrap.Admin.Extensions /// /// public static void InitModal(this IJSRuntime? jSRuntime) => jSRuntime.InvokeVoidAsync("$.initModal"); + + /// + /// 弹出 Modal 组件 + /// + /// + /// + public static void ToggleModal(this IJSRuntime? jSRuntime, string modalId) => jSRuntime.InvokeVoidAsync("$.toggleModal", modalId); } } diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor index a6f12c24..8992e481 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor @@ -1,4 +1,6 @@ - +@inject IJSRuntime JSRuntime + + 查询条件 @@ -26,41 +28,28 @@ - - - - - - - - - - - 新增 - 删除 - 编辑 - - 查询结果 - - - 字典标签 - 字典名称 - 字典代码 - 字典类型 - - - @context.Category - @context.Name - @context.Code - @context.Define - - - + + + + 字典标签 + 字典名称 + 字典代码 + 字典类型 + + + @context.Category + @context.Name + @context.Code + @context.Define + + + + @@ -70,34 +59,29 @@ - - Launch demo modal - - - + - 字典标签 - + 字典类型 - - - 系统使用 - 自定义 - + + + + + 字典名称 - + 字典代码 - + @@ -107,7 +91,7 @@ 关闭 - + 保存 @@ -131,6 +115,10 @@ protected Pagination? Pagination { get; set; } + protected Table? Table { get; set; } + + protected BootstrapDict Model { get; set; } = new BootstrapDict(); + protected override void OnInitialized() { Query(1); @@ -138,21 +126,35 @@ protected override void OnAfterRender(bool firstRender) { - if (firstRender && Pagination != null) + if (firstRender) { - Pagination.ClickPageCallback = pageIndex => + if (Pagination != null) { - if (pageIndex != PageIndex) + Pagination.ClickPageCallback = pageIndex => { - Query(pageIndex); + if (pageIndex != PageIndex) + { + Query(pageIndex); + StateHasChanged(); + } + }; + Pagination.PageItemsChangeCallback = () => + { + Query(1); StateHasChanged(); - } - }; - Pagination.PageItemsChangeCallback = () => + }; + } + if (Table != null) { - Query(1); - StateHasChanged(); - }; + Table.AddCallback = () => + { + JSRuntime.ToggleModal("#DialogDict"); + }; + Table.EditCallback = () => + { + + }; + } } } @@ -167,4 +169,9 @@ PageCount = (int)Math.Ceiling(data.Count() * 1.0d / pageItems); PageIndex = pageIndex; } + + protected void Save() + { + JSRuntime.ToggleModal("#DialogDict"); + } } diff --git a/src/admin/Bootstrap.Admin/Shared/Select.razor b/src/admin/Bootstrap.Admin/Shared/Select.razor index b316cd3e..f0a96464 100644 --- a/src/admin/Bootstrap.Admin/Shared/Select.razor +++ b/src/admin/Bootstrap.Admin/Shared/Select.razor @@ -1,7 +1,7 @@ @inherits SelectBase - + diff --git a/src/admin/Bootstrap.Admin/Shared/Table.razor b/src/admin/Bootstrap.Admin/Shared/Table.razor index 5f809126..ea6ec07b 100644 --- a/src/admin/Bootstrap.Admin/Shared/Table.razor +++ b/src/admin/Bootstrap.Admin/Shared/Table.razor @@ -1,6 +1,22 @@ @typeparam TItem @inherits TableBase + + + AddCallback())" class="btn btn-success" asp-auth="add">新增 + 删除 + EditCallback())" class="btn btn-primary" asp-auth="edit">编辑 + + + + + AddCallback())" asp-auth="add"> + + EditCallback())" asp-auth="edit"> + + + + @TableHeader diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css index e6dd09a2..58f277e2 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css +++ b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css @@ -67,6 +67,18 @@ nav .dropdown .nav-link-close.dropdown-toggle:after { padding: 0.5rem; } +.card-body .bootstrap-table { + margin-top: 0rem; +} + +.bs-bars { + margin-bottom: 0.625rem; +} + +.bootstrap-table { + margin-bottom: 0; +} + .pagination-bar { flex: 1 1 auto; margin-bottom: 1rem; diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js index 082e9a2c..905fae65 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js +++ b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js @@ -118,6 +118,9 @@ }, initModal: function () { $('.modal').appendTo($('body')); + }, + toggleModal: function (modalId) { + $(modalId).modal('toggle'); } });