2020-06-23 15:19:44 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
DrawerService.OnCloseEvent += DrawerService_OnClose;
|
|
|
|
|
DrawerService.OnOpenEvent += DrawerService_OnCreate;
|
2021-04-04 15:40:54 +08:00
|
|
|
|
DrawerService.OnUpdateEvent += DrawerService_OnUpdateEvent;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
DrawerService.OnCloseEvent -= DrawerService_OnClose;
|
|
|
|
|
DrawerService.OnOpenEvent -= DrawerService_OnCreate;
|
2021-04-04 15:40:54 +08:00
|
|
|
|
DrawerService.OnUpdateEvent -= DrawerService_OnUpdateEvent;
|
|
|
|
|
|
2020-06-23 15:19:44 +08:00
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
private readonly List<DrawerRef> _drawerRefs = new List<DrawerRef>();
|
2020-06-23 15:19:44 +08:00
|
|
|
|
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// <summary>
|
2020-09-16 19:42:48 +08:00
|
|
|
|
/// Create and Open a drawer
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// </summary>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
private async Task DrawerService_OnCreate(DrawerRef drawerRef)
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2021-04-04 15:40:54 +08:00
|
|
|
|
drawerRef.Config.Visible = true;
|
2020-06-30 13:40:51 +08:00
|
|
|
|
if (!_drawerRefs.Contains(drawerRef))
|
|
|
|
|
{
|
|
|
|
|
_drawerRefs.Add(drawerRef);
|
|
|
|
|
}
|
2020-06-23 15:19:44 +08:00
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update drawer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="drawerRef"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task DrawerService_OnUpdateEvent(DrawerRef drawerRef)
|
|
|
|
|
{
|
|
|
|
|
if (_drawerRefs.Contains(drawerRef))
|
|
|
|
|
{
|
|
|
|
|
await InvokeStateHasChangedAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// <summary>
|
2020-09-16 19:42:48 +08:00
|
|
|
|
/// Close the drawer
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// </summary>
|
2021-04-04 15:40:54 +08:00
|
|
|
|
private async Task DrawerService_OnClose(DrawerRef drawerRef)
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2021-04-04 15:40:54 +08:00
|
|
|
|
drawerRef.Config.Visible = false;
|
2020-06-30 13:40:51 +08:00
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
await Task.Delay(300);
|
|
|
|
|
if (_drawerRefs.Contains(drawerRef))
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
_drawerRefs.Remove(drawerRef);
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|