diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor index df16854f3d2..62e2915e225 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor @@ -107,6 +107,43 @@ + +
+

@((MarkupString)Localizer["TablesKeepAddingDescription"].Value)

+

@((MarkupString)Localizer["TablesKeepAddingTips"].Value)

+
+ + + + + + + + +
+ +
+

@((MarkupString)Localizer["TablesKeepAddingDrawerDescription"].Value)

+
+ + + + + + + + +
+
+
@((MarkupString)Localizer["TablesColumnEditTemplateDescription1"].Value)
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor.cs index e24d544beec..4754e75edfe 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesEdit.razor.cs @@ -32,6 +32,12 @@ public partial class TablesEdit [NotNull] private IEnumerable? BindItems { get; set; } + [NotNull] + private IEnumerable? KeepAddingItems { get; set; } + + [NotNull] + private IEnumerable? KeepAddingDrawerItems { get; set; } + private InsertRowMode InsertMode { get; set; } = InsertRowMode.Last; private string? PlaceHolderString { get; set; } @@ -58,10 +64,44 @@ protected override void OnInitialized() CustomerDataService = new FooDataService(FooLocalizer); BindItems = Foo.GenerateFoo(FooLocalizer).Take(5).ToList(); PlaceHolderString ??= Localizer["TablesEditShowSearchPlaceHolderString"]; + + var keepAddingItems = Foo.GenerateFoo(FooLocalizer, 4); + + // 数量列从 0 开始 便于观察连续新增时数量递增的效果 + keepAddingItems.ForEach(i => i.Count = 0); + KeepAddingItems = keepAddingItems; + + var keepAddingDrawerItems = Foo.GenerateFoo(FooLocalizer, 4); + keepAddingDrawerItems.ForEach(i => i.Count = 0); + KeepAddingDrawerItems = keepAddingDrawerItems; } private Task OnAddAsync() => Task.FromResult(new Foo() { Id = GenerateId(), DateTime = DateTime.Now, Address = $"Custom address {DateTime.Now.Second}" }); + private Task OnKeepAddAsync() => Task.FromResult(Foo.Generate(FooLocalizer)); + + /// + /// 点击「保存并新增」按钮时基于上一条已保存数据创建下一条模型 数量 +10 + /// + /// 刚刚保存成功的模型实例 + private static async Task OnKeepAddingAsync(Foo lastModel) + { + // 模拟延时 + await Task.Delay(10); + + return new Foo() + { + Id = lastModel.Id + 1, + DateTime = lastModel.DateTime, + Name = lastModel.Name, + Address = lastModel.Address, + Complete = lastModel.Complete, + Education = lastModel.Education, + Hobby = lastModel.Hobby, + Count = lastModel.Count + 10 + }; + } + private int GenerateId() { var id = Items.Count; diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 0ca7e2778b8..caba3e897cd 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -5066,6 +5066,11 @@ "TablesEditTemplateIntro": "Set ShowSearch to show the query component", "TablesEditTemplateTitle": "Tables with single table maintenance", "TablesEditTitle": "Table", + "TablesKeepAddingDescription": "The next item is created by the OnKeepAddingAsync callback whose parameter is the model saved just now. In this example the Count of the new item is the Count of the previous item plus 10", + "TablesKeepAddingDrawerDescription": "The table below uses EditMode.Drawer, and keep adding behaves exactly the same as in dialog mode", + "TablesKeepAddingIntro": "Set ShowKeepAddingButton to show the Save and Add button in the New dialog/drawer footer. Clicking it saves the current item and keeps the UI open, and the next item is created by the OnKeepAddingAsync callback for continuous input", + "TablesKeepAddingTips": "Note: when the OnKeepAddingAsync callback is not set, the component falls back to the OnAddAsync callback, CreateItemCallback and the AddAsync method of the injected IDataService in order, which is the same as before, except that the OnKeepAddingAsync callback has the highest priority", + "TablesKeepAddingTitle": "Keep adding", "TablesReadonlyColumnDescription": "Corresponding database calculated columns, or model read-only attributes", "TablesReadonlyColumnIntro": "By setting Field and FieldName", "TablesReadonlyColumnTips1": "Do not write @bind-Field. Read-only columns cannot be entered when Add or Edit", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 58547c207b0..2ad776c2d8d 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -5066,6 +5066,11 @@ "TablesEditTemplateIntro": "通过设置 EditTemplate 自定义编辑弹窗,10.0.1 版本后支持联动功能", "TablesEditTemplateTitle": "具有单表维护功能的表格", "TablesEditTitle": "Table 表格", + "TablesKeepAddingDescription": "下一条数据由 OnKeepAddingAsync 回调创建,回调参数为刚刚保存成功的模型实例;本示例中新数据的 Count 为上一笔数据的 Count 加 10", + "TablesKeepAddingDrawerDescription": "下表中 EditMode 为 Drawer,连续新增在抽屉模式下具有与弹窗模式完全一致的行为", + "TablesKeepAddingIntro": "设置 ShowKeepAddingButton 在 新建 弹窗/抽屉 Footer 中显示 保存并新增 按钮,点击后先保存当前数据并保持界面打开,下一条数据由 OnKeepAddingAsync 回调创建以便连续录入", + "TablesKeepAddingTips": "注意:未设置 OnKeepAddingAsync 回调时,组件依次回落调用 OnAddAsync、CreateItemCallback 以及注入服务 IDataService 的 AddAsync 方法,此处知识点与以前一致,仅优先执行 OnKeepAddingAsync 回调", + "TablesKeepAddingTitle": "连续新增", "TablesReadonlyColumnDescription": "对应数据库计算列,或者模型只读属性", "TablesReadonlyColumnIntro": "通过设置 Field 与 FieldName 即可", "TablesReadonlyColumnTips1": "不要写 @bind-Field 只读列在 新建 或者 编辑 时均无法录入", diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 00d482fedc4..6903cd84772 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 11.0.1-beta02 + 11.0.1-beta03 diff --git a/src/BootstrapBlazor/Components/Dialog/EditDialog.razor b/src/BootstrapBlazor/Components/Dialog/EditDialog.razor index 4591eee23fa..f59eb24c7e5 100644 --- a/src/BootstrapBlazor/Components/Dialog/EditDialog.razor +++ b/src/BootstrapBlazor/Components/Dialog/EditDialog.razor @@ -3,14 +3,15 @@ @inherits DialogBase @attribute [BootstrapModuleAutoLoader("Dialog/EditDialog.razor.js", AutoInvokeInit = false, AutoInvokeDispose = false)] - @if (BodyTemplate != null) {
- @BodyTemplate(Model) + @BodyTemplate(_currentModel)
+ +@code { + /// + /// 获得 编辑弹窗 Footer 内容 + /// Gets the Footer content of the edit dialog + /// + private RenderFragment RenderFooter => @ + @if (FooterTemplate != null) + { + @FooterTemplate(_currentModel) + } + else + { + @if (!IsTracking) + { + + } + + @* 「保存并新增」先于主保存按钮渲染 作为表单默认按钮 未禁用回车提交时按「保存并新增」处理 *@ + @if (IsKeepAdding) + { +