mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
ef22dd5a1b
* feat: add mentions component * fix: update with z-index * feat: new mention components (unfinished) * fix: show chinese letter for affix and tree * refactor: clean code * fix: the display position of the dropdown is consistent with the cursor * fix: mistakes Co-authored-by: ElderJames <shunjiey@hotmail.com> Co-authored-by: zxyao <zxyao145@gmail.com>
128 lines
3.0 KiB
C#
128 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public abstract class AntComponentBase : ComponentBase, IDisposable
|
|
{
|
|
[Parameter]
|
|
public ForwardRef RefBack { get; set; }
|
|
|
|
private readonly Queue<Func<Task>> _afterRenderCallQuene = new Queue<Func<Task>>();
|
|
|
|
protected void CallAfterRender(Func<Task> action)
|
|
{
|
|
_afterRenderCallQuene.Enqueue(action);
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
if (firstRender)
|
|
{
|
|
await OnFirstAfterRenderAsync();
|
|
}
|
|
|
|
if (_afterRenderCallQuene.Count > 0)
|
|
{
|
|
var actions = _afterRenderCallQuene.ToArray();
|
|
_afterRenderCallQuene.Clear();
|
|
|
|
foreach (var action in actions)
|
|
{
|
|
if (IsDisposed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await action();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected virtual Task OnFirstAfterRenderAsync()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected AntComponentBase()
|
|
{
|
|
}
|
|
|
|
protected void InvokeStateHasChanged()
|
|
{
|
|
InvokeAsync(() =>
|
|
{
|
|
if (!IsDisposed)
|
|
{
|
|
StateHasChanged();
|
|
}
|
|
});
|
|
}
|
|
|
|
protected async Task InvokeStateHasChangedAsync()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
if (!IsDisposed)
|
|
{
|
|
StateHasChanged();
|
|
}
|
|
});
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime Js { get; set; }
|
|
|
|
protected async Task<T> JsInvokeAsync<T>(string code, params object[] args)
|
|
{
|
|
try
|
|
{
|
|
return await Js.InvokeAsync<T>(code, args);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected async Task JsInvokeAsync(string code, params object[] args)
|
|
{
|
|
try
|
|
{
|
|
await Js.InvokeVoidAsync(code, args);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected bool IsDisposed { get; private set; }
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (IsDisposed) return;
|
|
|
|
IsDisposed = true;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
~AntComponentBase()
|
|
{
|
|
// Finalizer calls Dispose(false)
|
|
Dispose(false);
|
|
}
|
|
}
|
|
}
|