mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
6bf817d1ea
* refactor: change the name of ModalRef to ConfirmRef in order to create a Modal dialog in service mode BREAKING CHANGE: all using of ModalRef must rename to ConfirmRef * refactor: chang the name of ModalTemplate to ConfirmTemplate in order to create a Modal dialog in service mode BREAKING CHANGE: all using of ModalTemplate must rename to ConfirmTemplate * feat(module: modal): support creating Modal dialog from ModalService Co-authored-by: James Yeung <shunjiey@hotmail.com>
99 lines
2.5 KiB
C#
99 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public class ConfirmRef<TResult> : ConfirmRef
|
|
{
|
|
public Func<TResult, Task> OnCancel { get; set; }
|
|
|
|
public Func<TResult, Task> OnOk { get; set; }
|
|
|
|
internal ConfirmRef(ConfirmOptions config, ModalService service) : base(config, service)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 确定
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task TriggerOkAsync(TResult result)
|
|
{
|
|
await (_service?.CloseAsync(this) ?? Task.CompletedTask);
|
|
await (OnOk?.Invoke(result) ?? Task.CompletedTask);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task TriggerCancelAsync(TResult result)
|
|
{
|
|
await (_service.CloseAsync(this) ?? Task.CompletedTask);
|
|
await (OnCancel?.Invoke(result) ?? Task.CompletedTask);
|
|
}
|
|
}
|
|
|
|
public class ConfirmRef
|
|
{
|
|
public ConfirmOptions Config { get; set; }
|
|
|
|
protected ModalService _service;
|
|
|
|
internal IModalTemplate ModalTemplate { get; set; }
|
|
|
|
public Func<Task> OnOpen { get; set; }
|
|
|
|
public Func<Task> OnClose { get; set; }
|
|
|
|
public Func<Task> OnDestroy { get; set; }
|
|
|
|
internal bool IsCreateByModalService => _service != null;
|
|
|
|
internal ConfirmRef(ConfirmOptions config)
|
|
{
|
|
Config = config;
|
|
}
|
|
|
|
internal ConfirmRef(ConfirmOptions config, ModalService service)
|
|
{
|
|
Config = config;
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开窗体
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task OpenAsync()
|
|
{
|
|
await (_service?.OpenAsync(this) ?? Task.CompletedTask);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭窗体无返回值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task CloseAsync()
|
|
{
|
|
await (_service?.CloseAsync(this) ?? Task.CompletedTask);
|
|
}
|
|
|
|
public async Task UpdateConfig()
|
|
{
|
|
await (_service?.Update(this) ?? Task.CompletedTask);
|
|
}
|
|
|
|
public async Task UpdateConfig(ConfirmOptions config)
|
|
{
|
|
Config = config;
|
|
await (_service?.Update(this) ?? Task.CompletedTask);
|
|
}
|
|
|
|
internal TaskCompletionSource<ConfirmResult> TaskCompletionSource { get; set; }
|
|
}
|
|
}
|