2020-07-12 23:19:55 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ModalRef : FeedbackRefWithOkCancelBase
|
2020-07-12 23:19:55 +08:00
|
|
|
|
{
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public ModalOptions Config { get; private set; }
|
2020-10-14 15:09:11 +08:00
|
|
|
|
private readonly ModalService _service;
|
2020-07-12 23:19:55 +08:00
|
|
|
|
|
2020-10-14 15:09:11 +08:00
|
|
|
|
internal ModalRef(ModalOptions config, ModalService modalService)
|
2020-07-12 23:19:55 +08:00
|
|
|
|
{
|
|
|
|
|
Config = config;
|
2020-10-14 15:09:11 +08:00
|
|
|
|
_service = modalService;
|
2020-07-12 23:19:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-10-14 15:09:11 +08:00
|
|
|
|
/// open the Modal dialog
|
2020-07-12 23:19:55 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public override async Task OpenAsync()
|
2020-07-12 23:19:55 +08:00
|
|
|
|
{
|
2020-10-14 15:09:11 +08:00
|
|
|
|
if (!Config.Visible)
|
|
|
|
|
{
|
|
|
|
|
Config.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _service.CreateOrOpenModalAsync(this);
|
2020-07-12 23:19:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
|
2020-07-12 23:19:55 +08:00
|
|
|
|
/// <summary>
|
2020-10-14 15:09:11 +08:00
|
|
|
|
/// close the Modal dialog
|
2020-07-12 23:19:55 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
public override async Task CloseAsync()
|
2020-07-12 23:19:55 +08:00
|
|
|
|
{
|
2020-10-14 15:09:11 +08:00
|
|
|
|
await _service.CloseModalAsync(this);
|
2020-07-12 23:19:55 +08:00
|
|
|
|
}
|
2021-04-04 15:40:54 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update modal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task UpdateConfigAsync()
|
|
|
|
|
{
|
|
|
|
|
await _service.UpdateModalAsync(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-07-11 20:48:16 +08:00
|
|
|
|
/// ModalRef with return value
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TResult"></typeparam>
|
|
|
|
|
public class ModalRef<TResult> : ModalRef, IOkCancelRef<TResult>
|
|
|
|
|
{
|
|
|
|
|
internal ModalRef(ModalOptions config, ModalService modalService) : base(config, modalService)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
await (OnOk?.Invoke(result) ?? Task.CompletedTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task CancelAsync(TResult result)
|
|
|
|
|
{
|
|
|
|
|
await (OnOk?.Invoke(result) ?? Task.CompletedTask);
|
|
|
|
|
}
|
2020-07-12 23:19:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|