2020-06-03 10:24:16 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-11-25 11:08:12 +08:00
|
|
|
|
using System.Globalization;
|
2020-05-29 00:33:49 +08:00
|
|
|
|
using AntDesign.Internal;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
2020-06-01 14:09:28 +08:00
|
|
|
|
public class DatePickerPanelBase<TValue> : PickerPanelBase
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
[CascadingParameter]
|
2020-06-03 10:24:16 +08:00
|
|
|
|
public IDatePicker DatePicker { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string PrefixCls { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Picker { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsRange { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsCalendar { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsShowHeader { get; set; } = true;
|
|
|
|
|
|
2021-07-31 18:53:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used only by DatePickerWithTimePanel
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsShowTime { get; set; } = false;
|
|
|
|
|
|
2020-11-25 11:08:12 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public DatePickerLocale Locale { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public CultureInfo CultureInfo { get; set; }
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public Action ClosePanel { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2021-01-10 13:19:07 +08:00
|
|
|
|
public Action<DateTime, int?> ChangePickerValue { get; set; } //nullable int as picker index is no longer needed here unless forced
|
2020-06-03 10:24:16 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Action<DateTime, int> ChangeValue { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Action<string, int> ChangePickerType { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<int, DateTime> GetIndexPickerValue { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<int, DateTime?> GetIndexValue { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, bool> DisabledDate { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// for Calendar.DateFullCellRender、DatePicker.DateRender
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, DateTime, RenderFragment> DateRender { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// for Calendar.MonthFullCellRender、DatePicker.MonthCellRender
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> MonthCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// for Calendar.DateCellRender
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> CalendarDateRender { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// for Calendar.MonthCellRender
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> CalendarMonthCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment RenderExtraFooter { get; set; }
|
|
|
|
|
|
2021-07-31 18:53:53 +08:00
|
|
|
|
protected Dictionary<string, object> GetAttributes()
|
2020-06-03 10:24:16 +08:00
|
|
|
|
{
|
|
|
|
|
return new Dictionary<string, object>()
|
|
|
|
|
{
|
|
|
|
|
{ "PrefixCls", PrefixCls },
|
|
|
|
|
{ "Picker", Picker },
|
2020-11-25 11:08:12 +08:00
|
|
|
|
{ "Locale", Locale },
|
|
|
|
|
{ "CultureInfo", CultureInfo },
|
2020-06-03 10:24:16 +08:00
|
|
|
|
{ "ClosePanel", ClosePanel },
|
|
|
|
|
{ "ChangePickerValue", ChangePickerValue },
|
|
|
|
|
{ "ChangeValue", ChangeValue },
|
|
|
|
|
{ "ChangePickerType", ChangePickerType },
|
|
|
|
|
{ "GetIndexPickerValue", GetIndexPickerValue },
|
|
|
|
|
{ "GetIndexValue", GetIndexValue },
|
|
|
|
|
{ "DisabledDate", DisabledDate },
|
|
|
|
|
{ "DateRender", DateRender },
|
|
|
|
|
{ "MonthCellRender", MonthCellRender },
|
|
|
|
|
{ "CalendarDateRender", CalendarDateRender },
|
|
|
|
|
{ "CalendarMonthCellRender", CalendarMonthCellRender },
|
|
|
|
|
{ "RenderExtraFooter", RenderExtraFooter },
|
|
|
|
|
{ "IsRange", IsRange },
|
|
|
|
|
{ "PickerIndex", PickerIndex },
|
|
|
|
|
{ "IsCalendar", IsCalendar },
|
|
|
|
|
{ "IsShowHeader", IsShowHeader },
|
2021-07-31 18:53:53 +08:00
|
|
|
|
{ "IsShowTime", IsShowTime },
|
2020-06-03 10:24:16 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
protected void OnSelectTime(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(date, PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectDate(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(year: date.Year, month: date.Month, day: date.Day), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectYear(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(year: date.Year), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectQuarter(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(month: date.Month), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectMonth(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(month: date.Month), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectDay(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(day: date.Day), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectHour(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(hour: date.Hour), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectMinute(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(minute: date.Minute), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectSecond(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
OnSelect?.Invoke(CombineNewShowDate(second: date.Second), PickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectShowYear(DateTime date)
|
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ChangePickerValue(CombineNewShowDate(year: date.Year), PickerIndex);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectShowMonth(DateTime date)
|
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ChangePickerValue(CombineNewShowDate(month: date.Month), PickerIndex);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnSelectShowDay(DateTime date)
|
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ChangePickerValue(CombineNewShowDate(day: date.Day), PickerIndex);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected DateTime CombineNewShowDate(
|
|
|
|
|
int? year = null,
|
|
|
|
|
int? month = null,
|
|
|
|
|
int? day = null,
|
|
|
|
|
int? hour = null,
|
|
|
|
|
int? minute = null,
|
|
|
|
|
int? second = null)
|
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
return DateHelper.CombineNewDate(
|
2021-03-23 11:08:07 +08:00
|
|
|
|
PickerValue,
|
2020-06-03 10:24:16 +08:00
|
|
|
|
year,
|
|
|
|
|
month,
|
|
|
|
|
day,
|
|
|
|
|
hour,
|
|
|
|
|
minute,
|
|
|
|
|
second
|
|
|
|
|
);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ChangePickerYearValue(int interval)
|
|
|
|
|
{
|
2021-07-31 18:53:53 +08:00
|
|
|
|
DateTime baseDate;
|
|
|
|
|
if (IsShowTime || PickerIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
baseDate = PickerValue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
baseDate = Picker switch
|
|
|
|
|
{
|
|
|
|
|
DatePickerType.Date => PickerValue.AddMonths(-1),
|
|
|
|
|
DatePickerType.Week => PickerValue.AddMonths(-1),
|
|
|
|
|
DatePickerType.Year => PickerValue.AddYears(-10),
|
|
|
|
|
_ => PickerValue.AddYears(-1)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
ChangePickerValue(DateHelper.AddYearsSafely(baseDate, interval), null);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ChangePickerMonthValue(int interval)
|
|
|
|
|
{
|
2021-07-31 18:53:53 +08:00
|
|
|
|
DateTime baseDate;
|
|
|
|
|
if (IsShowTime || PickerIndex == 0)
|
|
|
|
|
baseDate = PickerValue;
|
|
|
|
|
else
|
|
|
|
|
baseDate = PickerValue.AddMonths(-1);
|
|
|
|
|
ChangePickerValue(DateHelper.AddMonthsSafely(baseDate, interval), null);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
protected void Close()
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ClosePanel?.Invoke();
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
protected DateTime PickerValue { get => GetIndexPickerValue(PickerIndex); }
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
2021-05-07 15:31:13 +08:00
|
|
|
|
protected DateTime? Value { get => GetIndexValue(PickerIndex); }
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
public void PopUpPicker(string type)
|
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ChangePickerType(type, PickerIndex);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
2021-03-12 17:02:11 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
|
|
|
|
ClassMapper.Add($"{PrefixCls}-panel")
|
|
|
|
|
.If($"{PrefixCls}-panel-rtl", () => RTL);
|
|
|
|
|
}
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|