fix(frontend): keep long quota labels clear of progress bars

This commit is contained in:
Anderson committed 2026-10-21 02:28:53 +08:00
1 parent 8f2cbb53d9
commit 0cceee50e0
2 files changed
+7 -7

No files matched your search

@@ -35,7 +35,7 @@
<!-- Progress bar row -->
<div class="flex items-center gap-1">
<!-- Label badge (label-width: fixed = 定宽居中, auto = 限宽截断左对齐) -->
<!-- Label badge: minimum width for compact labels, or capped/truncated auto mode. -->
<span :class="[labelSizeClass, labelClass]">
{{ label }}
</span>
@@ -78,7 +78,7 @@ const props = withDefaults(
estimatedTotalCost?: number | null
showNowWhenIdle?: boolean
remainingCapacity?: boolean
/** fixed: 定宽居中徽章(账号页纵向对齐);auto: 限宽截断左对齐(监控页组合标签) */
/** fixed: 最小宽度居中徽章;auto: 限宽截断左对齐(监控页组合标签) */
labelWidth?: 'fixed' | 'auto'
}>(),
{ labelWidth: 'fixed' }
@@ -125,12 +125,11 @@ const labelClass = computed(() => {
return colors[props.color]
})
// Label badge width mode: fixed 定宽保证账号页纵向对齐;auto 限宽截断适配
// 监控页「Pro/7 天」类组合标签。百分比列在两种模式下保持不变。
// Keep short labels aligned, but let longer labels reserve space before the bar.
const labelSizeClass = computed(() =>
props.labelWidth === 'auto'
? 'max-w-[72px] shrink-0 truncate rounded px-1 text-left text-[10px] font-medium'
: 'w-[32px] shrink-0 rounded px-1 text-center text-[10px] font-medium'
: 'min-w-[32px] shrink-0 whitespace-nowrap rounded px-1 text-center text-[10px] font-medium'
)
// Progress bar color based on utilization
@@ -186,13 +186,14 @@ describe('UsageProgressBar', () => {
expect(mountAt(90).get('.h-1\\.5 + span').classes()).toContain('text-red-600')
})
it('labelWidth 默认 fixed:标签保持定宽居中,百分比列不变', () => {
it('labelWidth 默认 fixed:标签保持最小宽度且不换行,百分比列不变', () => {
const wrapper = mount(UsageProgressBar, {
props: { label: '5h', utilization: 30, color: 'indigo' }
})
const label = wrapper.get('.gap-1 > span')
expect(label.classes()).toContain('w-[32px]')
expect(label.classes()).toContain('min-w-[32px]')
expect(label.classes()).toContain('whitespace-nowrap')
expect(label.classes()).toContain('text-center')
expect(label.classes()).not.toContain('max-w-[72px]')