Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DateTimePicker): support customize disabled date #4304

Merged
merged 70 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
352ff17
feat(DateTimePicker): Support custom disable dates
izanhzh Sep 14, 2024
2a0fc34
调整单元测试
izanhzh Sep 14, 2024
679cee5
撤销格式化调整
izanhzh Sep 14, 2024
7311b22
撤销格式化调整
izanhzh Sep 14, 2024
09ebedf
Merge branch 'main' into feat-date-time-picker-support-custom-disable…
izanhzh Sep 14, 2024
8811423
调整单元测试
izanhzh Sep 14, 2024
a62e712
调整ViewMode的赋值逻辑
izanhzh Sep 18, 2024
2740443
Merge branch 'main' into feat-date-time-picker-support-custom-disable…
izanhzh Sep 18, 2024
d9108b9
调整单元测试
izanhzh Sep 18, 2024
90bbda9
调整SelectedValue赋值
izanhzh Sep 18, 2024
a1516b4
Merge branch 'main' into feat-date-time-picker-support-custom-disable…
izanhzh Sep 24, 2024
84aee0e
提高覆盖率
izanhzh Sep 24, 2024
9c3799b
调整MinValueToToday逻辑
izanhzh Sep 24, 2024
562e167
撤销MinValueToToday时对MinValue/MaxValue的校验
izanhzh Sep 24, 2024
e5279d7
Merge branch 'main' into feat-date-time-picker-support-custom-disable…
ArgoZhang Sep 27, 2024
5761d95
refactor: 重命名参数名称
ArgoZhang Sep 27, 2024
777cbd2
调整支持不可为空时间
izanhzh Sep 28, 2024
5e8df2c
补充单元测试
izanhzh Sep 28, 2024
a9ee2b2
Merge branch 'main' into feat-date-time-picker-support-custom-disable…
ArgoZhang Sep 28, 2024
668665a
test: 更新单元测试
ArgoZhang Sep 28, 2024
d720ebb
doc: 移除不使用的命名空间
ArgoZhang Sep 28, 2024
3df5d06
revert: 撤销更改
ArgoZhang Sep 28, 2024
66fbea4
refactor: 更新代码提高代码覆盖率
ArgoZhang Sep 28, 2024
d2c1c1f
refactor: 精简代码提高可读性
ArgoZhang Sep 28, 2024
e71feff
doc: 更新功能示例
ArgoZhang Sep 28, 2024
c6ce0a7
refactor: 更改禁用日期回调方法名称
ArgoZhang Sep 28, 2024
35d8eff
test: 更新单元测试
ArgoZhang Sep 28, 2024
f12707a
refactor: 重新设计禁用日期获得逻辑
ArgoZhang Sep 28, 2024
b5a0bb7
doc: 更新示例
ArgoZhang Sep 28, 2024
98e78a9
test: 更新单元测试
ArgoZhang Sep 28, 2024
84c0012
refactor: 重构代码
ArgoZhang Sep 28, 2024
e7d370c
refactor: 重构代码
ArgoZhang Sep 28, 2024
98dbf89
refactor: 撤销代码更改
ArgoZhang Sep 28, 2024
8059c23
test: 更新单元测试
ArgoZhang Sep 28, 2024
96cafc9
refactor: 重构清除缓存逻辑
ArgoZhang Sep 28, 2024
7abdb98
doc: 更新示例
ArgoZhang Sep 28, 2024
4ec63d8
refactor: 更新缓存清除逻辑
ArgoZhang Sep 28, 2024
ad706da
test: 更新单元测试
ArgoZhang Sep 28, 2024
a9ec98c
refactor: 代码重构
ArgoZhang Sep 28, 2024
6efa64d
doc: 更新注释文档
ArgoZhang Sep 28, 2024
907cb74
doc: 更新示例
ArgoZhang Sep 28, 2024
cd6e51a
refactor: 代码重构
ArgoZhang Sep 28, 2024
27e8b44
perf: 提高性能
ArgoZhang Sep 28, 2024
082b8a5
refactor: 重构代码
ArgoZhang Sep 28, 2024
d679c9e
feat: 视图切换时更新禁用日期缓存
ArgoZhang Sep 28, 2024
7fef08b
refactor: 格式化代码
ArgoZhang Sep 28, 2024
2ce4b7a
wip: 临时提交
ArgoZhang Sep 28, 2024
ea42fa3
refactor: 增加 UI 显示逻辑
ArgoZhang Sep 28, 2024
4379d90
revert: 撤销 UI 更改
ArgoZhang Sep 28, 2024
853f04b
refactor: 重命名回调方法
ArgoZhang Sep 29, 2024
65cba62
refactor: 优化代码
ArgoZhang Sep 29, 2024
e6ed623
refactor: 更新示例
ArgoZhang Sep 29, 2024
efc0a52
feat: 增加缓存清除实例方法
ArgoZhang Sep 29, 2024
324544a
doc: 增加动态切换回调方法示例
ArgoZhang Sep 29, 2024
22bbcb3
refactor: 重构 FormatValueAsString 提高可读性
ArgoZhang Sep 29, 2024
29a2042
doc: 更新文档说明
ArgoZhang Sep 29, 2024
06ce4d7
doc: 更新注意事项
ArgoZhang Sep 29, 2024
1c75cc1
test: 增加清除方法单元测试
ArgoZhang Sep 29, 2024
91fa9b2
doc: 更新介绍文字
ArgoZhang Sep 29, 2024
4de9e89
doc: 更正单词拼写错误
ArgoZhang Sep 29, 2024
7d8f48d
refactor: 调整示例
ArgoZhang Sep 29, 2024
742a6a1
doc: 更新文档
ArgoZhang Sep 29, 2024
371d8dc
doc: 更新示例
ArgoZhang Sep 29, 2024
d631dc4
refactor: 更新文档
ArgoZhang Sep 29, 2024
d34987a
refactor: 防止多线程报错
ArgoZhang Sep 29, 2024
2894626
feat: 增加 DisplayDisabledDayAsEmpty 参数
ArgoZhang Sep 29, 2024
2d96c36
doc: 更新示例
ArgoZhang Sep 29, 2024
3548070
refactor: 更新 FormatValueAsString 逻辑
ArgoZhang Sep 29, 2024
09eab5a
Merge branch 'main' into feat-date-time-picker-support-custom-disable…
ArgoZhang Sep 29, 2024
91da121
doc: 更新 DisplayDisabledDayAsEmpty 参数说明
ArgoZhang Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<section ignore>
<Tips class="mt-3">
<p>@((MarkupString)Localizer["FeatureIntro"].Value)</p>
<ul class="ul-demo mt-3">
<li>@((MarkupString)Localizer["FeatureShowLunarIntro"].Value)</li>
<li>@((MarkupString)Localizer["FeatureShowSolarTermIntro"].Value)</li>
<li>@((MarkupString)Localizer["FeatureShowFestivalsIntro"].Value)</li>
<li>@((MarkupString)Localizer["FeatureShowHolidaysIntro"].Value)</li>
</ul>
<div>@((MarkupString)Localizer["FeatureFestivalIntro"].Value)</div>
</Tips>
</section>
Expand All @@ -51,7 +57,7 @@
<DateTimePicker @bind-Value="@ValidateFormValue" />
</div>
<div class="col-12 col-sm-auto align-self-end">
<Button ButtonType="ButtonType.Submit" Text="@Localizer["SubmitText"]" Icon="fa-solid fa-floppy-disk" />
<Button ButtonType="ButtonType.Submit" Text="@Localizer["SubmitText"]" Icon="fa-solid fa-floppy-disk"></Button>
</div>
</div>
</ValidateForm>
Expand Down Expand Up @@ -173,10 +179,6 @@
</div>
</DemoBlock>

