From 77832889630c85a66ca99c26feb3029a49b7abd5 Mon Sep 17 00:00:00 2001 From: Argo-Cloud Date: Mon, 29 Mar 2021 15:26:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E9=AA=8C=E8=AF=81=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E6=94=AF=E6=8C=81=E5=BC=82=E6=AD=A5=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Button/Button.razor.cs | 46 +++++++++++++++++++ .../Components/Validate/ValidateBase.cs | 2 +- .../ValidateForm/ValidateForm.razor | 2 +- .../ValidateForm/ValidateForm.razor.cs | 39 +++++++++++----- 4 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 src/BootstrapBlazor/Components/Button/Button.razor.cs diff --git a/src/BootstrapBlazor/Components/Button/Button.razor.cs b/src/BootstrapBlazor/Components/Button/Button.razor.cs new file mode 100644 index 000000000..5ef009488 --- /dev/null +++ b/src/BootstrapBlazor/Components/Button/Button.razor.cs @@ -0,0 +1,46 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using BootstrapBlazor.Components; +using Microsoft.AspNetCore.Components; +using System; + +namespace BootstrapBlazor.Components +{ + /// + /// + /// + public partial class Button + { + /// + /// 获得 ValidateForm 实例 + /// + [CascadingParameter] + protected ValidateForm? ValidateForm { get; set; } + + /// + /// OnInitialized 方法 + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + if (IsAsync && ValidateForm != null) + { + // 开启异步操作时与 ValidateForm 联动 + ValidateForm.RegisterAsyncSubmitButton(this); + } + } + + /// + /// 触发按钮异步操作方法 + /// + /// true 时显示正在操作 false 时表示结束 + internal void TriggerAsync(bool loading) + { + ButtonIcon = loading ? LoadingIcon : Icon; + SetDisable(loading); + } + } +} diff --git a/src/BootstrapBlazor/Components/Validate/ValidateBase.cs b/src/BootstrapBlazor/Components/Validate/ValidateBase.cs index 501dc5acd..003cde416 100644 --- a/src/BootstrapBlazor/Components/Validate/ValidateBase.cs +++ b/src/BootstrapBlazor/Components/Validate/ValidateBase.cs @@ -236,7 +236,7 @@ namespace BootstrapBlazor.Components protected EditContext? CascadedEditContext { get; set; } /// - /// 获得 ValidateFormBase 实例 + /// 获得 ValidateForm 实例 /// [CascadingParameter] protected ValidateForm? EditForm { get; set; } diff --git a/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor b/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor index c602b124a..75aeef639 100644 --- a/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor +++ b/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor @@ -2,7 +2,7 @@ @inherits IdComponentBase - + @ChildContent diff --git a/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs b/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs index d20eaaca0..6169e7e9b 100644 --- a/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs +++ b/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs @@ -5,7 +5,6 @@ using BootstrapBlazor.Localization.Json; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System; using System.Collections.Concurrent; @@ -22,17 +21,8 @@ namespace BootstrapBlazor.Components /// /// ValidateForm 组件类 /// - public sealed partial class ValidateForm + public partial class ValidateForm { - /// - /// A callback that will be invoked when the form is submitted. - /// If using this parameter, you are responsible for triggering any validation - /// manually, e.g., by calling . - /// - [Parameter] - [NotNull] - public Func? OnSubmit { get; set; } - /// /// A callback that will be invoked when the form is submitted and the /// is determined to be valid. @@ -334,5 +324,32 @@ namespace BootstrapBlazor.Components } } } + + private List