2020-03-22 21:24:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-07-12 23:19:55 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
2020-03-22 21:24:41 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-03-22 21:24:41 +08:00
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
public class DrawerRef<TResult> : DrawerRef
|
|
|
|
|
{
|
|
|
|
|
public new Func<TResult, Task> OnClose { get; set; }
|
|
|
|
|
|
2020-07-12 23:19:55 +08:00
|
|
|
|
internal DrawerRef(DrawerOptions config, DrawerService service) : base(config, service)
|
2020-06-30 13:40:51 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭抽屉
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task CloseAsync(TResult result)
|
|
|
|
|
{
|
|
|
|
|
await _service.CloseAsync(this);
|
|
|
|
|
await OnClose.Invoke(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 21:24:41 +08:00
|
|
|
|
public class DrawerRef
|
|
|
|
|
{
|
2020-07-12 23:19:55 +08:00
|
|
|
|
public DrawerOptions Config { get; set; }
|
2020-06-30 13:40:51 +08:00
|
|
|
|
public Drawer Drawer { get; set; }
|
|
|
|
|
|
|
|
|
|
protected DrawerService _service;
|
|
|
|
|
|
|
|
|
|
public Func<Task> OnOpen { get; set; }
|
|
|
|
|
|
2020-09-09 11:33:41 +08:00
|
|
|
|
public Func<DrawerClosingEventArgs, Task> OnClose { get; set; }
|
2020-06-23 15:19:44 +08:00
|
|
|
|
|
2020-07-12 23:19:55 +08:00
|
|
|
|
internal DrawerRef(DrawerOptions config)
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
Config = config;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 23:19:55 +08:00
|
|
|
|
internal DrawerRef(DrawerOptions config, DrawerService service)
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
Config = config;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
_service = service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-09-09 11:33:41 +08:00
|
|
|
|
/// open a drawer
|
2020-06-23 15:19:44 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-06-30 13:40:51 +08:00
|
|
|
|
public async Task OpenAsync()
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
await _service.OpenAsync(this);
|
|
|
|
|
if (OnOpen != null)
|
|
|
|
|
await OnOpen.Invoke();
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// <summary>
|
2020-09-09 11:33:41 +08:00
|
|
|
|
/// close the drawer without return value
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task CloseAsync()
|
|
|
|
|
{
|
|
|
|
|
await _service.CloseAsync(this);
|
|
|
|
|
if (OnClose != null)
|
2020-09-09 11:33:41 +08:00
|
|
|
|
await OnClose.Invoke(new DrawerClosingEventArgs(false));
|
2020-06-30 13:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal async Task HandleOnCancel()
|
|
|
|
|
{
|
2020-07-12 23:19:55 +08:00
|
|
|
|
var args = new DrawerClosingEventArgs(false);
|
2020-09-09 11:33:41 +08:00
|
|
|
|
if (OnClose != null)
|
2020-06-30 13:40:51 +08:00
|
|
|
|
{
|
2020-09-09 11:33:41 +08:00
|
|
|
|
await OnClose.Invoke(args);
|
2020-06-30 13:40:51 +08:00
|
|
|
|
}
|
2020-09-09 11:33:41 +08:00
|
|
|
|
if (!args.Cancel)
|
2020-06-30 13:40:51 +08:00
|
|
|
|
await _service.CloseAsync(this);
|
|
|
|
|
}
|
2020-03-22 21:24:41 +08:00
|
|
|
|
}
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|