mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
6bf817d1ea
* refactor: change the name of ModalRef to ConfirmRef in order to create a Modal dialog in service mode BREAKING CHANGE: all using of ModalRef must rename to ConfirmRef * refactor: chang the name of ModalTemplate to ConfirmTemplate in order to create a Modal dialog in service mode BREAKING CHANGE: all using of ModalTemplate must rename to ConfirmTemplate * feat(module: modal): support creating Modal dialog from ModalService Co-authored-by: James Yeung <shunjiey@hotmail.com>
53 lines
1.5 KiB
C#
53 lines
1.5 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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
ModalService.OnModalOpenEvent -= ModalService_OnModalOpenEvent;
|
|
ModalService.OnModalCloseEvent -= ModalService_OnModalCloseEvent;
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|