From 6c14cff1ec21f3f954eea55c940b44aa18a88759 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 10 Jun 2025 12:34:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20ShowSwal?= =?UTF-8?q?=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Select/Select.razor.cs | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index 5144a13b7ca..95ca07b408a 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -52,14 +52,15 @@ public partial class Select : ISelect, ILookup public bool DisableItemChangedWhenFirstRender { get; set; } /// - /// Gets or sets the callback method before the selected item changes. Returns true to change the selected item value; otherwise, the selected item value does not change. + /// 获取/设置 选中项改变前的回调方法。返回 true 则改变选中项的值;否则选中项的值不变。 + /// Gets or sets the callback method before the selected item changes. Returns true to change the selected item value; otherwise, the selected item value does not change. /// [Parameter] public Func>? OnBeforeSelectedItemChange { get; set; } /// /// Gets or sets whether to show the Swal confirmation popup when returns true. Default is true. - /// 获得/设置 是否显示 Swal 确认弹窗 + /// 获得/设置 是否显示 Swal 确认弹窗 默认值 为 true /// [Parameter] public bool ShowSwal { get; set; } = true; @@ -342,26 +343,33 @@ public async Task ConfirmSelectedItem(int index) private async Task OnClickItem(SelectedItem item) { var ret = true; + + // 自定义回调方法 OnBeforeSelectedItemChange 返回 false 时不修改选中项 if (OnBeforeSelectedItemChange != null) { ret = await OnBeforeSelectedItemChange(item); - if (ret && ShowSwal) + return; + } + + // 如果 ShowSwal 为 true 且 则显示 Swal 确认弹窗,通过确认弹窗返回值决定是否修改选中项 + if (ShowSwal) + { + // Return true to show modal + var option = new SwalOption() + { + Category = SwalCategory, + Title = SwalTitle, + Content = SwalContent + }; + if (!string.IsNullOrEmpty(SwalFooter)) { - // Return true to show modal - var option = new SwalOption() - { - Category = SwalCategory, - Title = SwalTitle, - Content = SwalContent - }; - if (!string.IsNullOrEmpty(SwalFooter)) - { - option.ShowFooter = true; - option.FooterTemplate = builder => builder.AddContent(0, SwalFooter); - } - ret = await SwalService.ShowModal(option); + option.ShowFooter = true; + option.FooterTemplate = builder => builder.AddContent(0, SwalFooter); } + ret = await SwalService.ShowModal(option); } + + // 如果 ret 为 true 则修改选中项 if (ret) { _defaultVirtualizedItemText = item.Text; From 4d6fd479ab1f4381877eb91bcac09121565c40b3 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 10 Jun 2025 15:30:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=20ShowSwal?= =?UTF-8?q?=20=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Select/Select.razor.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index 95ca07b408a..9756f754d56 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -59,11 +59,11 @@ public partial class Select : ISelect, ILookup public Func>? OnBeforeSelectedItemChange { get; set; } /// - /// Gets or sets whether to show the Swal confirmation popup when returns true. Default is true. - /// 获得/设置 是否显示 Swal 确认弹窗 默认值 为 true + /// Gets or sets whether to show the Swal confirmation popup. Default is false. + /// 获得/设置 是否显示 Swal 确认弹窗 默认值 为 false /// [Parameter] - public bool ShowSwal { get; set; } = true; + public bool ShowSwal { get; set; } /// /// Gets or sets the callback method when the selected item changes. @@ -348,13 +348,11 @@ private async Task OnClickItem(SelectedItem item) if (OnBeforeSelectedItemChange != null) { ret = await OnBeforeSelectedItemChange(item); - return; } // 如果 ShowSwal 为 true 且 则显示 Swal 确认弹窗,通过确认弹窗返回值决定是否修改选中项 - if (ShowSwal) + if (ret && ShowSwal) { - // Return true to show modal var option = new SwalOption() { Category = SwalCategory,