Skip to content

Commit cee3310

Browse files
committed
feat: 增加 ShowMonth 参数
1 parent 1c0abc4 commit cee3310

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true)]
44

55
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" id="@Id">
6+
@if (ShowDay)
7+
{
8+
<div class="bb-flip-clock-list month">
9+
@RenderItem(3)
10+
@RenderItem(10)
11+
</div>
12+
}
13+
614
@if (ShowDay)
715
{
816
<div class="bb-flip-clock-list day">

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace BootstrapBlazor.Components;
1111
/// </summary>
1212
public partial class FlipClock
1313
{
14+
/// <summary>
15+
/// 获得/设置 是否显示 Month 默认 false
16+
/// </summary>
17+
[Parameter]
18+
public bool ShowMonth { get; set; }
19+
1420
/// <summary>
1521
/// 获得/设置 是否显示 Day 默认 false
1622
/// </summary>

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function init(id, options) {
1414
return;
1515
}
1616

17+
const listMonth = el.querySelector('.bb-flip-clock-list.month');
1718
const listDay = el.querySelector('.bb-flip-clock-list.day');
1819
const listHour = el.querySelector('.bb-flip-clock-list.hour');
1920
const listMinute = el.querySelector('.bb-flip-clock-list.minute');
@@ -37,6 +38,7 @@ export function init(id, options) {
3738
else {
3839
now = new Date();
3940
return {
41+
months: now.getMonth() + 1,
4042
days: now.getDate(),
4143
hours: now.getHours(),
4244
minutes: now.getMinutes(),
@@ -48,15 +50,16 @@ export function init(id, options) {
4850
const minutes = Math.floor(totalMilliseconds / (1000 * 60)) % 60;
4951
const hours = Math.floor(totalMilliseconds / (1000 * 60 * 60)) % 24;
5052
const days = Math.floor(totalMilliseconds / (1000 * 60 * 60 * 24));
51-
return { days, hours, minutes, seconds };
53+
return { months, days, hours, minutes, seconds };
5254
}
5355

56+
let lastMonth;
5457
let lastDay;
5558
let lastHour;
5659
let lastMinute;
5760
let lastSecond;
5861
const go = () => {
59-
const { days, hours, minutes, seconds } = getDate();
62+
const { months, days, hours, minutes, seconds } = getDate();
6063

6164
if (lastSecond !== seconds) {
6265
lastSecond = seconds;
@@ -74,7 +77,11 @@ export function init(id, options) {
7477
lastDay = days;
7578
setTime(listDay, days, countDown);
7679
}
77-
return { days, hours, minutes, seconds }
80+
if (lastMonth !== months) {
81+
lastDay = days;
82+
setTime(listMonth, months, countDown);
83+
}
84+
return { months, days, hours, minutes, seconds }
7885
}
7986

8087
let start = void 0

0 commit comments

Comments
 (0)