Skip to content

Commit 62eb9fe

Browse files
committed
修改FlipClock
增加ShowDay参数
1 parent c0e8878 commit 62eb9fe

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor

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

55
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" id="@Id">
6+
7+
@if (ShowDay)
8+
{
9+
<div class="bb-flip-clock-list day">
10+
@RenderItem(10)
11+
@RenderItem(10)
12+
</div>
13+
}
14+
615
@if (ShowHour)
716
{
817
<div class="bb-flip-clock-list hour">

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace BootstrapBlazor.Components;
1111
/// </summary>
1212
public partial class FlipClock
1313
{
14+
/// <summary>
15+
/// 获得/设置 是否显示 Day 默认 false
16+
/// </summary>
17+
[Parameter]
18+
public bool ShowDay { get; set; } = false;
1419
/// <summary>
1520
/// 获得/设置 是否显示 Hour 默认 true
1621
/// </summary>

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,36 @@ export function init(id, options) {
2121

2222
let counter = 0;
2323
const getDate = () => {
24+
let totalMilliseconds = 0;
2425
let now;
26+
2527
if (options.viewMode === "Count") {
2628
counter += 1000;
27-
now = new Date(new Date().getTimezoneOffset() * 60 * 1000 - options.startValue + counter);
29+
// 计算累计时间(单位:毫秒)
30+
totalMilliseconds = counter - options.startValue;
2831
}
2932
else if (countDown) {
3033
counter += 1000;
31-
now = new Date(new Date().getTimezoneOffset() * 60 * 1000 + options.startValue - counter);
34+
// 计算剩余时间(单位:毫秒)
35+
totalMilliseconds = options.startValue - counter;
36+
// 确保不会出现负数
37+
if (totalMilliseconds < 0) totalMilliseconds = 0;
3238
}
3339
else {
3440
now = new Date();
41+
return {
42+
days: now.getDate(), // 返回当前日期(月份中的第几天)
43+
hours: now.getHours(),
44+
minutes: now.getMinutes(),
45+
seconds: now.getSeconds()
46+
};
3547
}
36-
return { hours: now.getHours(), minutes: now.getMinutes(), seconds: now.getSeconds() };
48+
// 将时间戳转换为天/时/分/秒
49+
const seconds = Math.floor(totalMilliseconds / 1000) % 60;
50+
const minutes = Math.floor(totalMilliseconds / (1000 * 60)) % 60;
51+
const hours = Math.floor(totalMilliseconds / (1000 * 60 * 60)) % 24;
52+
const days = Math.floor(totalMilliseconds / (1000 * 60 * 60 * 24));
53+
return { days, hours, minutes, seconds };
3754
}
3855

3956
let lastHour;

0 commit comments

Comments
 (0)