🎨 style(tokens-table): enhance quota usage progress bar UI

Improves the “Balance” column in `TokensTable`:

• Re-styled progress bar: wider container (`w-[140px]`) and `showInfo` enabled to display percentage label.
• Added `format={() => \`\${percent}%\`}` for precise percentage feedback.
• Maintains dynamic color mapping (success / warning / danger) for clarity.

Result: clearer, more informative visual representation of remaining token quota.
This commit is contained in:
t0ng7u
2025-07-13 18:10:59 +08:00
parent 4f06a1df50
commit d1e48d02bd
3 changed files with 9 additions and 23 deletions

View File

@@ -34,7 +34,6 @@ import {
Layout, Layout,
Modal, Modal,
Progress, Progress,
Skeleton,
Table, Table,
Tag, Tag,
Typography Typography
@@ -665,17 +664,7 @@ const LogsTable = () => {
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full"> <div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full">
<div className="flex items-center text-orange-500 mb-2 md:mb-0"> <div className="flex items-center text-orange-500 mb-2 md:mb-0">
<IconEyeOpened className="mr-2" /> <IconEyeOpened className="mr-2" />
{loading ? ( <Text>{t('任务记录')}</Text>
<Skeleton.Title
style={{
width: 300,
marginBottom: 0,
marginTop: 0
}}
/>
) : (
<Text>{t('任务记录')}</Text>
)}
</div> </div>
<Button <Button
theme='light' theme='light'

View File

@@ -40,7 +40,6 @@ import {
IconCopy, IconCopy,
IconEyeOpened, IconEyeOpened,
IconEyeClosed, IconEyeClosed,
IconBolt,
} from '@douyinfe/semi-icons'; } from '@douyinfe/semi-icons';
import { Key } from 'lucide-react'; import { Key } from 'lucide-react';
import EditToken from '../../pages/Token/EditToken'; import EditToken from '../../pages/Token/EditToken';
@@ -62,7 +61,7 @@ const TokensTable = () => {
dataIndex: 'name', dataIndex: 'name',
}, },
{ {
title: t('余'), title: t('余'),
key: 'quota', key: 'quota',
render: (text, record) => { render: (text, record) => {
if (record.unlimited_quota) { if (record.unlimited_quota) {
@@ -72,15 +71,13 @@ const TokensTable = () => {
const used = parseInt(record.used_quota) || 0; const used = parseInt(record.used_quota) || 0;
const remain = parseInt(record.remain_quota) || 0; const remain = parseInt(record.remain_quota) || 0;
const total = used + remain; const total = used + remain;
// 计算剩余额度百分比100% 表示额度未使用
const percent = total > 0 ? (remain / total) * 100 : 0; const percent = total > 0 ? (remain / total) * 100 : 0;
// 根据剩余百分比动态设置颜色100% 绿色,<=10% 红色,<=30% 黄色,其余默认
const getProgressColor = (pct) => { const getProgressColor = (pct) => {
if (pct === 100) return 'var(--semi-color-success)'; if (pct === 100) return 'var(--semi-color-success)';
if (pct <= 10) return 'var(--semi-color-danger)'; if (pct <= 10) return 'var(--semi-color-danger)';
if (pct <= 30) return 'var(--semi-color-warning)'; if (pct <= 30) return 'var(--semi-color-warning)';
return undefined; // 默认颜色 return undefined;
}; };
return ( return (
@@ -93,13 +90,13 @@ const TokensTable = () => {
</div> </div>
} }
> >
<div className='w-[30px]'> <div className='w-[140px]'>
<Progress <Progress
percent={percent} percent={percent}
stroke={getProgressColor(percent)} stroke={getProgressColor(percent)}
showInfo={false} showInfo
aria-label='quota usage' aria-label='quota usage'
type="circle" format={() => `${percent.toFixed(0)}%`}
size='small' size='small'
/> />
</div> </div>
@@ -141,7 +138,7 @@ const TokensTable = () => {
<Tag <Tag
color={tagColor} color={tagColor}
shape='circle' shape='circle'
prefixIcon={ suffixIcon={
<Switch <Switch
size='small' size='small'
checked={enabled} checked={enabled}
@@ -166,7 +163,7 @@ const TokensTable = () => {
content={t('当前分组为 auto会自动选择最优分组当一个组不可用时自动降级到下一个组熔断机制')} content={t('当前分组为 auto会自动选择最优分组当一个组不可用时自动降级到下一个组熔断机制')}
position='top' position='top'
> >
<Tag color='blue' shape='circle' prefixIcon={<IconBolt />}> {t('智能熔断')} </Tag> <Tag color='white' shape='circle'> {t('智能熔断')} </Tag>
</Tooltip> </Tooltip>
); );
} }

View File

@@ -584,7 +584,7 @@ export function renderText(text, limit) {
export function renderGroup(group) { export function renderGroup(group) {
if (group === '') { if (group === '') {
return ( return (
<Tag key='default' color='orange' shape='circle'> <Tag key='default' color='white' shape='circle'>
{i18next.t('用户分组')} {i18next.t('用户分组')}
</Tag> </Tag>
); );