From 0fff12c7ca24cfd7bf364399da1973db7d932d45 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Mar 2022 18:36:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/SweetAlert/SwalService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs index 47e0a64fd..a303011b6 100644 --- a/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs +++ b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs @@ -48,7 +48,7 @@ public class SwalService : BootstrapServiceBase, IDisposable public async Task ShowModal(SwalOption option, SweetAlert? swal = null) { await Invoke(option, swal); - return option.IsConfirm != true || await option.ReturnTask.Task; + return !option.IsConfirm || await option.ReturnTask.Task; } /// -- Gitee From a3f80041c7f7e4edb694ee4d8abf36091cae1dc3 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Mar 2022 18:51:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=A7=BB=E5=8A=A8=20ShowModal=20=E5=88=B0=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E7=B1=BB=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SweetAlert/SwalService.cs | 12 ---------- .../Extensions/SwalExtensions.cs | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 src/BootstrapBlazor/Extensions/SwalExtensions.cs diff --git a/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs index a303011b6..f0dff6cda 100644 --- a/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs +++ b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs @@ -39,18 +39,6 @@ public class SwalService : BootstrapServiceBase, IDisposable await Invoke(option, swal); } - /// - /// 异步回调方法 - /// - /// - /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 - /// - public async Task ShowModal(SwalOption option, SweetAlert? swal = null) - { - await Invoke(option, swal); - return !option.IsConfirm || await option.ReturnTask.Task; - } - /// /// /// diff --git a/src/BootstrapBlazor/Extensions/SwalExtensions.cs b/src/BootstrapBlazor/Extensions/SwalExtensions.cs new file mode 100644 index 000000000..71c7efea5 --- /dev/null +++ b/src/BootstrapBlazor/Extensions/SwalExtensions.cs @@ -0,0 +1,24 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// Swal 扩展类 +/// +public static class SwalExtensions +{ + /// + /// 异步回调方法 + /// + /// + /// + /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 + /// + public static async Task ShowModal(this SwalService service, SwalOption option, SweetAlert? swal = null) + { + await service.Show(option, swal); + return !option.IsConfirm || await option.ReturnTask.Task; + } +} -- Gitee From 50465cbce6fac777bc3f0caf40bed41d1eb5661e Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Mar 2022 18:59:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20ShowModal=20?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=89=8B=E5=8A=A8=E8=AE=BE=E7=BD=AE=20IsConf?= =?UTF-8?q?irm=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SweetAlert/SwalOption.cs | 12 ++++++------ src/BootstrapBlazor/Extensions/SwalExtensions.cs | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs b/src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs index 769574f31..8198a9e5c 100644 --- a/src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs +++ b/src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs @@ -21,6 +21,12 @@ public class SwalOption : PopupOptionBase /// internal TaskCompletionSource ReturnTask { get; } = new TaskCompletionSource(); + /// + /// 获得/设置 是否为确认弹窗模式 默认为 false + /// + /// 此属性给模态弹窗时使用 + internal bool IsConfirm { get; set; } + /// /// 获得/设置 提示类型 默认为 Success /// @@ -56,12 +62,6 @@ public class SwalOption : PopupOptionBase /// public bool ShowFooter { get; set; } - /// - /// 获得/设置 是否为确认弹窗模式 默认为 false - /// - /// 此属性给模态弹窗时使用 - public bool IsConfirm { get; set; } - /// /// 获得/设置 按钮模板 /// diff --git a/src/BootstrapBlazor/Extensions/SwalExtensions.cs b/src/BootstrapBlazor/Extensions/SwalExtensions.cs index 71c7efea5..bf60da877 100644 --- a/src/BootstrapBlazor/Extensions/SwalExtensions.cs +++ b/src/BootstrapBlazor/Extensions/SwalExtensions.cs @@ -18,6 +18,7 @@ public static class SwalExtensions /// public static async Task ShowModal(this SwalService service, SwalOption option, SweetAlert? swal = null) { + option.IsConfirm = true; await service.Show(option, swal); return !option.IsConfirm || await option.ReturnTask.Task; } -- Gitee From 61462896917e2b224d7b97e543e6f1a4a41ac8d2 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Mar 2022 18:59:49 +0800 Subject: [PATCH 4/4] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/SwalTest.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/UnitTest/Components/SwalTest.cs b/test/UnitTest/Components/SwalTest.cs index e04d0e69f..245060d4e 100644 --- a/test/UnitTest/Components/SwalTest.cs +++ b/test/UnitTest/Components/SwalTest.cs @@ -90,8 +90,7 @@ public class SwalTest : SwalTestBase { cancel = await swal.ShowModal(new SwalOption() { - Content = "I am Swal", - IsConfirm = true + Content = "I am Swal" }); }); @@ -105,8 +104,7 @@ public class SwalTest : SwalTestBase { confirm = await swal.ShowModal(new SwalOption() { - Content = "I am Swal", - IsConfirm = true, + Content = "I am Swal" }); }); -- Gitee