2020-05-15 14:31:12 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Timers;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-15 14:31:12 +08:00
|
|
|
|
{
|
|
|
|
|
public partial class Spin : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// small | default | large
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Size { get; set; } = "default";
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Tip { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Delay { get; set; } = 0;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-07 21:34:43 +08:00
|
|
|
|
public bool Spinning { get; set; } = true;
|
2020-05-15 14:31:12 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string WrapperClassName { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment Indicator { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
private ClassMapper WrapperClassMapper { get; set; } = new ClassMapper();
|
|
|
|
|
|
|
|
|
|
private const string PrefixCls = "ant-spin";
|
|
|
|
|
|
|
|
|
|
private bool _isLoading = true;
|
|
|
|
|
|
|
|
|
|
private bool Simple => ChildContent == null;
|
|
|
|
|
|
|
|
|
|
private string ContainerClass => _isLoading ? $"{PrefixCls}-blur" : "";
|
|
|
|
|
|
|
|
|
|
private Timer _delayTimer;
|
|
|
|
|
|
|
|
|
|
private void SetClass()
|
|
|
|
|
{
|
|
|
|
|
WrapperClassMapper
|
|
|
|
|
.If(WrapperClassName, () => !string.IsNullOrWhiteSpace(WrapperClassName))
|
|
|
|
|
.If($"{PrefixCls}-nested-loading", () => !Simple);
|
|
|
|
|
|
2021-03-12 17:02:11 +08:00
|
|
|
|
ClassMapper
|
|
|
|
|
.Add(PrefixCls)
|
2020-05-15 14:31:12 +08:00
|
|
|
|
.If($"{PrefixCls}-spinning", () => _isLoading)
|
|
|
|
|
.If($"{PrefixCls}-lg", () => Size == "large")
|
|
|
|
|
.If($"{PrefixCls}-sm", () => Size == "small")
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.If($"{PrefixCls}-show-text", () => string.IsNullOrWhiteSpace(Tip))
|
|
|
|
|
.If($"{PrefixCls}-rtl", () => RTL);
|
2020-05-15 14:31:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
SetClass();
|
|
|
|
|
|
|
|
|
|
_isLoading = Spinning;
|
|
|
|
|
|
|
|
|
|
if (Delay > 0)
|
|
|
|
|
{
|
|
|
|
|
_delayTimer = new Timer(Delay);
|
|
|
|
|
_delayTimer.Elapsed += DelayElapsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
|
|
|
|
|
if (_delayTimer != null)
|
|
|
|
|
{
|
|
|
|
|
if (_isLoading != Spinning)
|
|
|
|
|
{
|
|
|
|
|
_delayTimer.Stop();
|
|
|
|
|
_delayTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_delayTimer.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-05 16:07:49 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_isLoading != Spinning)
|
|
|
|
|
{
|
2020-06-07 21:34:43 +08:00
|
|
|
|
_isLoading = Spinning;
|
2020-06-05 16:07:49 +08:00
|
|
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-15 14:31:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DelayElapsed(object sender, ElapsedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
_isLoading = Spinning;
|
|
|
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
2021-09-09 12:56:11 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
_delayTimer?.Dispose();
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
2020-05-15 14:31:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|