Skip to content

Commit

Permalink
feat: add CloseDialogAsync method on DialogOption (#581)
Browse files Browse the repository at this point in the history
* fix: 修复客户端验证不正确问题

* refactor: 精简代码

# Conflicts:
#	src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs

* feat: DialogOption 增加 CloseDialogAsync 方法用于关闭弹窗

* doc: 格式化文档
  • Loading branch information
ArgoZhang authored Feb 26, 2023
1 parent 370dc43 commit facc626
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
option.Component = BootstrapDynamicComponent.CreateComponent<Button>(new Dictionary<string, object?>
{
[nameof(Button.Text)] = "Click to close the popup",
[nameof(Button.OnClick)] = EventCallback.Factory.Create<MouseEventArgs>(this, async () => await option.Dialog.Close())
[nameof(Button.OnClick)] = EventCallback.Factory.Create<MouseEventArgs>(this, option.CloseDialogAsync)
});
await DialogService.Show(option);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
option.Component = BootstrapDynamicComponent.CreateComponent<Button>(new Dictionary<string, object?>
{
[nameof(Button.Text)] = "Click to close the popup",
[nameof(Button.OnClick)] = EventCallback.Factory.Create<MouseEventArgs>(this, () => option.Dialog.Close())
[nameof(Button.OnClick)] = EventCallback.Factory.Create<MouseEventArgs>(this, option.CloseDialogAsync)
});

await DialogService.Show(option);
Expand Down
14 changes: 12 additions & 2 deletions src/BootstrapBlazor/Components/Dialog/DialogOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class DialogOption
/// <summary>
/// 获得/设置 相关弹窗实例
/// </summary>
[NotNull]
public Modal? Dialog { get; internal set; }
internal Modal? Dialog { get; set; }

/// <summary>
/// 获得/设置 弹窗标题
Expand Down Expand Up @@ -160,6 +159,17 @@ public class DialogOption
/// </summary>
public Func<Task>? OnShownAsync { get; set; }

/// <summary>
/// 关闭弹窗方法
/// </summary>
public async Task CloseDialogAsync()
{
if (Dialog != null)
{
await Dialog.Close();
}
}

/// <summary>
/// 将参数转换为组件属性方法
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/BootstrapBlazor/Components/Dialog/EditDialogOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public EditDialogOption()
/// </summary>
public RenderFragment<TModel>? DialogBodyTemplate { get; set; }


/// <summary>
/// 获得/设置 EditDialog Footer 模板
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions src/BootstrapBlazor/Components/Validate/ValidateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ protected TValue CurrentValue
{
_ = OnValueChanged.Invoke(value);
}
if (IsNeedValidate && FieldIdentifier != null)
{
EditContext?.NotifyFieldChanged(FieldIdentifier.Value);
}
if (ValueChanged.HasDelegate)
{
_ = ValueChanged.InvokeAsync(value);
}
if (IsNeedValidate && FieldIdentifier != null)
{
EditContext?.NotifyFieldChanged(FieldIdentifier.Value);
}
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public static async Task ShowSearchDialog<TModel>(this DialogService service, Se
[nameof(SearchDialog<TModel>.Items)] = option.Items ?? Utility.GenerateColumns<TModel>(item => item.Searchable),
[nameof(SearchDialog<TModel>.OnResetSearchClick)] = new Func<Task>(async () =>
{
await option.Dialog.Close();
await option.CloseDialogAsync();
if (option.OnResetSearchClick != null)
{
await option.OnResetSearchClick();
}
}),
[nameof(SearchDialog<TModel>.OnSearchClick)] = new Func<Task>(async () =>
{
await option.Dialog.Close();
await option.CloseDialogAsync();
if (option.OnSearchClick != null)
{
await option.OnSearchClick();
Expand Down Expand Up @@ -66,15 +66,14 @@ public static async Task ShowEditDialog<TModel>(this DialogService service, Edit
[nameof(EditDialog<TModel>.ShowLoading)] = option.ShowLoading,
[nameof(EditDialog<TModel>.ShowLabel)] = option.ShowLabel,
[nameof(EditDialog<TModel>.Items)] = option.Items ?? Utility.GenerateColumns<TModel>(item => item.Editable),
[nameof(EditDialog<TModel>.OnCloseAsync)] = option.OnCloseAsync,
[nameof(EditDialog<TModel>.OnSaveAsync)] = new Func<EditContext, Task>(async context =>
{
if (option.OnEditAsync != null)
{
var ret = await option.OnEditAsync(context);
if (ret)
{
await option.Dialog.Close();
await option.CloseDialogAsync();
}
}
}),
Expand Down Expand Up @@ -174,7 +173,7 @@ public static async Task<DialogResult> ShowModal<TDialog>(this DialogService ser
}
else
{
await option.Dialog.Close();
await option.CloseDialogAsync();
}
option.ReturnTask.SetResult(result);
}
Expand Down

0 comments on commit facc626

Please sign in to comment.