mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +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>
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public partial class ModalContainer
|
|
{
|
|
[Inject]
|
|
private ModalService ModalService { get; set; }
|
|
|
|
private readonly List<ModalRef> _modalRefs = new List<ModalRef>();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
ModalService.OnModalOpenEvent += ModalService_OnModalOpenEvent;
|
|
ModalService.OnModalCloseEvent += ModalService_OnModalCloseEvent;
|
|
ModalService.OnModalUpdateEvent += ModalService_OnModalUpdateEvent;
|
|
}
|
|
|
|
private async Task ModalService_OnModalOpenEvent(ModalRef modalRef)
|
|
{
|
|
if (!_modalRefs.Contains(modalRef))
|
|
{
|
|
_modalRefs.Add(modalRef);
|
|
}
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task ModalService_OnModalCloseEvent(ModalRef modalRef)
|
|
{
|
|
modalRef.Config.Visible = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
await Task.Delay(250);
|
|
if (modalRef.Config.DestroyOnClose && _modalRefs.Contains(modalRef))
|
|
{
|
|
_modalRefs.Remove(modalRef);
|
|
}
|
|
}
|
|
|
|
private async Task ModalService_OnModalUpdateEvent(ModalRef arg)
|
|
{
|
|
await InvokeStateHasChangedAsync();
|
|
}
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
ModalService.OnModalOpenEvent -= ModalService_OnModalOpenEvent;
|
|
ModalService.OnModalCloseEvent -= ModalService_OnModalCloseEvent;
|
|
ModalService.OnModalUpdateEvent -= ModalService_OnModalUpdateEvent;
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|