<DemoBlock Title="@Localizer["ShowLunarTitle"]" Introduction="@Localizer["ShowLunarIntro"]" Name="ShowLunar">
<DateTimePicker TValue="DateTimeOffset" ShowLunar="true" ShowSolarTerm="true" ShowFestivals="true" ShowHolidays="true"></DateTimePicker>
</DemoBlock>

<DemoBlock Title="@Localizer["DayTemplateTitle"]" Introduction="@Localizer["DayTemplateIntro"]" Name="DayTemplate">
<DateTimePicker TValue="DateTimeOffset?" CustomClass="custom-picker">
<DayTemplate>
Expand All @@ -188,6 +190,38 @@
</DateTimePicker>
</DemoBlock>

<DemoBlock Title="@Localizer["DisableDayCallbackTitle"]" Introduction="@Localizer["DisableDayCallbackIntro"]" Name="OnDisabledDayCallback">
<section ignore>
<Tips>
@((MarkupString)Localizer["DisableDayCallbackTip"].Value)
</Tips>
<GroupBox Title="@Localizer["DisableOptions"]">
<div class="row g-3 form-inline text-end">
<div class="col-12 col-sm-6 col-md-auto">
<Switch DisplayText="@Localizer["DisableWeekend"]" ShowLabel="true" @bind-Value="_disableWeekend" OnValueChanged="OnDisabledDaysChanged" />
</div>
<div class="col-12 col-sm-6 col-md-auto">
<Switch DisplayText="@Localizer["DisableToday"]" ShowLabel="true" @bind-Value="_disableToday" OnValueChanged="OnDisabledDaysChanged" />
</div>
</div>
</GroupBox>
</section>
<div class="row form-inline g-3">
<div class="col-12 col-sm-6">
<DateTimePicker ViewMode="DatePickerViewMode.DateTime" DisplayText="@Localizer["DisableDayCallbackAllowNullDisplayText"]"
ShowLabel="true" @bind-Value="@_disabledNullValue" @ref="_picker1"
OnGetDisabledDaysCallback="OnGetDisabledDaysCallback" DisplayDisabledDayAsEmpty="true">
</DateTimePicker>
</div>
<div class="col-12 col-sm-6">
<DateTimePicker ViewMode="DatePickerViewMode.DateTime" DisplayText="@Localizer["DisableDayCallbackNotAllowNullDisplayText"]"
ShowLabel="true" @bind-Value="@_disabledValue" @ref="_picker2"
OnGetDisabledDaysCallback="OnGetDisabledDaysCallback">
</DateTimePicker>
</div>
</div>
</DemoBlock>

