mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-14 17:01:18 +08:00
8f00e1d393
* feat: drawer support return value * feat: drawer supports return value * feat: drawer support return value * feat: drawer support return value * docs: avoid duplicate names * fix: demo Co-authored-by: ElderJames <shunjiey@hotmail.com>
87 lines
2.0 KiB
C#
87 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public class DrawerRef<TResult> : DrawerRef
|
|
{
|
|
public new Func<TResult, Task> OnClose { get; set; }
|
|
|
|
internal DrawerRef(DrawerConfig config, DrawerService service) : base(config, service)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭抽屉
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task CloseAsync(TResult result)
|
|
{
|
|
await _service.CloseAsync(this);
|
|
await OnClose.Invoke(result);
|
|
}
|
|
|
|
}
|
|
|
|
public class DrawerRef
|
|
{
|
|
public DrawerConfig Config { get; set; }
|
|
public Drawer Drawer { get; set; }
|
|
|
|
protected DrawerService _service;
|
|
|
|
public Func<Task> OnOpen { get; set; }
|
|
|
|
public Func<Task> OnClose { get; set; }
|
|
|
|
internal DrawerRef(DrawerConfig config)
|
|
{
|
|
Config = config;
|
|
}
|
|
|
|
internal DrawerRef(DrawerConfig config, DrawerService service)
|
|
{
|
|
Config = config;
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开抽屉
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task OpenAsync()
|
|
{
|
|
await _service.OpenAsync(this);
|
|
if (OnOpen != null)
|
|
await OnOpen.Invoke();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭抽屉无返回值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task CloseAsync()
|
|
{
|
|
await _service.CloseAsync(this);
|
|
if (OnClose != null)
|
|
await OnClose.Invoke();
|
|
}
|
|
|
|
|
|
internal async Task HandleOnCancel()
|
|
{
|
|
bool isClose = true;
|
|
if (Config.OnCancel != null)
|
|
{
|
|
isClose = Config.OnCancel.Invoke() ?? true;
|
|
}
|
|
if (isClose == true)
|
|
await _service.CloseAsync(this);
|
|
|
|
}
|
|
}
|
|
}
|