diff --git a/src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs b/src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs index 769574f3168686f6e24483279f61983ed2c9c79c..8198a9e5c1ebbf7a6661bda9d13d58e8482b93dd 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/Components/SweetAlert/SwalService.cs b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs index 47e0a64fd7ee130e807c1a64e95043cf6f03f58a..f0dff6cdaee9a33acea5b9dc4741593bec06d198 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 != true || await option.ReturnTask.Task; - } - /// /// /// diff --git a/src/BootstrapBlazor/Extensions/SwalExtensions.cs b/src/BootstrapBlazor/Extensions/SwalExtensions.cs new file mode 100644 index 0000000000000000000000000000000000000000..bf60da877760827b6fa30d41098cf3e0e042be5a --- /dev/null +++ b/src/BootstrapBlazor/Extensions/SwalExtensions.cs @@ -0,0 +1,25 @@ +// 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) + { + option.IsConfirm = true; + await service.Show(option, swal); + return !option.IsConfirm || await option.ReturnTask.Task; + } +} diff --git a/test/UnitTest/Components/SwalTest.cs b/test/UnitTest/Components/SwalTest.cs index e04d0e69f30671e055f06877e9daacfa3399a8d7..245060d4e136a818cebd704afc577ff00ef921cd 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" }); });