2020-10-14 15:09:11 +08:00
|
|
|
|
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;
|
2021-04-04 15:40:54 +08:00
|
|
|
|
ModalService.OnModalUpdateEvent += ModalService_OnModalUpdateEvent;
|
2020-10-14 15:09:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ModalService_OnModalOpenEvent(ModalRef modalRef)
|
|
|
|
|
{
|
|
|
|
|
if (!_modalRefs.Contains(modalRef))
|
|
|
|
|
{
|
|
|
|
|
_modalRefs.Add(modalRef);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ModalService_OnModalCloseEvent(ModalRef modalRef)
|
|
|
|
|
{
|
2021-07-11 20:48:16 +08:00
|
|
|
|
if (modalRef.Config.Visible)
|
2020-10-14 15:09:11 +08:00
|
|
|
|
{
|
2021-07-11 20:48:16 +08:00
|
|
|
|
modalRef.Config.Visible = false;
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
await Task.Delay(250);
|
|
|
|
|
if (modalRef.Config.DestroyOnClose && _modalRefs.Contains(modalRef))
|
|
|
|
|
{
|
|
|
|
|
_modalRefs.Remove(modalRef);
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
2020-10-14 15:09:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 15:40:54 +08:00
|
|
|
|
private async Task ModalService_OnModalUpdateEvent(ModalRef arg)
|
|
|
|
|
{
|
|
|
|
|
await InvokeStateHasChangedAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 15:09:11 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
ModalService.OnModalOpenEvent -= ModalService_OnModalOpenEvent;
|
|
|
|
|
ModalService.OnModalCloseEvent -= ModalService_OnModalCloseEvent;
|
2021-04-04 15:40:54 +08:00
|
|
|
|
ModalService.OnModalUpdateEvent -= ModalService_OnModalUpdateEvent;
|
2020-10-14 15:09:11 +08:00
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|