-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathSwalExtensions.cs
More file actions
73 lines (70 loc) · 3.17 KB
/
SwalExtensions.cs
File metadata and controls
73 lines (70 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
namespace BootstrapBlazor.Components;
/// <summary>
/// <para lang="zh">Swal 扩展类</para>
/// <para lang="en">Swal 扩展类</para>
/// </summary>
public static class SwalExtensions
{
/// <summary>
/// <para lang="zh">异步回调方法</para>
/// <para lang="en">异步callback method</para>
/// </summary>
/// <param name="service"></param>
/// <param name="option"></param>
/// <param name="swal"><para lang="zh">指定弹窗组件 默认为 null 使用 <see cref="BootstrapBlazorRoot"/> 组件内置弹窗组件</para><para lang="en">指定弹窗component default is为 null 使用 <see cref="BootstrapBlazorRoot"/> component内置弹窗component</para></param>
public static async Task<bool> ShowModal(this SwalService service, SwalOption option, SweetAlert? swal = null)
{
option.IsConfirm = true;
await service.Show(option, swal);
return await option.ConfirmContext.ConfirmTask.Task;
}
/// <summary>
/// <para lang="zh">将配置信息转化为参数集合</para>
/// <para lang="en">将配置信息转化为参数collection</para>
/// </summary>
/// <param name="option"></param>
public static IDictionary<string, object?> Parse(this SwalOption option) => new Dictionary<string, object?>()
{
[nameof(SweetAlertBody.Category)] = option.Category,
[nameof(SweetAlertBody.ShowClose)] = option.ShowClose,
[nameof(SweetAlertBody.IsConfirm)] = option.IsConfirm,
[nameof(SweetAlertBody.ShowFooter)] = option.ShowFooter,
[nameof(SweetAlertBody.OnCloseAsync)] = async () =>
{
if (option.IsConfirm)
{
option.ConfirmContext.Value = false;
}
if (option.OnCloseAsync != null)
{
await option.OnCloseAsync();
}
},
[nameof(SweetAlertBody.OnConfirmAsync)] = async () =>
{
if (option.IsConfirm)
{
option.ConfirmContext.Value = true;
}
if (option.OnConfirmAsync != null)
{
await option.OnConfirmAsync();
}
},
[nameof(SweetAlertBody.Title)] = option.Title,
[nameof(SweetAlertBody.Content)] = option.Content,
[nameof(SweetAlertBody.BodyTemplate)] = option.BodyTemplate,
[nameof(SweetAlertBody.Footer)] = option.Footer,
[nameof(SweetAlertBody.FooterTemplate)] = option.FooterTemplate,
[nameof(SweetAlertBody.ButtonTemplate)] = option.ButtonTemplate,
[nameof(SweetAlertBody.CloseButtonIcon)] = option.CloseButtonIcon,
[nameof(SweetAlertBody.ConfirmButtonIcon)] = option.ConfirmButtonIcon,
[nameof(SweetAlertBody.CloseButtonText)] = option.CloseButtonText,
[nameof(SweetAlertBody.CancelButtonText)] = option.CancelButtonText,
[nameof(SweetAlertBody.ConfirmButtonText)] = option.ConfirmButtonText
};
}