diff --git a/src/admin/Bootstrap.Admin/Pages/Components/AssignModalBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/AssignModalBase.cs new file mode 100644 index 00000000..ec6d46b7 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Pages/Components/AssignModalBase.cs @@ -0,0 +1,114 @@ +using Bootstrap.Admin.Pages.Shared; +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bootstrap.Admin.Pages.Components +{ + /// + /// 模态框组件类 + /// + public class AssignModalBase : ComponentBase + { +#nullable disable + /// + /// 获得/设置 数据绑定项 + /// + [Parameter] + public TItem Item { get; set; } +#nullable restore + + /// + /// 获得/设置 Modal 实例 + /// + [Parameter] + public ModalBase? Modal { get; set; } + + /// + /// 获得/设置 Id + /// + [Parameter] + public string Id { get; set; } = ""; + + /// + /// 获得/设置 弹窗标题 + /// + [Parameter] + public string Title { get; set; } = "未设置"; + + /// + /// 获得/设置 表格 Toolbar 按钮模板 + /// + [Parameter] + public RenderFragment? ItemTemplate { get; set; } + + /// + /// 获得/设置 Items + /// + public IEnumerable Items { get; set; } = new TItem[0]; + + /// + /// Toast 组件实例 + /// + protected Toast? Toast { get; set; } + + /// + /// 显示提示信息 + /// + /// + /// + /// + protected void ShowMessage(string title, string text, ToastCategory cate = ToastCategory.Success) => Toast?.ShowMessage(title, text, cate); + + /// + /// 获得/设置 保存回调事件 + /// + [Parameter] + public Func, bool>? OnSave { get; set; } + + /// + /// OnAfterRender 方法 + /// + /// + protected override void OnAfterRender(bool firstRender) + { + if (show) + { + show = false; + Modal?.Toggle(); + } + } + + /// + /// SetParametersAsync 方法 + /// + public override Task SetParametersAsync(ParameterView parameters) + { + parameters.SetParameterProperties(this); + if (string.IsNullOrEmpty(Id)) throw new InvalidOperationException("Modal Component Id property must be set"); + return base.SetParametersAsync(ParameterView.Empty); + } + + /// + /// Save 方法 + /// + protected void Save() + { + bool ret = OnSave?.Invoke(Items) ?? false; + Modal?.Toggle(); + ShowMessage(Title, ret ? "保存成功" : "保存失败", ret ? ToastCategory.Success : ToastCategory.Error); + } + + private bool show; + /// + /// Update 方法 + /// + public void Update(IEnumerable items) + { + Items = items; + show = true; + StateHasChanged(); + } + } +} diff --git a/src/admin/Bootstrap.Admin/Pages/Components/CheckboxBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/CheckboxBase.cs index 5cc91f9c..7a9a70a1 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/CheckboxBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/CheckboxBase.cs @@ -32,31 +32,31 @@ namespace Bootstrap.Admin.Pages.Components /// 勾选回调方法 /// [Parameter] - public Action ToggleCallback { get; set; } = new Action((v, c) => { }); + public Action? OnClick { get; set; } /// - /// + /// 组件状态改变回调方法 /// [Parameter] - public Func SetCheckCallback { get; set; } = new Func(item => CheckBoxState.UnChecked); + public Func? SetCheckCallback { get; set; } /// - /// + /// OnParametersSet 方法 /// protected override void OnParametersSet() { - State = SetCheckCallback(Item); + State = SetCheckCallback?.Invoke(Item) ?? CheckBoxState.UnChecked; Checked = State == CheckBoxState.Checked; } /// - /// + /// 获得/设置 选择框状态 /// [Parameter] public CheckBoxState State { get; set; } /// - /// + /// RenderStateCss 方法 /// /// protected string RenderStateCss() @@ -75,5 +75,15 @@ namespace Bootstrap.Admin.Pages.Components } return ret; } + + /// + /// 点击选择框方法 + /// + protected void ToggleClick() + { + Checked = !Checked; + State = Checked ? CheckBoxState.Checked : CheckBoxState.UnChecked; + OnClick?.Invoke(Item, Checked); + } } } diff --git a/src/admin/Bootstrap.Admin/Pages/Components/EditPageBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/EditPageBase.cs index c8205e88..f7ae0333 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/EditPageBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/EditPageBase.cs @@ -160,6 +160,11 @@ namespace Bootstrap.Admin.Pages.Components } } + /// + /// 获得 Table 组件选择项目集合 + /// + public IEnumerable SelectedItems { get { return Table?.SelectedItems ?? new List(); } } + /// /// 分页查询方法 /// diff --git a/src/admin/Bootstrap.Admin/Pages/Components/ModalBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/ModalBase.cs index f96e3721..b7f199a9 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/ModalBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/ModalBase.cs @@ -1,7 +1,7 @@ -using Bootstrap.Admin.Pages.Extensions; -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System; +using System.Threading.Tasks; namespace Bootstrap.Admin.Pages.Components { @@ -11,13 +11,13 @@ namespace Bootstrap.Admin.Pages.Components public class ModalBase : ComponentBase { /// - /// + /// 获得/设置 IJSRuntime 实例 /// [Inject] protected IJSRuntime? JSRuntime { get; set; } /// - /// + /// 获得/设置 ModalBody 代码块 /// [Parameter] public RenderFragment? ModalBody { get; set; } @@ -29,13 +29,13 @@ namespace Bootstrap.Admin.Pages.Components public RenderFragment? ModalFooter { get; set; } /// - /// + /// 获得/设置 Id /// [Parameter] public string Id { get; set; } = ""; /// - /// + /// 获得/设置 弹窗标题 /// [Parameter] public string Title { get; set; } = "未设置"; @@ -65,7 +65,7 @@ namespace Bootstrap.Admin.Pages.Components public bool ShowFooter { get; set; } = true; /// - /// + /// OnAfterRender 方法 /// /// protected override void OnAfterRender(bool firstRender) @@ -111,7 +111,7 @@ namespace Bootstrap.Admin.Pages.Components } /// - /// + /// Toggle 弹窗方法 /// public void Toggle() { @@ -125,19 +125,19 @@ namespace Bootstrap.Admin.Pages.Components public enum ModalSize { /// - /// + /// 默认大小 /// Default, /// - /// + /// 小窗口 /// Small, /// - /// + /// 大窗口 /// Large, /// - /// + /// 超大窗口 /// ExtraLarge, } diff --git a/src/admin/Bootstrap.Admin/Pages/Shared/AssignModal.razor b/src/admin/Bootstrap.Admin/Pages/Shared/AssignModal.razor new file mode 100644 index 00000000..7453ae7d --- /dev/null +++ b/src/admin/Bootstrap.Admin/Pages/Shared/AssignModal.razor @@ -0,0 +1,29 @@ +@typeparam TItem +@inherits AssignModalBase + + + +
+
+ @foreach(var item in Items) + { +
+ @ItemTemplate?.Invoke(item) +
+ } +
+
+
+ + + + +
+ + diff --git a/src/admin/Bootstrap.Admin/Pages/Shared/Checkbox.razor b/src/admin/Bootstrap.Admin/Pages/Shared/Checkbox.razor index 1bb45d3c..c2c3c5f5 100644 --- a/src/admin/Bootstrap.Admin/Pages/Shared/Checkbox.razor +++ b/src/admin/Bootstrap.Admin/Pages/Shared/Checkbox.razor @@ -1,7 +1,7 @@ @typeparam TItem @inherits CheckboxBase -