diff --git a/web/src/components/table/tokens/TokensColumnDefs.js b/web/src/components/table/tokens/TokensColumnDefs.js index ffa5ff79..4c8125fc 100644 --- a/web/src/components/table/tokens/TokensColumnDefs.js +++ b/web/src/components/table/tokens/TokensColumnDefs.js @@ -28,7 +28,8 @@ import { Avatar, Tooltip, Progress, - Switch, + Popover, + Typography, Input, Modal } from '@douyinfe/semi-ui'; @@ -46,21 +47,22 @@ import { IconEyeClosed, } from '@douyinfe/semi-icons'; +// progress color helper +const getProgressColor = (pct) => { + if (pct === 100) return 'var(--semi-color-success)'; + if (pct <= 10) return 'var(--semi-color-danger)'; + if (pct <= 30) return 'var(--semi-color-warning)'; + return undefined; +}; + // Render functions function renderTimestamp(timestamp) { return <>{timestamp2string(timestamp)}; } -// Render status column with switch and progress bar -const renderStatus = (text, record, manageToken, t) => { +// Render status column only (no usage) +const renderStatus = (text, record, t) => { const enabled = text === 1; - const handleToggle = (checked) => { - if (checked) { - manageToken(record.id, 'enable', record); - } else { - manageToken(record.id, 'disable', record); - } - }; let tagColor = 'black'; let tagText = t('未知状态'); @@ -78,69 +80,11 @@ const renderStatus = (text, record, manageToken, t) => { tagText = t('已耗尽'); } - const used = parseInt(record.used_quota) || 0; - const remain = parseInt(record.remain_quota) || 0; - const total = used + remain; - const percent = total > 0 ? (remain / total) * 100 : 0; - - const getProgressColor = (pct) => { - if (pct === 100) return 'var(--semi-color-success)'; - if (pct <= 10) return 'var(--semi-color-danger)'; - if (pct <= 30) return 'var(--semi-color-warning)'; - return undefined; - }; - - const quotaSuffix = record.unlimited_quota ? ( -
{t('无限额度')}
- ) : ( -
- {`${renderQuota(remain)} / ${renderQuota(total)}`} - `${percent.toFixed(0)}%`} - style={{ width: '100%', marginTop: '1px', marginBottom: 0 }} - /> -
- ); - - const content = ( - - } - suffixIcon={quotaSuffix} - > + return ( + {tagText} ); - - const tooltipContent = record.unlimited_quota ? ( -
-
{t('已用额度')}: {renderQuota(used)}
-
- ) : ( -
-
{t('已用额度')}: {renderQuota(used)}
-
{t('剩余额度')}: {renderQuota(remain)} ({percent.toFixed(0)}%)
-
{t('总额度')}: {renderQuota(total)}
-
- ); - - return ( - - {content} - - ); }; // Render group column @@ -292,13 +236,65 @@ const renderAllowIps = (text, t) => { return {ipTags}; }; +// Render separate quota usage column +const renderQuotaUsage = (text, record, t) => { + const { Paragraph } = Typography; + const used = parseInt(record.used_quota) || 0; + const remain = parseInt(record.remain_quota) || 0; + const total = used + remain; + if (record.unlimited_quota) { + const popoverContent = ( +
+ + {t('已用额度')}: {renderQuota(used)} + +
+ ); + return ( + + + {t('无限额度')} + + + ); + } + const percent = total > 0 ? (remain / total) * 100 : 0; + const popoverContent = ( +
+ + {t('已用额度')}: {renderQuota(used)} + + + {t('剩余额度')}: {renderQuota(remain)} ({percent.toFixed(0)}%) + + + {t('总额度')}: {renderQuota(total)} + +
+ ); + return ( + + +
+ {`${renderQuota(remain)} / ${renderQuota(total)}`} + `${percent.toFixed(0)}%`} + style={{ width: '100%', marginTop: '1px', marginBottom: 0 }} + /> +
+
+
+ ); +}; + // Render operations column const renderOperations = (text, record, onOpenLink, setEditingToken, setShowEdit, manageToken, refresh, t) => { let chats = localStorage.getItem('chats'); let chatsArray = []; - let shouldUseCustom = true; - - if (shouldUseCustom) { + if (true) { try { chats = JSON.parse(chats); if (Array.isArray(chats)) { @@ -318,7 +314,6 @@ const renderOperations = (text, record, onOpenLink, setEditingToken, setShowEdit } } } catch (e) { - console.log(e); showError(t('聊天链接配置错误,请联系管理员')); } } @@ -359,6 +354,29 @@ const renderOperations = (text, record, onOpenLink, setEditingToken, setShowEdit + {record.status === 1 ? ( + + ) : ( + + )} + + ) : ( + + )}