2020-05-29 00:33:49 +08:00
|
|
|
|
@namespace AntDesign.Internal
|
2020-06-01 14:09:28 +08:00
|
|
|
|
@typeparam TValue
|
|
|
|
|
@inherits DatePickerPanelBase<TValue>
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
@{
|
2020-11-25 11:08:12 +08:00
|
|
|
|
var calendar = CultureInfo.Calendar;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
2021-06-27 09:53:01 +08:00
|
|
|
|
DateTime monthFirstDayDate = new DateTime(PickerValue.Year, PickerValue.Month, 1, 0, 0, 0);
|
2020-06-03 10:24:16 +08:00
|
|
|
|
int monthFirstDayOfWeek = (int)calendar.GetDayOfWeek(monthFirstDayDate);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
// sunday should be 7
|
|
|
|
|
if (monthFirstDayOfWeek == 0)
|
|
|
|
|
{
|
2020-11-25 11:08:12 +08:00
|
|
|
|
monthFirstDayOfWeek = DayOfWeekHelper.GetDiffForDayOfWeek(Locale.FirstDayOfWeek);
|
2020-06-03 10:24:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 11:08:12 +08:00
|
|
|
|
int diffDay = (int) Locale.FirstDayOfWeek - monthFirstDayOfWeek;
|
2021-06-27 09:53:01 +08:00
|
|
|
|
DateTime startDate;
|
|
|
|
|
int skipDays = 0;
|
|
|
|
|
if (monthFirstDayDate == DateTime.MinValue)
|
|
|
|
|
{
|
|
|
|
|
startDate = monthFirstDayDate;
|
|
|
|
|
skipDays = monthFirstDayOfWeek - (int)Locale.FirstDayOfWeek;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
startDate = monthFirstDayDate.AddDays(diffDay);
|
|
|
|
|
}
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 17:20:10 +08:00
|
|
|
|
<div class='@($"{PrefixCls}-panel")' @ref="Ref">
|
2020-11-25 11:08:12 +08:00
|
|
|
|
<DatePickerTemplate TValue="TValue"
|
2021-07-31 18:53:53 +08:00
|
|
|
|
@attributes="GetAttributes()"
|
2020-04-28 15:56:56 +08:00
|
|
|
|
MaxRow="6"
|
|
|
|
|
MaxCol="7"
|
|
|
|
|
ViewStartDate="startDate"
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ShowFooter="@ShowToday"
|
2020-04-28 15:56:56 +08:00
|
|
|
|
GetRowClass="GetRowClass"
|
|
|
|
|
IsInView="date => DateHelper.IsSameMonth(date, PickerValue)"
|
|
|
|
|
IsToday="date => DateHelper.IsSameDay(date, DatePicker.CurrentDate)"
|
|
|
|
|
IsSelected="date => !IsWeek && DateHelper.IsSameDay(date, Value)"
|
2020-11-25 11:08:12 +08:00
|
|
|
|
GetColTitle='date => date.ToString(Locale.Lang.DateFormat, CultureInfo)'
|
2020-04-28 15:56:56 +08:00
|
|
|
|
OnRowSelect="OnRowSelect"
|
|
|
|
|
OnValueSelect="OnValueSelect"
|
2021-06-27 09:53:01 +08:00
|
|
|
|
GetNextColValue="date => DateHelper.AddDaysSafely(date, 1)"
|
|
|
|
|
SkipDays="skipDays">
|
2020-04-28 15:56:56 +08:00
|
|
|
|
<RenderPickerHeader>
|
2020-06-03 10:24:16 +08:00
|
|
|
|
<DatePickerHeader TValue="TValue"
|
2021-07-31 18:53:53 +08:00
|
|
|
|
@attributes="GetAttributes()"
|
2020-06-03 10:24:16 +08:00
|
|
|
|
ShowSuperPreChange="@(!(IsRange && PickerIndex == 1))"
|
|
|
|
|
ShowPreChange="@(!(IsRange && PickerIndex == 1))"
|
|
|
|
|
ShowNextChange="@(!(IsRange && PickerIndex == 0))"
|
|
|
|
|
ShowSuperNextChange="@(!(IsRange && PickerIndex == 0))"/>
|
2020-04-28 15:56:56 +08:00
|
|
|
|
</RenderPickerHeader>
|
|
|
|
|
<RenderTableHeader>
|
|
|
|
|
<tr>
|
|
|
|
|
@if (IsWeek)
|
|
|
|
|
{
|
|
|
|
|
<th></th>
|
|
|
|
|
}
|
2020-11-25 11:08:12 +08:00
|
|
|
|
@foreach(string weekDay in Locale.Lang.ShortWeekDays)
|
2021-02-05 14:32:25 +08:00
|
|
|
|
{
|
2020-06-16 12:31:46 +08:00
|
|
|
|
<th>@(weekDay)</th>
|
|
|
|
|
}
|
2020-04-28 15:56:56 +08:00
|
|
|
|
</tr>
|
|
|
|
|
</RenderTableHeader>
|
2021-05-07 15:31:13 +08:00
|
|
|
|
<RenderFirstCol>
|
2020-04-28 15:56:56 +08:00
|
|
|
|
@if (IsWeek)
|
2021-05-07 15:31:13 +08:00
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
<td class="@(PrefixCls)-cell @(PrefixCls)-cell-weak">
|
2021-05-07 15:31:13 +08:00
|
|
|
|
@DateHelper.GetWeekOfYear(context, Locale.FirstDayOfWeek)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
</td>
|
|
|
|
|
}
|
2021-05-07 15:31:13 +08:00
|
|
|
|
</RenderFirstCol>
|
2020-04-28 15:56:56 +08:00
|
|
|
|
<RenderColValue Context="currentColDate">
|
|
|
|
|
@currentColDate.Day
|
|
|
|
|
</RenderColValue>
|
2020-05-18 14:46:42 +08:00
|
|
|
|
</DatePickerTemplate>
|
2020-04-28 15:56:56 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
2020-10-19 12:04:24 +08:00
|
|
|
|
@if (RenderExtraFooter != null && !IsRange)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
<div class="@(PrefixCls)-footer">
|
|
|
|
|
<div class="@(PrefixCls)-footer-extra">
|
|
|
|
|
@RenderExtraFooter
|
2020-04-28 15:56:56 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
@if (ShowToday && !IsRange && Picker != DatePickerType.Time)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
2020-06-03 10:24:16 +08:00
|
|
|
|
<div class="@(PrefixCls)-footer">
|
2020-11-25 11:08:12 +08:00
|
|
|
|
<a class="@(PrefixCls)-today-btn"
|
2020-06-03 10:24:16 +08:00
|
|
|
|
@onclick="e => { OnSelectDate(DateTime.Now); Close(); }">
|
2020-11-25 11:08:12 +08:00
|
|
|
|
@Locale.Lang.Today
|
2020-04-28 15:56:56 +08:00
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsWeek { get; set; } = false;
|
|
|
|
|
|
2020-06-03 10:24:16 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool ShowToday { get; set; } = false;
|
|
|
|
|
|
2020-04-28 15:56:56 +08:00
|
|
|
|
private string GetRowClass(DateTime viewDate)
|
|
|
|
|
{
|
2021-05-07 15:31:13 +08:00
|
|
|
|
string selectedRowClass = IsWeek && DateHelper.IsSameWeak(viewDate, Value, Locale.FirstDayOfWeek) ? $"{PrefixCls}-week-panel-row-selected" : "";
|
2020-06-03 10:24:16 +08:00
|
|
|
|
string rowClass = IsWeek ? $"{PrefixCls}-week-panel-row" : "";
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
return $"{rowClass} {selectedRowClass}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRowSelect(DateTime viewDate)
|
|
|
|
|
{
|
|
|
|
|
if (IsWeek)
|
|
|
|
|
{
|
|
|
|
|
OnSelectDate(viewDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnValueSelect(DateTime viewDate)
|
|
|
|
|
{
|
|
|
|
|
if (!IsWeek)
|
|
|
|
|
{
|
|
|
|
|
OnSelectDate(viewDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|