Skip to content
Open
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion plugins/ztools-simpletimer/src/TimerWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const currentDisplayMs = computed(() => {
})

const displayTime = computed(() => formatTime(currentDisplayMs.value))
const displayTick = computed(() => Math.floor((currentDisplayMs.value % 1000) / 100))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

currentDisplayMs.value 在正计时模式下(stopwatch)直接取自 elapsedMs.value。如果系统时钟发生回拨,elapsedMs.value 可能会变为负数。虽然 formatTime 函数内部使用了 Math.max(0, ms) 来处理负值,但这里的 displayTick 计算直接使用了原始值。在 JavaScript 中,负数取模的结果仍为负数(例如 -150 % 1000-150),这会导致界面在极端情况下显示出类似 00:00:00.-1 的异常样式。建议在此处也进行边界检查,确保显示的一致性。

const displayTick = computed(() => Math.floor((Math.max(0, currentDisplayMs.value) % 1000) / 100))

const isCountdownLocked = computed(() => mode.value === 'countdown' && isRunning.value)
const isCountdownStartDisabled = computed(() => {
return mode.value === 'countdown' && !isRunning.value && countdownMs.value - elapsedMs.value <= 0
Expand Down Expand Up @@ -569,7 +570,7 @@ function handleBlur() {
</header>

<section class="timer-face" :class="{ 'timer-face-spacious': mode === 'stopwatch' }" aria-label="计时显示">
<output class="timer-display">{{ displayTime }}</output>
<output class="timer-display">{{ displayTime }}<span class="timer-tick">.{{ displayTick }}</span></output>
<div v-if="mode === 'countdown'" class="countdown-track" aria-hidden="true">
<span :style="{ width: `${Math.min(100, Math.max(0, (elapsedMs / Math.max(countdownMs, 1)) * 100))}%` }"></span>
</div>
Expand Down Expand Up @@ -773,6 +774,12 @@ input {
font-variant-numeric: tabular-nums;
letter-spacing: 0;
}
.timer-tick {
opacity: 0.72;
font-size: calc(22px * var(--timer-scale));
line-height: 1;
vertical-align: baseline;
}

.countdown-track {
width: calc(168px * var(--timer-scale));
Expand Down