mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-14 00:41:30 +08:00
31aac9f914
* refactor: support to use the same template for confirm and modal * refactor: support to use the same template for drawer * refactor: separate interface IOkCancelRef * chore: modify EventUtil class summary Co-authored-by: James Yeung <shunjiey@hotmail.com>
111 lines
3.0 KiB
C#
111 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public class DrawerRef : FeedbackRefBase
|
|
{
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
[Obsolete("Please replace it with Config")]
|
|
public DrawerOptions Options => Config;
|
|
|
|
public DrawerOptions Config { get; private set; }
|
|
|
|
public Drawer Drawer { get; set; }
|
|
|
|
public Func<ModalClosingEventArgs, Task> OnClosing { get; set; }
|
|
|
|
protected readonly DrawerService _service;
|
|
|
|
internal DrawerRef(DrawerOptions options, DrawerService service)
|
|
{
|
|
Config = options;
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// close Confirm dialog
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override async Task CloseAsync()
|
|
{
|
|
var e = new ModalClosingEventArgs();
|
|
await (OnClosing?.Invoke(e) ?? Task.CompletedTask);
|
|
if (!e.Cancel)
|
|
{
|
|
await _service.CloseAsync(this);
|
|
if (OnClose != null)//before close
|
|
await OnClose.Invoke();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Open Confirm dialog
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override async Task OpenAsync()
|
|
{
|
|
await _service.OpenAsync(this);
|
|
if (OnOpen != null)
|
|
await OnOpen.Invoke();
|
|
}
|
|
|
|
/// <summary>
|
|
/// update Confirm dialog config which Visible=true
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override async Task UpdateConfigAsync()
|
|
{
|
|
await (_service?.UpdateAsync(this) ?? Task.CompletedTask);
|
|
}
|
|
|
|
/// <summary>
|
|
/// update Confirm dialog config with a new ConfirmOptions
|
|
/// </summary>
|
|
/// <param name="config"></param>
|
|
/// <returns></returns>
|
|
public async Task UpdateConfigAsync(DrawerOptions config)
|
|
{
|
|
Config = config;
|
|
await UpdateConfigAsync();
|
|
}
|
|
}
|
|
|
|
public class DrawerRef<TResult> : DrawerRef
|
|
{
|
|
internal TaskCompletionSource<TResult> TaskCompletionSource { get; set; }
|
|
|
|
public Func<TResult, Task> OnClosed { get; set; }
|
|
|
|
internal DrawerRef(DrawerOptions options, DrawerService service) :base(options,service)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭抽屉
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task CloseAsync(TResult result)
|
|
{
|
|
var closeEventArgs = new ModalClosingEventArgs();
|
|
|
|
if (OnClosing != null)//before close
|
|
await OnClosing.Invoke(closeEventArgs);
|
|
|
|
if (closeEventArgs.Cancel)
|
|
return;
|
|
|
|
await _service.CloseAsync(this);
|
|
|
|
if (OnClosed != null)//after close
|
|
await OnClosed.Invoke(result);
|
|
|
|
TaskCompletionSource?.SetResult(result);
|
|
}
|
|
}
|
|
}
|