<AttributeTable Items="@GetAttributes()" />

<EventTable Items="@GetEvents()" />
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,54 @@ private string BindValueString
private bool _showSolarTerm = true;
private bool _showFestivals = true;
private bool _showHolidays = true;
private bool _disableWeekend = true;
private bool _disableToday = true;
private DateTime? _disabledNullValue = DateTime.Today;
private DateTime _disabledValue = DateTime.Today;

private async Task<List<DateTime>> OnGetDisabledDaysCallback(DateTime start, DateTime end)
{
var ret = new List<DateTime>();
if (_disableWeekend)
{
var day = start;
while (day <= end)
{
if (day.DayOfWeek is DayOfWeek.Sunday or DayOfWeek.Saturday)
{
ret.Add(day);
}
day = day.AddDays(1);
}

if (DateTime.Today.DayOfWeek is DayOfWeek.Sunday or DayOfWeek.Saturday)
{
// 处理今天是否禁用
ret.Add(DateTime.Today);
}
}

if (_disableToday)
{
// 处理今天是否禁用
ret.Add(DateTime.Today);
}

// 模拟异步延迟
await Task.Delay(100);
return ret;
}

private DateTimePicker<DateTime?> _picker1 = default!;

private DateTimePicker<DateTime> _picker2 = default!;

private Task OnDisabledDaysChanged(bool v)
{
_picker1.ClearDisabledDays();
_picker2.ClearDisabledDays();
return Task.CompletedTask;
}

/// <summary>
/// 获得事件方法
Expand All @@ -108,6 +156,12 @@ private EventItem[] GetEvents() =>
Name = "ValueChanged",
Description = Localizer["Event2"],
Type ="EventCallback<DateTime?>"
},
new()
{
Name = "OnGetDisabledDaysCallback",
Description = Localizer["OnGetDisabledDaysCallbackEvent"],
Type ="Func<DateTime, DateTime, Task<List<DateTime>>>"
}
];

Expand Down Expand Up @@ -214,6 +268,13 @@ private AttributeItem[] GetAttributes() =>
Type = "bool",
ValueList = "true/false",
DefaultValue = "false"
},
new() {
Name = "EnableDisabledDaysCache",
Description = Localizer["AttrEnableDisabledDaysCache"],
Type = "bool",
ValueList = "true/false",
DefaultValue = "true"
}
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ private AttributeItem[] GetAttributes() =>
Description = Localizer["OffTextAttr"],
Type = "string",
ValueList = "—",
DefaultValue = Localizer["OffTextDefautValue"]!
DefaultValue = Localizer["OffTextDefaultValue"]!
},
new()
{
Name = "OnText",
Description = Localizer["OnTextAttr"],
Type = "string",
ValueList = "—",
DefaultValue = Localizer["OnTextDefautValue"]!
DefaultValue = Localizer["OnTextDefaultValue"]!
},
new()
{
Expand Down
Loading