feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
@@ -336,12 +336,56 @@ const formatRecordNumber = (value) => {
|
||||
return Number.isFinite(number) ? number.toLocaleString('en-US') : value;
|
||||
};
|
||||
|
||||
// Both reference images show the same 2097px table at opposite scroll positions.
|
||||
const RECORD_COLUMN_WIDTHS = {
|
||||
time: 152,
|
||||
channel: 85,
|
||||
username: 120,
|
||||
token: 120,
|
||||
group: 148,
|
||||
type: 110,
|
||||
model: 225,
|
||||
use_time: 126,
|
||||
prompt: 110,
|
||||
completion: 110,
|
||||
cost: 136,
|
||||
ip: 110,
|
||||
retry: 120,
|
||||
details: 305,
|
||||
};
|
||||
|
||||
// 仅替换展示,不改变列的显示条件、复制回调与数据来源
|
||||
const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
|
||||
columns.map((column) => {
|
||||
const applyUsageRecordPresentation = (
|
||||
columns,
|
||||
{ t, COLUMN_KEYS, copyText, showUserInfoFunc, isAdminUser },
|
||||
) =>
|
||||
columns.map((baseColumn) => {
|
||||
const column = {
|
||||
...baseColumn,
|
||||
width: RECORD_COLUMN_WIDTHS[baseColumn.key],
|
||||
fixed: undefined,
|
||||
className: `usage-record-cell-${baseColumn.key}`,
|
||||
};
|
||||
switch (column.key) {
|
||||
case COLUMN_KEYS.TIME:
|
||||
return { ...column, render: (text) => renderRecordTime(text) };
|
||||
case COLUMN_KEYS.USERNAME:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record) =>
|
||||
isAdminUser ? (
|
||||
<button
|
||||
type='button'
|
||||
className='usage-record-copy-text'
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
showUserInfoFunc(record.user_id);
|
||||
}}
|
||||
>
|
||||
{record.display_name || text}
|
||||
</button>
|
||||
) : null,
|
||||
};
|
||||
case COLUMN_KEYS.TOKEN:
|
||||
return {
|
||||
...column,
|
||||
@@ -374,16 +418,21 @@ const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
|
||||
case COLUMN_KEYS.MODEL:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record, index) =>
|
||||
render: (text, record) =>
|
||||
record.type === 0 || record.type === 2 || record.type === 5 ? (
|
||||
<span className='usage-record-model'>
|
||||
{column.render(text, record, index)}
|
||||
</span>
|
||||
<button
|
||||
type='button'
|
||||
className='usage-record-copy-text usage-record-model'
|
||||
onClick={(event) => copyText(event, record.model_name)}
|
||||
>
|
||||
{record.model_name}
|
||||
</button>
|
||||
) : null,
|
||||
};
|
||||
case COLUMN_KEYS.USE_TIME:
|
||||
return {
|
||||
...column,
|
||||
title: t('用时/首字').replace('/', ' / '),
|
||||
render: (text, record) =>
|
||||
record.type === 2 || record.type === 5
|
||||
? renderRecordUseTime(record, t)
|
||||
@@ -396,7 +445,13 @@ const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
|
||||
align: 'right',
|
||||
render: (text, record, index) => {
|
||||
const node = column.render(text, record, index);
|
||||
return node?.props?.children ? formatRecordNumber(text) : null;
|
||||
const showZero =
|
||||
column.key === COLUMN_KEYS.COMPLETION &&
|
||||
Number(text) === 0 &&
|
||||
[0, 2, 5].includes(record.type);
|
||||
return node?.props?.children || showZero
|
||||
? formatRecordNumber(text)
|
||||
: null;
|
||||
},
|
||||
};
|
||||
case COLUMN_KEYS.COST:
|
||||
@@ -412,11 +467,50 @@ const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
|
||||
case COLUMN_KEYS.IP:
|
||||
return {
|
||||
...column,
|
||||
title: (
|
||||
<Tooltip
|
||||
content={t(
|
||||
'只有当用户设置开启IP记录时,才会进行请求和错误类型日志的IP记录',
|
||||
)}
|
||||
>
|
||||
<span>{t('IP')}</span>
|
||||
</Tooltip>
|
||||
),
|
||||
render: (text, record, index) =>
|
||||
(record.type === 2 || record.type === 5) && text
|
||||
? column.render(text, record, index)
|
||||
: '—',
|
||||
};
|
||||
case COLUMN_KEYS.RETRY:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record) => {
|
||||
if (!isAdminUser || (record.type !== 2 && record.type !== 5))
|
||||
return null;
|
||||
const other = getLogOther(record.other);
|
||||
const channels = other?.admin_info?.use_channel;
|
||||
return Array.isArray(channels) && channels.length
|
||||
? channels.join(' → ')
|
||||
: record.channel;
|
||||
},
|
||||
};
|
||||
case COLUMN_KEYS.DETAILS:
|
||||
return {
|
||||
...column,
|
||||
render: (text, record, index) => {
|
||||
const node = column.render(text, record, index);
|
||||
return React.cloneElement(
|
||||
node,
|
||||
{
|
||||
className: 'usage-record-details',
|
||||
style: { maxWidth: 'none', whiteSpace: 'nowrap' },
|
||||
},
|
||||
typeof node.props.children === 'string'
|
||||
? node.props.children.replaceAll(' * ', ' × ')
|
||||
: node.props.children,
|
||||
);
|
||||
},
|
||||
};
|
||||
default:
|
||||
return column;
|
||||
}
|
||||
@@ -787,6 +881,12 @@ export const getLogsColumns = ({
|
||||
},
|
||||
];
|
||||
return usageRecordMode
|
||||
? applyUsageRecordPresentation(columns, { t, COLUMN_KEYS, copyText })
|
||||
? applyUsageRecordPresentation(columns, {
|
||||
t,
|
||||
COLUMN_KEYS,
|
||||
copyText,
|
||||
showUserInfoFunc,
|
||||
isAdminUser,
|
||||
})
|
||||
: columns;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user