Skip to content

Commit ea42fa3

Browse files
committed
refactor: 增加 UI 显示逻辑
1 parent 2ce4b7a commit ea42fa3

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,12 @@ private async Task UpdateDisabledDaysCache(bool force)
539539
}
540540
}
541541

542-
private bool IsDisableDay(DateTime val)
542+
/// <summary>
543+
/// 判定当前日期是否为禁用日期
544+
/// </summary>
545+
/// <param name="val"></param>
546+
/// <returns></returns>
547+
public bool IsDisableDay(DateTime val)
543548
{
544549
bool ret = false;
545550
if (_monthDisabledDaysCache.TryGetValue($"{StartDate:yyyyMMdd}-{EndDate:yyyyMMdd}", out var disabledDays))

src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ShowLunar="ShowLunar" ShowSolarTerm="ShowSolarTerm" ShowFestivals="ShowFestivals" ShowHolidays="ShowHolidays"
1919
OnConfirm="OnConfirm" OnClear="OnClear" MinValue="MinValue" MaxValue="MaxValue"
2020
AutoClose="AutoClose" ViewMode="ViewMode" DayTemplate="DayTemplate!" DayDisabledTemplate="DayDisabledTemplate!"
21-
OnGetMonthDisabledDaysCallback="OnGetMonthDisabledDaysCallback!"
21+
OnGetMonthDisabledDaysCallback="OnGetMonthDisabledDaysCallback!" @ref="_datePickerBody"
2222
EnableGetMonthDisabledDaysCache="EnableGetMonthDisabledDaysCache">
2323
@ChildContent
2424
</DatePickerBody>

src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public string? Format
234234

235235
private DateTime SelectedValue { get; set; }
236236

237+
private DatePickerBody? _datePickerBody = default;
238+
237239
/// <summary>
238240
/// <inheritdoc/>
239241
/// </summary>
@@ -317,14 +319,27 @@ protected override string FormatValueAsString(TValue value)
317319
d = v2.DateTime;
318320
}
319321

320-
if (d.HasValue && MinValueToToday(d.Value))
321-
{
322-
d = DateTime.Today;
323-
}
324-
325-
if (d.HasValue && !MinValueToEmpty(d.Value))
322+
if (d.HasValue)
326323
{
327-
ret = d.Value.ToString(ViewMode == DatePickerViewMode.DateTime ? DateTimeFormat : DateFormat);
324+
if (MinValueToToday(d.Value))
325+
{
326+
d = DateTime.Today;
327+
}
328+
329+
if (_datePickerBody != null)
330+
{
331+
var isDisabled = _datePickerBody.IsDisableDay(d.Value);
332+
if (isDisabled)
333+
{
334+
d = DateTime.MinValue;
335+
}
336+
337+
var isEmpty = MinValueToEmpty(d.Value);
338+
if (!isEmpty)
339+
{
340+
ret = d.Value.ToString(ViewMode == DatePickerViewMode.DateTime ? DateTimeFormat : DateFormat);
341+
}
342+
}
328343
}
329344
return ret;
330345
}

0 commit comments

Comments
 (0)