From a6cfa9a2f5f0f86b108f3ccc971be8fb369853aa Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 21 Feb 2025 13:40:57 +0800 Subject: [PATCH 1/3] chore: bump version 9.3.1-beta28 Co-Authored-By: cervinkamichal0 <49551977+cervinkamichal0@users.noreply.github.com> --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 7185b9c967b..7bc313d131a 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.3.1-beta26 + 9.3.1-beta28 From 08fceef78ed32222393da8885357e29c91be9cfd Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 21 Feb 2025 14:12:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20FirstDayOfWeek?= =?UTF-8?q?=20=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DateTimePicker/DatePickerBody.razor.cs | 21 +++++++++++++++++-- .../DateTimePicker/DateTimePicker.razor | 2 +- .../DateTimePicker/DateTimePicker.razor.cs | 6 ++++++ 3 files changed, 26 insertions(+), 3 deletions(-) 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 /// From 2e21c244b36adb3cd675a0cca15e34ec5681ba2a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 21 Feb 2025 14:16:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/DateTimePickerTest.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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() {