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>
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public partial class DrawerContainer
|
|
{
|
|
[Inject]
|
|
private DrawerService DrawerService { get; set; }
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
DrawerService.OnCloseEvent += DrawerService_OnClose;
|
|
DrawerService.OnOpenEvent += DrawerService_OnCreate;
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
DrawerService.OnCloseEvent -= DrawerService_OnClose;
|
|
DrawerService.OnOpenEvent -= DrawerService_OnCreate;
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private List<DrawerRef> _drawerRefs = new List<DrawerRef>();
|
|
|
|
|
|
/// <summary>
|
|
/// 创建并打开抽屉
|
|
/// </summary>
|
|
private async Task DrawerService_OnCreate(DrawerRef drawerRef)
|
|
{
|
|
drawerRef.Config.Visible = true;
|
|
if (!_drawerRefs.Contains(drawerRef))
|
|
{
|
|
_drawerRefs.Add(drawerRef);
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭抽屉
|
|
/// </summary>
|
|
private async Task DrawerService_OnClose(DrawerRef drawerRef)
|
|
{
|
|
drawerRef.Config.Visible = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
await Task.Delay(300);
|
|
if (_drawerRefs.Contains(drawerRef))
|
|
{
|
|
_drawerRefs.Remove(drawerRef);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|