feat: update log table style

This commit is contained in:
JustSong 2025-01-31 20:02:51 +08:00
parent dc470ce82e
commit bad57d049a
2 changed files with 79 additions and 29 deletions

View File

@ -9,13 +9,34 @@ import {
Select, Select,
Table, Table,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import { API, isAdmin, showError, timestamp2string } from '../helpers'; import {
API,
copy,
isAdmin,
showError,
showSuccess,
showWarning,
timestamp2string,
} from '../helpers';
import { ITEMS_PER_PAGE } from '../constants'; import { ITEMS_PER_PAGE } from '../constants';
import { renderQuota } from '../helpers/render'; import { renderColorLabel, renderQuota } from '../helpers/render';
function renderTimestamp(timestamp) { function renderTimestamp(timestamp, request_id) {
return <>{timestamp2string(timestamp)}</>; return (
<code
onClick={async () => {
if (await copy(request_id)) {
showSuccess(`已复制请求 ID${request_id}`);
} else {
showWarning(`请求 ID 复制失败:${request_id}`);
}
}}
style={{ cursor: 'pointer' }}
>
{timestamp2string(timestamp)}
</code>
);
} }
const MODE_OPTIONS = [ const MODE_OPTIONS = [
@ -103,8 +124,6 @@ function renderDetail(log) {
</Label> </Label>
</> </>
)} )}
<br />
<code>{log.request_id}</code>
</> </>
); );
} }
@ -467,7 +486,9 @@ const LogsTable = () => {
if (log.deleted) return <></>; if (log.deleted) return <></>;
return ( return (
<Table.Row key={log.id}> <Table.Row key={log.id}>
<Table.Cell>{renderTimestamp(log.created_at)}</Table.Cell> <Table.Cell>
{renderTimestamp(log.created_at, log.request_id)}
</Table.Cell>
{isAdminUser && ( {isAdminUser && (
<Table.Cell> <Table.Cell>
{log.channel ? <Label basic>{log.channel}</Label> : ''} {log.channel ? <Label basic>{log.channel}</Label> : ''}
@ -475,23 +496,21 @@ const LogsTable = () => {
)} )}
{isAdminUser && ( {isAdminUser && (
<Table.Cell> <Table.Cell>
{log.username ? <Label>{log.username}</Label> : ''} {log.username ? (
</Table.Cell> <Label basic size={'tiny'}>
)} {log.username}
<Table.Cell> </Label>
{log.token_name ? (
<Label basic>{log.token_name}</Label>
) : ( ) : (
'' ''
)} )}
</Table.Cell> </Table.Cell>
)}
<Table.Cell>
{log.token_name ? renderColorLabel(log.token_name) : ''}
</Table.Cell>
<Table.Cell>{renderType(log.type)}</Table.Cell> <Table.Cell>{renderType(log.type)}</Table.Cell>
<Table.Cell> <Table.Cell>
{log.model_name ? ( {log.model_name ? renderColorLabel(log.model_name) : ''}
<Label basic>{log.model_name}</Label>
) : (
''
)}
</Table.Cell> </Table.Cell>
<Table.Cell> <Table.Cell>
{log.prompt_tokens ? log.prompt_tokens : ''} {log.prompt_tokens ? log.prompt_tokens : ''}

View File

@ -13,7 +13,8 @@ export function renderGroup(group) {
} }
let groups = group.split(','); let groups = group.split(',');
groups.sort(); groups.sort();
return <> return (
<>
{groups.map((group) => { {groups.map((group) => {
if (group === 'vip' || group === 'pro') { if (group === 'vip' || group === 'pro') {
return <Label color='yellow'>{group}</Label>; return <Label color='yellow'>{group}</Label>;
@ -22,7 +23,8 @@ export function renderGroup(group) {
} }
return <Label>{group}</Label>; return <Label>{group}</Label>;
})} })}
</>; </>
);
} }
export function renderNumber(num) { export function renderNumber(num) {
@ -56,3 +58,32 @@ export function renderQuotaWithPrompt(quota, digits) {
} }
return ''; return '';
} }
const colors = [
'red',
'orange',
'yellow',
'olive',
'green',
'teal',
'blue',
'violet',
'purple',
'pink',
'brown',
'grey',
'black',
];
export function renderColorLabel(text) {
let hash = 0;
for (let i = 0; i < text.length; i++) {
hash = text.charCodeAt(i) + ((hash << 5) - hash);
}
let index = Math.abs(hash % colors.length);
return (
<Label basic size={'tiny'} color={colors[index]}>
{text}
</Label>
);
}