mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-11-30 02:58:37 +08:00
!2738 fix(#I55J40): datatime view mode incorrect when click datetime cell to switch the view mode
* chore: bump version 6.5.18 * test: 增加代码覆盖率 * test: 增加天溢出单元测试 * test: 增加年溢出单元测试 * refactor: 更新 IsDayOverflow 逻辑 * refactor: 更改为属性 * doc: 格式化文档 * refactor: 重新排序枚举类型增加组件视图默认值 * fix: 修复 Month 视图时点击后进入 DateTime 视图 * doc: 更改文件名与枚举类型一致 * refactor: 排序 DatePickerViewMode 枚举类型
This commit is contained in:
parent
3ebfeb7bfc
commit
fa3ca5982c
@ -101,7 +101,7 @@
|
|||||||
<DateTimePicker TValue="DateTime" IsDisabled="IsDisabled" />
|
<DateTimePicker TValue="DateTime" IsDisabled="IsDisabled" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-sm-6">
|
<div class="col-12 col-sm-6">
|
||||||
<Switch @bind-Value="@IsDisabled" />
|
<Switch @bind-Value="@IsDisabled" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DemoBlock>
|
</DemoBlock>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>6.5.17</Version>
|
<Version>6.5.18</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||||
|
@ -69,7 +69,7 @@ public sealed partial class DatePickerBody
|
|||||||
.AddClass("disabled", IsDisabled(day) || overflow)
|
.AddClass("disabled", IsDisabled(day) || overflow)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
private bool IsDisabled(DateTime day) => (MinValue != null && day < MinValue) || (MaxValue != null && day > MaxValue);
|
private bool IsDisabled(DateTime day) => (MinValue.HasValue && day < MinValue.Value) || (MaxValue.HasValue && day > MaxValue.Value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得 年月日时分秒视图样式
|
/// 获得 年月日时分秒视图样式
|
||||||
@ -333,6 +333,31 @@ public sealed partial class DatePickerBody
|
|||||||
[NotNull]
|
[NotNull]
|
||||||
private string? Weekago { get; set; }
|
private string? Weekago { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<DatePickerViewMode, List<DatePickerViewMode>> AllowSwitchModes { get; } = new Dictionary<DatePickerViewMode, List<DatePickerViewMode>>
|
||||||
|
{
|
||||||
|
[DatePickerViewMode.DateTime] = new List<DatePickerViewMode>()
|
||||||
|
{
|
||||||
|
DatePickerViewMode.DateTime,
|
||||||
|
DatePickerViewMode.Month,
|
||||||
|
DatePickerViewMode.Year
|
||||||
|
},
|
||||||
|
[DatePickerViewMode.Date] = new List<DatePickerViewMode>()
|
||||||
|
{
|
||||||
|
DatePickerViewMode.Date,
|
||||||
|
DatePickerViewMode.Month,
|
||||||
|
DatePickerViewMode.Year
|
||||||
|
},
|
||||||
|
[DatePickerViewMode.Month] = new List<DatePickerViewMode>()
|
||||||
|
{
|
||||||
|
DatePickerViewMode.Month,
|
||||||
|
DatePickerViewMode.Year
|
||||||
|
},
|
||||||
|
[DatePickerViewMode.Year] = new List<DatePickerViewMode>()
|
||||||
|
{
|
||||||
|
DatePickerViewMode.Year
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// OnInitialized 方法
|
/// OnInitialized 方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -452,7 +477,10 @@ public sealed partial class DatePickerBody
|
|||||||
private Task SwitchView(DatePickerViewMode view)
|
private Task SwitchView(DatePickerViewMode view)
|
||||||
{
|
{
|
||||||
ShowTimePicker = false;
|
ShowTimePicker = false;
|
||||||
CurrentViewMode = view;
|
if (AllowSwitchModes[ViewMode].Contains(view))
|
||||||
|
{
|
||||||
|
CurrentViewMode = view;
|
||||||
|
}
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ public sealed partial class DateTimePicker<TValue>
|
|||||||
/// 获得/设置 组件显示模式 默认为显示年月日模式
|
/// 获得/设置 组件显示模式 默认为显示年月日模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public DatePickerViewMode ViewMode { get; set; }
|
public DatePickerViewMode ViewMode { get; set; } = DatePickerViewMode.Date;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得/设置 是否显示快捷侧边栏 默认不显示
|
/// 获得/设置 是否显示快捷侧边栏 默认不显示
|
||||||
|
@ -9,23 +9,23 @@ namespace BootstrapBlazor.Components;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DatePickerViewMode
|
public enum DatePickerViewMode
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 年月日模式
|
|
||||||
/// </summary>
|
|
||||||
Date,
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 年月日时分秒模式
|
/// 年月日时分秒模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DateTime,
|
DateTime,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 年视图
|
/// 年月日模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Year,
|
Date,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 月视图
|
/// 月视图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Month
|
Month,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 年视图
|
||||||
|
/// </summary>
|
||||||
|
Year
|
||||||
}
|
}
|
@ -96,19 +96,7 @@ internal static class DateTimeExtensions
|
|||||||
/// <param name="dt"></param>
|
/// <param name="dt"></param>
|
||||||
/// <param name="day"></param>
|
/// <param name="day"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool IsDayOverflow(this DateTime dt, int day)
|
public static bool IsDayOverflow(this DateTime dt, int day) => DateTime.MaxValue.AddDays(0 - day) < dt;
|
||||||
{
|
|
||||||
var ret = false;
|
|
||||||
if (day < 0)
|
|
||||||
{
|
|
||||||
ret = DateTime.MinValue.AddDays(0 - day) > dt;
|
|
||||||
}
|
|
||||||
else if (day > 0)
|
|
||||||
{
|
|
||||||
ret = DateTime.MaxValue.AddDays(0 - day) < dt;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -191,6 +191,26 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsYearOverflow_Ok()
|
||||||
|
{
|
||||||
|
var cut = Context.RenderComponent<DatePickerBody>(builder =>
|
||||||
|
{
|
||||||
|
builder.Add(a => a.Value, DateTime.MinValue.AddDays(1));
|
||||||
|
builder.Add(a => a.ViewMode, DatePickerViewMode.Year);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsDayOverflow()
|
||||||
|
{
|
||||||
|
var cut = Context.RenderComponent<DatePickerBody>(builder =>
|
||||||
|
{
|
||||||
|
builder.Add(a => a.Value, DateTime.MaxValue.AddDays(-1));
|
||||||
|
builder.Add(a => a.ViewMode, DatePickerViewMode.Date);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ShowSidebar_Ok()
|
public void ShowSidebar_Ok()
|
||||||
{
|
{
|
||||||
@ -282,7 +302,12 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
|||||||
{
|
{
|
||||||
builder.Add(a => a.Value, DateTime.Now);
|
builder.Add(a => a.Value, DateTime.Now);
|
||||||
builder.Add(a => a.MinValue, DateTime.Today.AddDays(-1));
|
builder.Add(a => a.MinValue, DateTime.Today.AddDays(-1));
|
||||||
builder.Add(a => a.MaxValue, DateTime.Today.AddDays(7));
|
});
|
||||||
|
|
||||||
|
cut.SetParametersAndRender(pb =>
|
||||||
|
{
|
||||||
|
pb.Add(a => a.MinValue, null);
|
||||||
|
pb.Add(a => a.MaxValue, DateTime.Today.AddDays(7));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user