2020-06-03 10:24:16 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-16 12:31:46 +08:00
|
|
|
|
using System.Globalization;
|
2020-06-03 10:24:16 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public partial class Calendar : AntDomComponentBase, IDatePicker
|
|
|
|
|
{
|
|
|
|
|
DateTime IDatePicker.CurrentDate { get; set; } = DateTime.Now;
|
2020-07-05 00:06:34 +08:00
|
|
|
|
DateTime? IDatePicker.HoverDateTime { get; set; }
|
2020-06-03 10:24:16 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public DateTime Value { get; set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
private DateTime _defaultValue;
|
2020-09-07 22:46:50 +08:00
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public DateTime DefaultValue
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _defaultValue;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_defaultValue = value;
|
|
|
|
|
Value = _defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public DateTime[] ValidRange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Mode { get; set; } = DatePickerType.Month;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool FullScreen { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<DateTime> OnSelect { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<DateTime> OnChange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<CalendarHeaderRenderArgs, RenderFragment> HeaderRender { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> DateCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> DateFullCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> MonthCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> MonthFullCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Action<DateTime, string> OnPanelChange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, bool> DisabledDate { get; set; } = null;
|
|
|
|
|
|
2020-11-25 11:08:12 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public DatePickerLocale Locale { get; set; } = LocaleProvider.CurrentLocale.DatePicker;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public CultureInfo CultureInfo { get; set; } = LocaleProvider.CurrentLocale.CurrentCulture;
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
protected string _picker;
|
2020-06-29 23:19:25 +08:00
|
|
|
|
protected readonly DateTime[] PickerValues = new DateTime[] { DateTime.Now, DateTime.Now };
|
2020-06-03 10:24:16 +08:00
|
|
|
|
protected Stack<string> _prePickerStack = new Stack<string>();
|
|
|
|
|
|
|
|
|
|
public readonly string PrefixCls = "ant-picker-calendar";
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
|
|
|
|
_picker = Mode switch
|
|
|
|
|
{
|
|
|
|
|
DatePickerType.Month => DatePickerType.Date,
|
|
|
|
|
DatePickerType.Year => DatePickerType.Month,
|
|
|
|
|
_ => DatePickerType.Date,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (ValidRange != null)
|
|
|
|
|
{
|
|
|
|
|
if (Value < ValidRange[0])
|
|
|
|
|
{
|
|
|
|
|
Value = ValidRange[0];
|
|
|
|
|
}
|
|
|
|
|
else if (Value > ValidRange[1])
|
|
|
|
|
{
|
|
|
|
|
Value = ValidRange[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
this.SetClass();
|
|
|
|
|
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void SetClass()
|
|
|
|
|
{
|
|
|
|
|
this.ClassMapper.Clear()
|
|
|
|
|
.Add(PrefixCls)
|
|
|
|
|
.If($"{PrefixCls}-full", () => FullScreen)
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.If($"{PrefixCls}-rtl", () => RTL)
|
2020-06-03 10:24:16 +08:00
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async Task OnSelectValue(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
Value = date;
|
|
|
|
|
|
|
|
|
|
await OnSelect.InvokeAsync(date);
|
|
|
|
|
await OnChange.InvokeAsync(date);
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ChangeValue(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
await OnSelectValue(date);
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangePickerType(string type, int index)
|
|
|
|
|
{
|
|
|
|
|
Mode = type;
|
|
|
|
|
|
|
|
|
|
string mode = type switch
|
|
|
|
|
{
|
|
|
|
|
DatePickerType.Year => DatePickerType.Month,
|
|
|
|
|
DatePickerType.Month => DatePickerType.Date,
|
|
|
|
|
_ => DatePickerType.Date,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_prePickerStack.Push(_picker);
|
|
|
|
|
_picker = mode;
|
|
|
|
|
|
2020-06-29 23:19:25 +08:00
|
|
|
|
OnPanelChange?.Invoke(PickerValues[index], _picker);
|
2020-06-03 10:24:16 +08:00
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangePickerType(string type)
|
|
|
|
|
{
|
|
|
|
|
ChangePickerType(type, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-05 00:06:34 +08:00
|
|
|
|
public int GetOnFocusPickerIndex()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IDatePicker.InvokeStateHasChanged()
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 12:43:48 +08:00
|
|
|
|
string IDatePicker.GetFormatValue(DateTime value, int index)
|
|
|
|
|
{
|
2020-11-23 23:00:24 +08:00
|
|
|
|
return value.ToString(CultureInfo);
|
2020-08-14 12:43:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IDatePicker.ChangePlaceholder(string placeholder, int index)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
public string Picker { get { return _picker; } }
|
|
|
|
|
}
|
|
|
|
|
}
|