diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 7b193de50b5..7bc313d131a 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.3.1-beta27 + 9.3.1-beta28 diff --git a/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs b/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs index 6c7291033df..221b51148db 100644 --- a/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs +++ b/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs @@ -20,7 +20,7 @@ private DateTime StartDate get { var d = GetSafeDayDateTime(CurrentDate, 1 - CurrentDate.Day); - d = GetSafeDayDateTime(d, 0 - (int)d.DayOfWeek); + d = GetSafeDayDateTime(d, (int)FirstDayOfWeek - (int)d.DayOfWeek); return d; } } @@ -388,6 +388,12 @@ public bool AllowNull [Parameter] public bool EnableDisabledDaysCache { get; set; } = true; + /// + /// 获得/设置 星期第一天 默认 + /// + [Parameter] + public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Sunday; + [Inject] [NotNull] private ICalendarFestivals? CalendarFestivals { get; set; } @@ -494,7 +500,7 @@ protected override void OnParametersSet() YearPeriodText ??= Localizer[nameof(YearPeriodText)]; MonthLists = [.. Localizer[nameof(MonthLists)].Value.Split(',')]; Months = [.. Localizer[nameof(Months)].Value.Split(',')]; - WeekLists = [.. Localizer[nameof(WeekLists)].Value.Split(',')]; + WeekLists = GetWeekList(); Today ??= Localizer[nameof(Today)]; Yesterday ??= Localizer[nameof(Yesterday)]; @@ -513,7 +519,9 @@ protected override async Task OnParametersSetAsync() { await base.OnParametersSetAsync(); + _render = false; await UpdateDisabledDaysCache(true); + _render = true; } private bool _render = true; @@ -523,6 +531,15 @@ protected override async Task OnParametersSetAsync() /// protected override bool ShouldRender() => _render; + private List GetWeekList() + { + var list = Localizer[nameof(WeekLists)].Value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); + + // 调整顺序 + var firstDayIndex = (int)FirstDayOfWeek; + return list.Skip(firstDayIndex).Concat(list.Take(firstDayIndex)).ToList(); + } + private async Task UpdateDisabledDaysCache(bool force) { if (OnGetDisabledDaysCallback != null) diff --git a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor index cc5ed32815c..718b97f3f37 100644 --- a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor +++ b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor @@ -13,7 +13,7 @@ { } - + /// 获得/设置 星期第一天 默认 + /// + [Parameter] + public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Sunday; + /// /// 获得/设置 组件图标 默认 fa-regular fa-calendar-days /// diff --git a/test/UnitTest/Components/DateTimePickerTest.cs b/test/UnitTest/Components/DateTimePickerTest.cs index 0ddc9069033..3ce55ebfdca 100644 --- a/test/UnitTest/Components/DateTimePickerTest.cs +++ b/test/UnitTest/Components/DateTimePickerTest.cs @@ -959,6 +959,20 @@ public void SidebarTemplate_Ok() cut.Contains("test-sidebar-template"); } + [Fact] + public void FirstDayOfWeek_Ok() + { + var cut = Context.RenderComponent>(pb => + { + pb.Add(a => a.FirstDayOfWeek, DayOfWeek.Monday); + pb.Add(a => a.Value, new DateTime(2025, 02, 20)); + }); + + var labels = cut.FindAll(".date-table tbody > tr:first-child > th"); + Assert.Equal("一", labels[0].TextContent); + Assert.Equal("日", labels[6].TextContent); + } + [Fact] public void GetSafeYearDateTime_Ok() {