2020-12-26 21:39:04 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public class ConfirmRef : FeedbackRefWithOkCancelBase
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
|
|
|
|
#region internal
|
|
|
|
|
|
|
|
|
|
internal bool IsCreateByModalService => Service != null;
|
|
|
|
|
internal TaskCompletionSource<ConfirmResult> TaskCompletionSource { get; set; }
|
|
|
|
|
|
|
|
|
|
internal ConfirmRef(ConfirmOptions config)
|
|
|
|
|
{
|
|
|
|
|
Config = config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal ConfirmRef(ConfirmOptions config, ModalService service)
|
|
|
|
|
{
|
|
|
|
|
Config = config;
|
|
|
|
|
Service = service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-07-11 20:48:16 +08:00
|
|
|
|
/// ModalService
|
2020-12-26 21:39:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
protected ModalService Service { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Confirm dialog options
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ConfirmOptions Config { get; private set; }
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
#region base inheritdoc
|
2020-12-26 21:39:04 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// close Confirm dialog
|
2020-12-26 21:39:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public override async Task CloseAsync()
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
2021-04-04 15:40:54 +08:00
|
|
|
|
await (Service?.DestroyConfirmAsync(this) ?? Task.CompletedTask);
|
2020-12-26 21:39:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
|
2020-12-26 21:39:04 +08:00
|
|
|
|
/// <summary>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// Open Confirm dialog
|
2020-12-26 21:39:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public override async Task OpenAsync()
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
2021-04-04 15:40:54 +08:00
|
|
|
|
await (Service?.OpenConfirmAsync(this) ?? Task.CompletedTask);
|
2020-12-26 21:39:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// update Confirm dialog config which Visible=true
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public override async Task UpdateConfigAsync()
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
|
|
|
|
await (Service?.UpdateConfirmAsync(this) ?? Task.CompletedTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// update Confirm dialog config with a new ConfirmOptions
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="config"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task UpdateConfigAsync(ConfirmOptions config)
|
|
|
|
|
{
|
|
|
|
|
Config = config;
|
|
|
|
|
await UpdateConfigAsync();
|
|
|
|
|
}
|
2021-04-04 15:40:54 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
2020-12-26 21:39:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
|
2020-12-26 21:39:04 +08:00
|
|
|
|
/// <summary>
|
2021-07-11 20:48:16 +08:00
|
|
|
|
/// ConfirmRef with return value
|
2020-12-26 21:39:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TResult"></typeparam>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public class ConfirmRef<TResult> : ConfirmRef, IOkCancelRef<TResult>
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
|
|
|
|
internal ConfirmRef(ConfirmOptions config, ModalService service) : base(config, service)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public new Func<TResult, Task> OnCancel { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public new Func<TResult, Task> OnOk { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task OkAsync(TResult result)
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
|
|
|
|
await (OnOk?.Invoke(result) ?? Task.CompletedTask);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task CancelAsync(TResult result)
|
2020-12-26 21:39:04 +08:00
|
|
|
|
{
|
|
|
|
|
await (OnCancel?.Invoke(result) ?? Task.CompletedTask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|