feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Tag as AntTag } from 'antd';
|
||||
import {
|
||||
Avatar,
|
||||
Space,
|
||||
@@ -25,7 +26,7 @@ import {
|
||||
Tooltip,
|
||||
Popover,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
renderGroup,
|
||||
renderQuota,
|
||||
@@ -35,7 +36,7 @@ import {
|
||||
renderModelPriceSimple,
|
||||
hoverOrClickTrigger,
|
||||
} from '../../../helpers';
|
||||
import { IconHelpCircle } from '@douyinfe/semi-icons';
|
||||
import { IconHelpCircle } from '@/components/ui/icons';
|
||||
import { Route } from 'lucide-react';
|
||||
|
||||
const colors = [
|
||||
@@ -282,6 +283,145 @@ function renderModelName(record, copyText, t, isRootUser) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 使用记录(个人端)呈现:原型为 Ant Design 预设无边框标签与纯文本,不含渐变点、脉冲与悬停缩放 ----
|
||||
const RECORD_TYPE_COLORS = {
|
||||
1: 'cyan',
|
||||
2: 'green',
|
||||
3: 'orange',
|
||||
4: 'purple',
|
||||
5: 'red',
|
||||
};
|
||||
|
||||
function renderRecordTime(text) {
|
||||
const [date, time] = String(text || '').split(' ');
|
||||
return (
|
||||
<div className='usage-record-time'>
|
||||
<span>{date}</span>
|
||||
<strong>{time}</strong>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function renderRecordType(type, t) {
|
||||
const config = TYPE_CONFIG[type] || TYPE_CONFIG.default;
|
||||
return (
|
||||
<AntTag bordered={false} color={RECORD_TYPE_COLORS[type]}>
|
||||
{t(config.label)}
|
||||
</AntTag>
|
||||
);
|
||||
}
|
||||
|
||||
function renderRecordUseTime(record, t) {
|
||||
const useTime = `${parseInt(record.use_time)}s`;
|
||||
const other = getLogOther(record.other);
|
||||
const firstTime =
|
||||
record.is_stream && other?.frt
|
||||
? ` / ${(parseFloat(other.frt) / 1000.0).toFixed(1)}s`
|
||||
: '';
|
||||
return (
|
||||
<span className='usage-record-use-time'>
|
||||
<span>
|
||||
{useTime}
|
||||
{firstTime && <em>{firstTime}</em>}
|
||||
</span>
|
||||
<AntTag bordered={false} color={record.is_stream ? 'cyan' : undefined}>
|
||||
{record.is_stream ? t('流') : t('非流')}
|
||||
</AntTag>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const formatRecordNumber = (value) => {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? number.toLocaleString('en-US') : value;
|
||||
};
|
||||
|
||||
// 仅替换展示,不改变列的显示条件、复制回调与数据来源
|
||||
const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
|
||||
columns.map((column) => {
|
||||
switch (column.key) {
|
||||
case COLUMN_KEYS.TIME:
|
||||
return { ...column, render: (text) => renderRecordTime(text) };
|
||||
case COLUMN_KEYS.TOKEN:
|
||||
return {
|
||||
...column,
|
||||
title: t('密钥'),
|
||||
render: (text, record) =>
|
||||
record.type === 0 || record.type === 2 || record.type === 5 ? (
|
||||
<button
|
||||
type='button'
|
||||
className='usage-record-copy-text'
|
||||
onClick={(event) => copyText(event, text)}
|
||||
>
|
||||
{t(text)}
|
||||
</button>
|
||||
) : null,
|
||||
};
|
||||
case COLUMN_KEYS.GROUP:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record, index) => {
|
||||
const node = column.render(text, record, index);
|
||||
const group =
|
||||
record.group || getLogOther(record.other)?.group || '';
|
||||
return group && node?.props?.children ? (
|
||||
<AntTag bordered={false}>{group}</AntTag>
|
||||
) : null;
|
||||
},
|
||||
};
|
||||
case COLUMN_KEYS.TYPE:
|
||||
return { ...column, render: (text) => renderRecordType(text, t) };
|
||||
case COLUMN_KEYS.MODEL:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record, index) =>
|
||||
record.type === 0 || record.type === 2 || record.type === 5 ? (
|
||||
<span className='usage-record-model'>
|
||||
{column.render(text, record, index)}
|
||||
</span>
|
||||
) : null,
|
||||
};
|
||||
case COLUMN_KEYS.USE_TIME:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record) =>
|
||||
record.type === 2 || record.type === 5
|
||||
? renderRecordUseTime(record, t)
|
||||
: null,
|
||||
};
|
||||
case COLUMN_KEYS.PROMPT:
|
||||
case COLUMN_KEYS.COMPLETION:
|
||||
return {
|
||||
...column,
|
||||
align: 'right',
|
||||
render: (text, record, index) => {
|
||||
const node = column.render(text, record, index);
|
||||
return node?.props?.children ? formatRecordNumber(text) : null;
|
||||
},
|
||||
};
|
||||
case COLUMN_KEYS.COST:
|
||||
return {
|
||||
...column,
|
||||
align: 'right',
|
||||
render: (text, record, index) => (
|
||||
<span className='usage-record-cost'>
|
||||
{column.render(text, record, index)}
|
||||
</span>
|
||||
),
|
||||
};
|
||||
case COLUMN_KEYS.IP:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record, index) =>
|
||||
(record.type === 2 || record.type === 5) && text
|
||||
? column.render(text, record, index)
|
||||
: '—',
|
||||
};
|
||||
default:
|
||||
return column;
|
||||
}
|
||||
});
|
||||
|
||||
export const getLogsColumns = ({
|
||||
t,
|
||||
COLUMN_KEYS,
|
||||
@@ -289,8 +429,9 @@ export const getLogsColumns = ({
|
||||
showUserInfoFunc,
|
||||
isAdminUser,
|
||||
isRootUser = false,
|
||||
usageRecordMode = false,
|
||||
}) => {
|
||||
return [
|
||||
const columns = [
|
||||
{
|
||||
key: COLUMN_KEYS.TIME,
|
||||
title: t('时间'),
|
||||
@@ -645,4 +786,7 @@ export const getLogsColumns = ({
|
||||
},
|
||||
},
|
||||
];
|
||||
return usageRecordMode
|
||||
? applyUsageRecordPresentation(columns, { t, COLUMN_KEYS, copyText })
|
||||
: columns;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user