Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
28e36f79
Unverified
Commit
28e36f79
authored
Mar 18, 2026
by
Wesley Liddick
Committed by
GitHub
Mar 18, 2026
Browse files
Merge pull request #1096 from Ethan0x0000/pr/fix-idle-usage-windows
fix(ui): 会话窗口空闲时显示“现在”,避免重置时间缺失
parents
6c020763
2005fc97
Changes
3
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/account/AccountUsageCell.vue
View file @
28e36f79
...
@@ -82,6 +82,7 @@
...
@@ -82,6 +82,7 @@
:utilization=
"usageInfo.five_hour.utilization"
:utilization=
"usageInfo.five_hour.utilization"
:resets-at=
"usageInfo.five_hour.resets_at"
:resets-at=
"usageInfo.five_hour.resets_at"
:window-stats=
"usageInfo.five_hour.window_stats"
:window-stats=
"usageInfo.five_hour.window_stats"
:show-now-when-idle=
"true"
color=
"indigo"
color=
"indigo"
/>
/>
<UsageProgressBar
<UsageProgressBar
...
@@ -90,6 +91,7 @@
...
@@ -90,6 +91,7 @@
:utilization=
"usageInfo.seven_day.utilization"
:utilization=
"usageInfo.seven_day.utilization"
:resets-at=
"usageInfo.seven_day.resets_at"
:resets-at=
"usageInfo.seven_day.resets_at"
:window-stats=
"usageInfo.seven_day.window_stats"
:window-stats=
"usageInfo.seven_day.window_stats"
:show-now-when-idle=
"true"
color=
"emerald"
color=
"emerald"
/>
/>
</div>
</div>
...
...
frontend/src/components/account/UsageProgressBar.vue
View file @
28e36f79
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
</span>
</span>
<!-- Reset time -->
<!-- Reset time -->
<span
v-if=
"
resetsAt
"
class=
"shrink-0 text-[10px] text-gray-400"
>
<span
v-if=
"
shouldShowResetTime
"
class=
"shrink-0 text-[10px] text-gray-400"
>
{{
formatResetTime
}}
{{
formatResetTime
}}
</span>
</span>
</div>
</div>
...
@@ -68,6 +68,7 @@ const props = defineProps<{
...
@@ -68,6 +68,7 @@ const props = defineProps<{
resetsAt
?:
string
|
null
resetsAt
?:
string
|
null
color
:
'
indigo
'
|
'
emerald
'
|
'
purple
'
|
'
amber
'
color
:
'
indigo
'
|
'
emerald
'
|
'
purple
'
|
'
amber
'
windowStats
?:
WindowStats
|
null
windowStats
?:
WindowStats
|
null
showNowWhenIdle
?:
boolean
}
>
()
}
>
()
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
...
@@ -139,9 +140,20 @@ const displayPercent = computed(() => {
...
@@ -139,9 +140,20 @@ const displayPercent = computed(() => {
return
percent
>
999
?
'
>999%
'
:
`
${
percent
}
%`
return
percent
>
999
?
'
>999%
'
:
`
${
percent
}
%`
})
})
const
shouldShowResetTime
=
computed
(()
=>
{
if
(
props
.
resetsAt
)
return
true
return
Boolean
(
props
.
showNowWhenIdle
&&
props
.
utilization
<=
0
)
})
// Format reset time
// Format reset time
const
formatResetTime
=
computed
(()
=>
{
const
formatResetTime
=
computed
(()
=>
{
// For rolling windows, when utilization is 0%, treat as immediately available.
if
(
props
.
showNowWhenIdle
&&
props
.
utilization
<=
0
)
{
return
'
现在
'
}
if
(
!
props
.
resetsAt
)
return
'
-
'
if
(
!
props
.
resetsAt
)
return
'
-
'
const
date
=
new
Date
(
props
.
resetsAt
)
const
date
=
new
Date
(
props
.
resetsAt
)
const
diffMs
=
date
.
getTime
()
-
now
.
value
.
getTime
()
const
diffMs
=
date
.
getTime
()
-
now
.
value
.
getTime
()
...
...
frontend/src/components/account/__tests__/UsageProgressBar.spec.ts
0 → 100644
View file @
28e36f79
import
{
afterEach
,
beforeEach
,
describe
,
expect
,
it
,
vi
}
from
'
vitest
'
import
{
mount
}
from
'
@vue/test-utils
'
import
UsageProgressBar
from
'
../UsageProgressBar.vue
'
vi
.
mock
(
'
vue-i18n
'
,
async
()
=>
{
const
actual
=
await
vi
.
importActual
<
typeof
import
(
'
vue-i18n
'
)
>
(
'
vue-i18n
'
)
return
{
...
actual
,
useI18n
:
()
=>
({
t
:
(
key
:
string
)
=>
key
})
}
})
describe
(
'
UsageProgressBar
'
,
()
=>
{
beforeEach
(()
=>
{
vi
.
useFakeTimers
()
vi
.
setSystemTime
(
new
Date
(
'
2026-03-17T00:00:00Z
'
))
})
afterEach
(()
=>
{
vi
.
useRealTimers
()
})
it
(
'
showNowWhenIdle=true 且利用率为 0 时显示“现在”
'
,
()
=>
{
const
wrapper
=
mount
(
UsageProgressBar
,
{
props
:
{
label
:
'
5h
'
,
utilization
:
0
,
resetsAt
:
'
2026-03-17T02:30:00Z
'
,
showNowWhenIdle
:
true
,
color
:
'
indigo
'
}
})
expect
(
wrapper
.
text
()).
toContain
(
'
现在
'
)
expect
(
wrapper
.
text
()).
not
.
toContain
(
'
2h 30m
'
)
})
it
(
'
showNowWhenIdle=true 但利用率大于 0 时显示倒计时
'
,
()
=>
{
const
wrapper
=
mount
(
UsageProgressBar
,
{
props
:
{
label
:
'
7d
'
,
utilization
:
12
,
resetsAt
:
'
2026-03-17T02:30:00Z
'
,
showNowWhenIdle
:
true
,
color
:
'
emerald
'
}
})
expect
(
wrapper
.
text
()).
toContain
(
'
2h 30m
'
)
expect
(
wrapper
.
text
()).
not
.
toContain
(
'
现在
'
)
})
it
(
'
showNowWhenIdle=false 时保持原有倒计时行为
'
,
()
=>
{
const
wrapper
=
mount
(
UsageProgressBar
,
{
props
:
{
label
:
'
1d
'
,
utilization
:
0
,
resetsAt
:
'
2026-03-17T02:30:00Z
'
,
showNowWhenIdle
:
false
,
color
:
'
indigo
'
}
})
expect
(
wrapper
.
text
()).
toContain
(
'
2h 30m
'
)
expect
(
wrapper
.
text
()).
not
.
toContain
(
'
现在
'
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment