2025-06-04 14:31:54 +08:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2024-12-13 19:03:14 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-03-23 21:24:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
API,
|
2024-08-11 11:25:32 +08:00
|
|
|
|
copy,
|
|
|
|
|
|
getTodayStartTimestamp,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
isAdmin,
|
|
|
|
|
|
showError,
|
|
|
|
|
|
showSuccess,
|
2024-08-11 11:25:32 +08:00
|
|
|
|
timestamp2string,
|
2025-06-03 23:56:39 +08:00
|
|
|
|
renderAudioModelPrice,
|
|
|
|
|
|
renderClaudeLogContent,
|
|
|
|
|
|
renderClaudeModelPrice,
|
|
|
|
|
|
renderClaudeModelPriceSimple,
|
|
|
|
|
|
renderGroup,
|
|
|
|
|
|
renderLogContent,
|
|
|
|
|
|
renderModelPrice,
|
|
|
|
|
|
renderModelPriceSimple,
|
|
|
|
|
|
renderNumber,
|
|
|
|
|
|
renderQuota,
|
|
|
|
|
|
stringToColor,
|
2025-06-04 14:31:54 +08:00
|
|
|
|
getLogOther,
|
|
|
|
|
|
renderModelTag
|
2025-06-04 00:42:06 +08:00
|
|
|
|
} from '../../helpers';
|
2023-10-31 00:03:22 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Avatar,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
Button,
|
|
|
|
|
|
Descriptions,
|
|
|
|
|
|
Modal,
|
|
|
|
|
|
Popover,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
Select,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Spin,
|
|
|
|
|
|
Table,
|
|
|
|
|
|
Tag,
|
2025-03-08 19:53:07 +08:00
|
|
|
|
Tooltip,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
Checkbox,
|
2025-05-23 13:06:53 +08:00
|
|
|
|
Card,
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
Divider,
|
|
|
|
|
|
Input,
|
2025-06-04 14:31:54 +08:00
|
|
|
|
DatePicker
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} from '@douyinfe/semi-ui';
|
2025-06-04 00:42:06 +08:00
|
|
|
|
import { ITEMS_PER_PAGE } from '../../constants';
|
2024-03-15 16:05:33 +08:00
|
|
|
|
import Paragraph from '@douyinfe/semi-ui/lib/es/typography/paragraph';
|
2025-05-23 13:06:53 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IconSetting,
|
|
|
|
|
|
IconSearch,
|
2025-06-04 14:31:54 +08:00
|
|
|
|
IconForward
|
2025-05-23 13:06:53 +08:00
|
|
|
|
} from '@douyinfe/semi-icons';
|
2023-10-31 00:03:22 +08:00
|
|
|
|
|
2025-05-23 13:06:53 +08:00
|
|
|
|
const { Text } = Typography;
|
2024-03-15 15:07:14 +08:00
|
|
|
|
|
2023-06-10 16:04:04 +08:00
|
|
|
|
function renderTimestamp(timestamp) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return <>{timestamp2string(timestamp)}</>;
|
2023-06-10 16:04:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const MODE_OPTIONS = [
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{ key: 'all', text: 'all', value: 'all' },
|
|
|
|
|
|
{ key: 'self', text: 'current user', value: 'self' },
|
2024-03-23 21:24:39 +08:00
|
|
|
|
];
|
2023-06-10 20:40:07 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const colors = [
|
|
|
|
|
|
'amber',
|
|
|
|
|
|
'blue',
|
|
|
|
|
|
'cyan',
|
|
|
|
|
|
'green',
|
|
|
|
|
|
'grey',
|
|
|
|
|
|
'indigo',
|
|
|
|
|
|
'light-blue',
|
|
|
|
|
|
'lime',
|
|
|
|
|
|
'orange',
|
|
|
|
|
|
'pink',
|
|
|
|
|
|
'purple',
|
|
|
|
|
|
'red',
|
|
|
|
|
|
'teal',
|
|
|
|
|
|
'violet',
|
|
|
|
|
|
'yellow',
|
|
|
|
|
|
];
|
2023-06-10 20:40:07 +08:00
|
|
|
|
|
2024-12-13 19:03:14 +08:00
|
|
|
|
const LogsTable = () => {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
|
|
function renderType(type) {
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case 1:
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='cyan' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('充值')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
case 2:
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='lime' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('消费')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
case 3:
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='orange' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('管理')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
case 4:
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='purple' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('系统')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2025-04-12 00:43:34 +08:00
|
|
|
|
case 5:
|
2025-04-28 11:06:32 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='red' size='large' shape='circle'>
|
2025-04-28 11:06:32 +08:00
|
|
|
|
{t('错误')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
default:
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='grey' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('未知')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderIsStream(bool) {
|
|
|
|
|
|
if (bool) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='blue' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('流')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
} else {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='purple' size='large' shape='circle'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('非流')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderUseTime(type) {
|
|
|
|
|
|
const time = parseInt(type);
|
|
|
|
|
|
if (time < 101) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='green' size='large' shape='circle'>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{' '}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{time} s{' '}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
} else if (time < 300) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='orange' size='large' shape='circle'>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{' '}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{time} s{' '}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
} else {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='red' size='large' shape='circle'>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{' '}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{time} s{' '}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderFirstUseTime(type) {
|
|
|
|
|
|
let time = parseFloat(type) / 1000.0;
|
|
|
|
|
|
time = time.toFixed(1);
|
|
|
|
|
|
if (time < 3) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='green' size='large' shape='circle'>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{' '}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{time} s{' '}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
} else if (time < 10) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='orange' size='large' shape='circle'>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{' '}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{time} s{' '}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
2024-12-13 19:03:14 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
return (
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Tag color='red' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{' '}
|
|
|
|
|
|
{time} s{' '}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-02-20 16:41:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderModelName(record) {
|
|
|
|
|
|
let other = getLogOther(record.other);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
let modelMapped =
|
|
|
|
|
|
other?.is_model_mapped &&
|
|
|
|
|
|
other?.upstream_model_name &&
|
|
|
|
|
|
other?.upstream_model_name !== '';
|
2025-02-20 16:41:46 +08:00
|
|
|
|
if (!modelMapped) {
|
2025-06-04 14:31:54 +08:00
|
|
|
|
return renderModelTag(record.model_name, {
|
|
|
|
|
|
onClick: (event) => {
|
|
|
|
|
|
copyText(event, record.model_name).then((r) => { });
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-02-20 16:41:46 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Space vertical align={'start'}>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Popover
|
|
|
|
|
|
content={
|
|
|
|
|
|
<div style={{ padding: 10 }}>
|
|
|
|
|
|
<Space vertical align={'start'}>
|
2025-06-04 14:31:54 +08:00
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
<Text strong style={{ marginRight: 8 }}>{t('请求并计费模型')}:</Text>
|
|
|
|
|
|
{renderModelTag(record.model_name, {
|
|
|
|
|
|
onClick: (event) => {
|
|
|
|
|
|
copyText(event, record.model_name).then((r) => { });
|
|
|
|
|
|
}
|
|
|
|
|
|
})}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
<Text strong style={{ marginRight: 8 }}>{t('实际模型')}:</Text>
|
|
|
|
|
|
{renderModelTag(other.upstream_model_name, {
|
|
|
|
|
|
onClick: (event) => {
|
|
|
|
|
|
copyText(event, other.upstream_model_name).then((r) => { });
|
|
|
|
|
|
}
|
|
|
|
|
|
})}
|
|
|
|
|
|
</div>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
2025-06-04 14:31:54 +08:00
|
|
|
|
{renderModelTag(record.model_name, {
|
|
|
|
|
|
onClick: (event) => {
|
2025-05-23 13:06:53 +08:00
|
|
|
|
copyText(event, record.model_name).then((r) => { });
|
2025-06-04 14:31:54 +08:00
|
|
|
|
},
|
|
|
|
|
|
suffixIcon: <IconForward style={{ width: '0.9em', height: '0.9em', opacity: 0.75 }} />
|
|
|
|
|
|
})}
|
2025-02-20 16:41:46 +08:00
|
|
|
|
</Popover>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-26 18:04:49 +08:00
|
|
|
|
|
2025-03-08 19:53:07 +08:00
|
|
|
|
// Define column keys for selection
|
|
|
|
|
|
const COLUMN_KEYS = {
|
|
|
|
|
|
TIME: 'time',
|
|
|
|
|
|
CHANNEL: 'channel',
|
|
|
|
|
|
USERNAME: 'username',
|
|
|
|
|
|
TOKEN: 'token',
|
|
|
|
|
|
GROUP: 'group',
|
|
|
|
|
|
TYPE: 'type',
|
|
|
|
|
|
MODEL: 'model',
|
|
|
|
|
|
USE_TIME: 'use_time',
|
|
|
|
|
|
PROMPT: 'prompt',
|
|
|
|
|
|
COMPLETION: 'completion',
|
|
|
|
|
|
COST: 'cost',
|
|
|
|
|
|
RETRY: 'retry',
|
2025-04-04 12:00:38 +08:00
|
|
|
|
DETAILS: 'details',
|
2025-03-08 19:53:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// State for column visibility
|
|
|
|
|
|
const [visibleColumns, setVisibleColumns] = useState({});
|
|
|
|
|
|
const [showColumnSelector, setShowColumnSelector] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
// Load saved column preferences from localStorage
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const savedColumns = localStorage.getItem('logs-table-columns');
|
|
|
|
|
|
if (savedColumns) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const parsed = JSON.parse(savedColumns);
|
|
|
|
|
|
// Make sure all columns are accounted for
|
|
|
|
|
|
const defaults = getDefaultColumnVisibility();
|
|
|
|
|
|
const merged = { ...defaults, ...parsed };
|
|
|
|
|
|
setVisibleColumns(merged);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('Failed to parse saved column preferences', e);
|
|
|
|
|
|
initDefaultColumns();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
initDefaultColumns();
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
// Get default column visibility based on user role
|
|
|
|
|
|
const getDefaultColumnVisibility = () => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
[COLUMN_KEYS.TIME]: true,
|
|
|
|
|
|
[COLUMN_KEYS.CHANNEL]: isAdminUser,
|
|
|
|
|
|
[COLUMN_KEYS.USERNAME]: isAdminUser,
|
|
|
|
|
|
[COLUMN_KEYS.TOKEN]: true,
|
|
|
|
|
|
[COLUMN_KEYS.GROUP]: true,
|
|
|
|
|
|
[COLUMN_KEYS.TYPE]: true,
|
|
|
|
|
|
[COLUMN_KEYS.MODEL]: true,
|
|
|
|
|
|
[COLUMN_KEYS.USE_TIME]: true,
|
|
|
|
|
|
[COLUMN_KEYS.PROMPT]: true,
|
|
|
|
|
|
[COLUMN_KEYS.COMPLETION]: true,
|
|
|
|
|
|
[COLUMN_KEYS.COST]: true,
|
|
|
|
|
|
[COLUMN_KEYS.RETRY]: isAdminUser,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
[COLUMN_KEYS.DETAILS]: true,
|
2025-03-08 19:53:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize default column visibility
|
|
|
|
|
|
const initDefaultColumns = () => {
|
|
|
|
|
|
const defaults = getDefaultColumnVisibility();
|
|
|
|
|
|
setVisibleColumns(defaults);
|
|
|
|
|
|
localStorage.setItem('logs-table-columns', JSON.stringify(defaults));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Handle column visibility change
|
|
|
|
|
|
const handleColumnVisibilityChange = (columnKey, checked) => {
|
|
|
|
|
|
const updatedColumns = { ...visibleColumns, [columnKey]: checked };
|
|
|
|
|
|
setVisibleColumns(updatedColumns);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Handle "Select All" checkbox
|
|
|
|
|
|
const handleSelectAll = (checked) => {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const allKeys = Object.keys(COLUMN_KEYS).map((key) => COLUMN_KEYS[key]);
|
2025-03-08 19:53:07 +08:00
|
|
|
|
const updatedColumns = {};
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
|
|
|
|
|
allKeys.forEach((key) => {
|
2025-03-08 19:53:07 +08:00
|
|
|
|
// For admin-only columns, only enable them if user is admin
|
2025-04-04 12:00:38 +08:00
|
|
|
|
if (
|
|
|
|
|
|
(key === COLUMN_KEYS.CHANNEL ||
|
|
|
|
|
|
key === COLUMN_KEYS.USERNAME ||
|
|
|
|
|
|
key === COLUMN_KEYS.RETRY) &&
|
|
|
|
|
|
!isAdminUser
|
|
|
|
|
|
) {
|
2025-03-08 19:53:07 +08:00
|
|
|
|
updatedColumns[key] = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
updatedColumns[key] = checked;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2025-03-08 19:53:07 +08:00
|
|
|
|
setVisibleColumns(updatedColumns);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Define all columns
|
|
|
|
|
|
const allColumns = [
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.TIME,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('时间'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'timestamp2string',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.CHANNEL,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('渠道'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'channel',
|
|
|
|
|
|
className: isAdmin() ? 'tableShow' : 'tableHiddle',
|
|
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
return isAdminUser ? (
|
2025-04-28 11:06:32 +08:00
|
|
|
|
record.type === 0 || record.type === 2 || record.type === 5 ? (
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
{
|
2025-01-09 15:20:12 +08:00
|
|
|
|
<Tooltip content={record.channel_name || '[未知]'}>
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color={colors[parseInt(text) % colors.length]}
|
|
|
|
|
|
size='large'
|
2025-05-23 13:06:53 +08:00
|
|
|
|
shape='circle'
|
2025-01-09 15:20:12 +08:00
|
|
|
|
>
|
|
|
|
|
|
{' '}
|
|
|
|
|
|
{text}{' '}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
</Tooltip>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
)
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.USERNAME,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('用户'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'username',
|
|
|
|
|
|
className: isAdmin() ? 'tableShow' : 'tableHiddle',
|
|
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
return isAdminUser ? (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Avatar
|
|
|
|
|
|
size='small'
|
|
|
|
|
|
color={stringToColor(text)}
|
|
|
|
|
|
style={{ marginRight: 4 }}
|
2024-12-28 15:34:28 +08:00
|
|
|
|
onClick={(event) => {
|
|
|
|
|
|
event.stopPropagation();
|
2025-04-04 12:00:38 +08:00
|
|
|
|
showUserInfo(record.user_id);
|
2024-12-28 15:34:28 +08:00
|
|
|
|
}}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
>
|
|
|
|
|
|
{typeof text === 'string' && text.slice(0, 1)}
|
|
|
|
|
|
</Avatar>
|
|
|
|
|
|
{text}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.TOKEN,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('令牌'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'token_name',
|
|
|
|
|
|
render: (text, record, index) => {
|
2025-04-28 11:06:32 +08:00
|
|
|
|
return record.type === 0 || record.type === 2 || record.type === 5 ? (
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color='grey'
|
|
|
|
|
|
size='large'
|
2025-05-23 13:06:53 +08:00
|
|
|
|
shape='circle'
|
2024-12-28 15:34:28 +08:00
|
|
|
|
onClick={(event) => {
|
|
|
|
|
|
//cancel the row click event
|
|
|
|
|
|
copyText(event, text);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{' '}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t(text)}{' '}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-12-21 20:24:22 +08:00
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.GROUP,
|
2024-12-21 20:24:22 +08:00
|
|
|
|
title: t('分组'),
|
|
|
|
|
|
dataIndex: 'group',
|
|
|
|
|
|
render: (text, record, index) => {
|
2025-04-12 00:43:34 +08:00
|
|
|
|
if (record.type === 0 || record.type === 2 || record.type === 5) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
if (record.group) {
|
|
|
|
|
|
return <>{renderGroup(record.group)}</>;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let other = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
other = JSON.parse(record.other);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error(
|
|
|
|
|
|
`Failed to parse record.other: "${record.other}".`,
|
|
|
|
|
|
e,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (other === null) {
|
|
|
|
|
|
return <></>;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (other.group !== undefined) {
|
|
|
|
|
|
return <>{renderGroup(other.group)}</>;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return <></>;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-21 20:24:22 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
return <></>;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.TYPE,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('类型'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'type',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-10-14 16:15:10 +08:00
|
|
|
|
return <>{renderType(text)}</>;
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.MODEL,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('模型'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'model_name',
|
|
|
|
|
|
render: (text, record, index) => {
|
2025-04-28 11:06:32 +08:00
|
|
|
|
return record.type === 0 || record.type === 2 || record.type === 5 ? (
|
2025-02-20 16:41:46 +08:00
|
|
|
|
<>{renderModelName(record)}</>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.USE_TIME,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('用时/首字'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'use_time',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-06-26 18:04:49 +08:00
|
|
|
|
if (record.is_stream) {
|
|
|
|
|
|
let other = getLogOther(record.other);
|
|
|
|
|
|
return (
|
2024-10-14 16:15:10 +08:00
|
|
|
|
<>
|
2024-08-11 11:25:32 +08:00
|
|
|
|
<Space>
|
|
|
|
|
|
{renderUseTime(text)}
|
2025-03-09 21:23:33 +08:00
|
|
|
|
{renderFirstUseTime(other?.frt)}
|
2024-08-11 11:25:32 +08:00
|
|
|
|
{renderIsStream(record.is_stream)}
|
|
|
|
|
|
</Space>
|
2024-10-14 16:15:10 +08:00
|
|
|
|
</>
|
2024-06-26 18:04:49 +08:00
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return (
|
2024-10-14 16:15:10 +08:00
|
|
|
|
<>
|
2024-08-11 11:25:32 +08:00
|
|
|
|
<Space>
|
|
|
|
|
|
{renderUseTime(text)}
|
|
|
|
|
|
{renderIsStream(record.is_stream)}
|
|
|
|
|
|
</Space>
|
2024-10-14 16:15:10 +08:00
|
|
|
|
</>
|
2024-06-26 18:04:49 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.PROMPT,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('提示'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'prompt_tokens',
|
|
|
|
|
|
render: (text, record, index) => {
|
2025-04-28 11:06:32 +08:00
|
|
|
|
return record.type === 0 || record.type === 2 || record.type === 5 ? (
|
2024-10-14 16:15:10 +08:00
|
|
|
|
<>{<span> {text} </span>}</>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.COMPLETION,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('补全'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'completion_tokens',
|
|
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
return parseInt(text) > 0 &&
|
2025-04-12 00:43:34 +08:00
|
|
|
|
(record.type === 0 || record.type === 2 || record.type === 5) ? (
|
2024-10-14 16:15:10 +08:00
|
|
|
|
<>{<span> {text} </span>}</>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.COST,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('花费'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'quota',
|
|
|
|
|
|
render: (text, record, index) => {
|
2025-04-28 11:06:32 +08:00
|
|
|
|
return record.type === 0 || record.type === 2 || record.type === 5 ? (
|
2024-10-14 16:15:10 +08:00
|
|
|
|
<>{renderQuota(text, 6)}</>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
) : (
|
|
|
|
|
|
<></>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-11-05 20:44:22 +08:00
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.RETRY,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('重试'),
|
2024-11-05 20:44:22 +08:00
|
|
|
|
dataIndex: 'retry',
|
|
|
|
|
|
className: isAdmin() ? 'tableShow' : 'tableHiddle',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
let content = t('渠道') + `:${record.channel}`;
|
2024-11-05 20:44:22 +08:00
|
|
|
|
if (record.other !== '') {
|
|
|
|
|
|
let other = JSON.parse(record.other);
|
|
|
|
|
|
if (other === null) {
|
|
|
|
|
|
return <></>;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (other.admin_info !== undefined) {
|
|
|
|
|
|
if (
|
|
|
|
|
|
other.admin_info.use_channel !== null &&
|
|
|
|
|
|
other.admin_info.use_channel !== undefined &&
|
|
|
|
|
|
other.admin_info.use_channel !== ''
|
|
|
|
|
|
) {
|
|
|
|
|
|
// channel id array
|
|
|
|
|
|
let useChannel = other.admin_info.use_channel;
|
|
|
|
|
|
let useChannelStr = useChannel.join('->');
|
2024-12-13 19:03:14 +08:00
|
|
|
|
content = t('渠道') + `:${useChannelStr}`;
|
2024-11-05 20:44:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return isAdminUser ? <div>{content}</div> : <></>;
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{
|
2025-03-08 19:53:07 +08:00
|
|
|
|
key: COLUMN_KEYS.DETAILS,
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('详情'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'content',
|
2025-06-07 02:45:07 +08:00
|
|
|
|
fixed: 'right',
|
2024-03-23 21:24:39 +08:00
|
|
|
|
render: (text, record, index) => {
|
2024-06-26 18:04:49 +08:00
|
|
|
|
let other = getLogOther(record.other);
|
2024-07-15 20:23:19 +08:00
|
|
|
|
if (other == null || record.type !== 2) {
|
2024-05-12 15:35:57 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<Paragraph
|
|
|
|
|
|
ellipsis={{
|
|
|
|
|
|
rows: 2,
|
|
|
|
|
|
showTooltip: {
|
|
|
|
|
|
type: 'popover',
|
|
|
|
|
|
opts: { style: { width: 240 } },
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
|
|
|
|
|
style={{ maxWidth: 240 }}
|
|
|
|
|
|
>
|
|
|
|
|
|
{text}
|
|
|
|
|
|
</Paragraph>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-03-12 21:31:46 +08:00
|
|
|
|
let content = other?.claude
|
|
|
|
|
|
? renderClaudeModelPriceSimple(
|
2025-05-23 13:06:53 +08:00
|
|
|
|
other.model_ratio,
|
|
|
|
|
|
other.model_price,
|
|
|
|
|
|
other.group_ratio,
|
|
|
|
|
|
other.cache_tokens || 0,
|
|
|
|
|
|
other.cache_ratio || 1.0,
|
|
|
|
|
|
other.cache_creation_tokens || 0,
|
|
|
|
|
|
other.cache_creation_ratio || 1.0,
|
|
|
|
|
|
)
|
2025-03-12 21:31:46 +08:00
|
|
|
|
: renderModelPriceSimple(
|
2025-05-23 13:06:53 +08:00
|
|
|
|
other.model_ratio,
|
|
|
|
|
|
other.model_price,
|
|
|
|
|
|
other.group_ratio,
|
|
|
|
|
|
other.cache_tokens || 0,
|
|
|
|
|
|
other.cache_ratio || 1.0,
|
|
|
|
|
|
);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Paragraph
|
|
|
|
|
|
ellipsis={{
|
|
|
|
|
|
rows: 2,
|
|
|
|
|
|
}}
|
|
|
|
|
|
style={{ maxWidth: 240 }}
|
|
|
|
|
|
>
|
|
|
|
|
|
{content}
|
|
|
|
|
|
</Paragraph>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2023-06-24 15:28:11 +08:00
|
|
|
|
|
2025-03-08 19:53:07 +08:00
|
|
|
|
// Update table when column visibility changes
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (Object.keys(visibleColumns).length > 0) {
|
|
|
|
|
|
// Save to localStorage
|
2025-04-04 12:00:38 +08:00
|
|
|
|
localStorage.setItem(
|
|
|
|
|
|
'logs-table-columns',
|
|
|
|
|
|
JSON.stringify(visibleColumns),
|
|
|
|
|
|
);
|
2025-03-08 19:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}, [visibleColumns]);
|
|
|
|
|
|
|
|
|
|
|
|
// Filter columns based on visibility settings
|
|
|
|
|
|
const getVisibleColumns = () => {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
return allColumns.filter((column) => visibleColumns[column.key]);
|
2025-03-08 19:53:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Column selector modal
|
|
|
|
|
|
const renderColumnSelector = () => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
title={t('列设置')}
|
|
|
|
|
|
visible={showColumnSelector}
|
|
|
|
|
|
onCancel={() => setShowColumnSelector(false)}
|
|
|
|
|
|
footer={
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme="light"
|
|
|
|
|
|
onClick={() => initDefaultColumns()}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('重置')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme="light"
|
|
|
|
|
|
onClick={() => setShowColumnSelector(false)}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('取消')}
|
|
|
|
|
|
</Button>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type='primary'
|
|
|
|
|
|
onClick={() => setShowColumnSelector(false)}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('确定')}
|
|
|
|
|
|
</Button>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
</div>
|
2025-03-08 19:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div style={{ marginBottom: 20 }}>
|
|
|
|
|
|
<Checkbox
|
2025-04-04 12:00:38 +08:00
|
|
|
|
checked={Object.values(visibleColumns).every((v) => v === true)}
|
|
|
|
|
|
indeterminate={
|
|
|
|
|
|
Object.values(visibleColumns).some((v) => v === true) &&
|
|
|
|
|
|
!Object.values(visibleColumns).every((v) => v === true)
|
|
|
|
|
|
}
|
|
|
|
|
|
onChange={(e) => handleSelectAll(e.target.checked)}
|
2025-03-08 19:53:07 +08:00
|
|
|
|
>
|
|
|
|
|
|
{t('全选')}
|
|
|
|
|
|
</Checkbox>
|
|
|
|
|
|
</div>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<div
|
2025-05-23 13:06:53 +08:00
|
|
|
|
className="flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4"
|
2025-05-25 01:46:45 +08:00
|
|
|
|
style={{ border: '1px solid var(--semi-color-border)' }}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
>
|
|
|
|
|
|
{allColumns.map((column) => {
|
2025-03-08 19:53:07 +08:00
|
|
|
|
// Skip admin-only columns for non-admin users
|
2025-04-04 12:00:38 +08:00
|
|
|
|
if (
|
|
|
|
|
|
!isAdminUser &&
|
|
|
|
|
|
(column.key === COLUMN_KEYS.CHANNEL ||
|
|
|
|
|
|
column.key === COLUMN_KEYS.USERNAME ||
|
|
|
|
|
|
column.key === COLUMN_KEYS.RETRY)
|
|
|
|
|
|
) {
|
2025-03-08 19:53:07 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2025-03-08 19:53:07 +08:00
|
|
|
|
return (
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<div
|
|
|
|
|
|
key={column.key}
|
2025-05-23 13:06:53 +08:00
|
|
|
|
className="w-1/2 mb-4 pr-2"
|
2025-04-04 12:00:38 +08:00
|
|
|
|
>
|
2025-03-08 19:53:07 +08:00
|
|
|
|
<Checkbox
|
|
|
|
|
|
checked={!!visibleColumns[column.key]}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(e) =>
|
|
|
|
|
|
handleColumnVisibilityChange(column.key, e.target.checked)
|
|
|
|
|
|
}
|
2025-03-08 19:53:07 +08:00
|
|
|
|
>
|
|
|
|
|
|
{column.title}
|
|
|
|
|
|
</Checkbox>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const [logs, setLogs] = useState([]);
|
2024-10-04 16:08:18 +08:00
|
|
|
|
const [expandData, setExpandData] = useState({});
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const [showStat, setShowStat] = useState(false);
|
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
const [loadingStat, setLoadingStat] = useState(false);
|
|
|
|
|
|
const [activePage, setActivePage] = useState(1);
|
|
|
|
|
|
const [logCount, setLogCount] = useState(ITEMS_PER_PAGE);
|
|
|
|
|
|
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
|
|
|
|
|
|
const [logType, setLogType] = useState(0);
|
|
|
|
|
|
const isAdminUser = isAdmin();
|
|
|
|
|
|
let now = new Date();
|
2024-08-01 17:36:26 +08:00
|
|
|
|
// 初始化start_timestamp为今天0点
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const [inputs, setInputs] = useState({
|
|
|
|
|
|
username: '',
|
|
|
|
|
|
token_name: '',
|
|
|
|
|
|
model_name: '',
|
2024-08-01 17:36:26 +08:00
|
|
|
|
start_timestamp: timestamp2string(getTodayStartTimestamp()),
|
2024-03-15 16:05:33 +08:00
|
|
|
|
end_timestamp: timestamp2string(now.getTime() / 1000 + 3600),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
channel: '',
|
2024-12-24 14:48:11 +08:00
|
|
|
|
group: '',
|
2024-03-15 16:05:33 +08:00
|
|
|
|
});
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const {
|
|
|
|
|
|
username,
|
|
|
|
|
|
token_name,
|
|
|
|
|
|
model_name,
|
|
|
|
|
|
start_timestamp,
|
|
|
|
|
|
end_timestamp,
|
|
|
|
|
|
channel,
|
2024-12-24 14:48:11 +08:00
|
|
|
|
group,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} = inputs;
|
2023-06-24 15:28:11 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const [stat, setStat] = useState({
|
2024-03-23 21:24:39 +08:00
|
|
|
|
quota: 0,
|
|
|
|
|
|
token: 0,
|
2024-03-15 16:05:33 +08:00
|
|
|
|
});
|
2023-06-24 15:28:11 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const handleInputChange = (value, name) => {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-06-24 15:28:11 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const getLogSelfStat = async () => {
|
2024-12-24 22:30:05 +08:00
|
|
|
|
let localStartTimestamp = Date.parse(start_timestamp) / 1000;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let localEndTimestamp = Date.parse(end_timestamp) / 1000;
|
2024-12-24 14:48:11 +08:00
|
|
|
|
let url = `/api/log/self/stat?type=${logType}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&group=${group}`;
|
2024-08-01 18:14:10 +08:00
|
|
|
|
url = encodeURI(url);
|
2024-08-11 11:25:32 +08:00
|
|
|
|
let res = await API.get(url);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
setStat(data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-06-10 16:04:04 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const getLogStat = async () => {
|
|
|
|
|
|
let localStartTimestamp = Date.parse(start_timestamp) / 1000;
|
|
|
|
|
|
let localEndTimestamp = Date.parse(end_timestamp) / 1000;
|
2024-12-24 14:48:11 +08:00
|
|
|
|
let url = `/api/log/stat?type=${logType}&username=${username}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&channel=${channel}&group=${group}`;
|
2024-08-01 18:14:10 +08:00
|
|
|
|
url = encodeURI(url);
|
2024-08-11 11:25:32 +08:00
|
|
|
|
let res = await API.get(url);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
setStat(data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-08-19 17:08:50 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const handleEyeClick = async () => {
|
2024-08-01 16:13:08 +08:00
|
|
|
|
if (loadingStat) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setLoadingStat(true);
|
|
|
|
|
|
if (isAdminUser) {
|
|
|
|
|
|
await getLogStat();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await getLogSelfStat();
|
|
|
|
|
|
}
|
|
|
|
|
|
setShowStat(true);
|
|
|
|
|
|
setLoadingStat(false);
|
|
|
|
|
|
};
|
2023-10-31 00:03:22 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const showUserInfo = async (userId) => {
|
|
|
|
|
|
if (!isAdminUser) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const res = await API.get(`/api/user/${userId}`);
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
Modal.info({
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('用户信息'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
content: (
|
|
|
|
|
|
<div style={{ padding: 12 }}>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<p>
|
|
|
|
|
|
{t('用户名')}: {data.username}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
{t('余额')}: {renderQuota(data.quota)}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
{t('已用额度')}:{renderQuota(data.used_quota)}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
{t('请求次数')}:{renderNumber(data.request_count)}
|
|
|
|
|
|
</p>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
),
|
|
|
|
|
|
centered: true,
|
2024-03-15 16:05:33 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-11-08 01:14:12 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const setLogsFormat = (logs) => {
|
2024-10-04 16:08:18 +08:00
|
|
|
|
let expandDatesLocal = {};
|
2024-03-15 16:05:33 +08:00
|
|
|
|
for (let i = 0; i < logs.length; i++) {
|
|
|
|
|
|
logs[i].timestamp2string = timestamp2string(logs[i].created_at);
|
2024-12-28 15:34:28 +08:00
|
|
|
|
logs[i].key = logs[i].id;
|
2024-10-04 16:08:18 +08:00
|
|
|
|
let other = getLogOther(logs[i].other);
|
|
|
|
|
|
let expandDataLocal = [];
|
|
|
|
|
|
if (isAdmin()) {
|
2024-11-05 20:44:22 +08:00
|
|
|
|
// let content = '渠道:' + logs[i].channel;
|
|
|
|
|
|
// if (other.admin_info !== undefined) {
|
|
|
|
|
|
// if (
|
|
|
|
|
|
// other.admin_info.use_channel !== null &&
|
|
|
|
|
|
// other.admin_info.use_channel !== undefined &&
|
|
|
|
|
|
// other.admin_info.use_channel !== ''
|
|
|
|
|
|
// ) {
|
|
|
|
|
|
// // channel id array
|
|
|
|
|
|
// let useChannel = other.admin_info.use_channel;
|
|
|
|
|
|
// let useChannelStr = useChannel.join('->');
|
|
|
|
|
|
// content = `渠道:${useChannelStr}`;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// expandDataLocal.push({
|
|
|
|
|
|
// key: '渠道重试',
|
|
|
|
|
|
// value: content,
|
|
|
|
|
|
// })
|
2025-04-04 12:00:38 +08:00
|
|
|
|
}
|
2025-01-09 15:20:12 +08:00
|
|
|
|
if (isAdminUser && (logs[i].type === 0 || logs[i].type === 2)) {
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('渠道信息'),
|
2025-04-04 12:00:38 +08:00
|
|
|
|
value: `${logs[i].channel} - ${logs[i].channel_name || '[未知]'}`,
|
2025-01-09 15:20:12 +08:00
|
|
|
|
});
|
2024-10-04 16:08:18 +08:00
|
|
|
|
}
|
2024-11-07 16:12:09 +08:00
|
|
|
|
if (other?.ws || other?.audio) {
|
2024-10-04 16:08:18 +08:00
|
|
|
|
expandDataLocal.push({
|
2024-12-13 19:03:14 +08:00
|
|
|
|
key: t('语音输入'),
|
2024-10-04 16:08:18 +08:00
|
|
|
|
value: other.audio_input,
|
|
|
|
|
|
});
|
|
|
|
|
|
expandDataLocal.push({
|
2024-12-13 19:03:14 +08:00
|
|
|
|
key: t('语音输出'),
|
2024-10-04 16:08:18 +08:00
|
|
|
|
value: other.audio_output,
|
|
|
|
|
|
});
|
|
|
|
|
|
expandDataLocal.push({
|
2024-12-13 19:03:14 +08:00
|
|
|
|
key: t('文字输入'),
|
2024-10-04 16:08:18 +08:00
|
|
|
|
value: other.text_input,
|
|
|
|
|
|
});
|
|
|
|
|
|
expandDataLocal.push({
|
2024-12-13 19:03:14 +08:00
|
|
|
|
key: t('文字输出'),
|
2024-10-04 16:08:18 +08:00
|
|
|
|
value: other.text_output,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-03-08 02:44:09 +08:00
|
|
|
|
if (other?.cache_tokens > 0) {
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('缓存 Tokens'),
|
|
|
|
|
|
value: other.cache_tokens,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-03-12 21:31:46 +08:00
|
|
|
|
if (other?.cache_creation_tokens > 0) {
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('缓存创建 Tokens'),
|
|
|
|
|
|
value: other.cache_creation_tokens,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (logs[i].type === 2) {
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('日志详情'),
|
|
|
|
|
|
value: other?.claude
|
|
|
|
|
|
? renderClaudeLogContent(
|
2025-05-23 13:06:53 +08:00
|
|
|
|
other?.model_ratio,
|
|
|
|
|
|
other.completion_ratio,
|
|
|
|
|
|
other.model_price,
|
|
|
|
|
|
other.group_ratio,
|
|
|
|
|
|
other.cache_ratio || 1.0,
|
|
|
|
|
|
other.cache_creation_ratio || 1.0,
|
|
|
|
|
|
)
|
2025-03-12 21:31:46 +08:00
|
|
|
|
: renderLogContent(
|
2025-05-23 13:06:53 +08:00
|
|
|
|
other?.model_ratio,
|
|
|
|
|
|
other.completion_ratio,
|
|
|
|
|
|
other.model_price,
|
|
|
|
|
|
other.group_ratio,
|
|
|
|
|
|
other?.user_group_ratio,
|
|
|
|
|
|
false,
|
|
|
|
|
|
1.0,
|
|
|
|
|
|
undefined,
|
|
|
|
|
|
other.web_search || false,
|
|
|
|
|
|
other.web_search_call_count || 0,
|
|
|
|
|
|
other.file_search || false,
|
|
|
|
|
|
other.file_search_call_count || 0,
|
|
|
|
|
|
),
|
2025-03-12 21:31:46 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-11-05 20:44:22 +08:00
|
|
|
|
if (logs[i].type === 2) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
let modelMapped =
|
|
|
|
|
|
other?.is_model_mapped &&
|
|
|
|
|
|
other?.upstream_model_name &&
|
|
|
|
|
|
other?.upstream_model_name !== '';
|
2025-02-20 16:41:46 +08:00
|
|
|
|
if (modelMapped) {
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('请求并计费模型'),
|
|
|
|
|
|
value: logs[i].model_name,
|
|
|
|
|
|
});
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('实际模型'),
|
|
|
|
|
|
value: other.upstream_model_name,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-11-07 16:12:09 +08:00
|
|
|
|
let content = '';
|
|
|
|
|
|
if (other?.ws || other?.audio) {
|
|
|
|
|
|
content = renderAudioModelPrice(
|
2025-03-09 21:23:33 +08:00
|
|
|
|
other?.text_input,
|
|
|
|
|
|
other?.text_output,
|
|
|
|
|
|
other?.model_ratio,
|
|
|
|
|
|
other?.model_price,
|
|
|
|
|
|
other?.completion_ratio,
|
|
|
|
|
|
other?.audio_input,
|
|
|
|
|
|
other?.audio_output,
|
2024-11-07 16:12:09 +08:00
|
|
|
|
other?.audio_ratio,
|
|
|
|
|
|
other?.audio_completion_ratio,
|
2025-03-09 21:23:33 +08:00
|
|
|
|
other?.group_ratio,
|
|
|
|
|
|
other?.cache_tokens || 0,
|
|
|
|
|
|
other?.cache_ratio || 1.0,
|
2024-11-07 16:12:09 +08:00
|
|
|
|
);
|
2025-03-12 21:31:46 +08:00
|
|
|
|
} else if (other?.claude) {
|
|
|
|
|
|
content = renderClaudeModelPrice(
|
|
|
|
|
|
logs[i].prompt_tokens,
|
|
|
|
|
|
logs[i].completion_tokens,
|
|
|
|
|
|
other.model_ratio,
|
|
|
|
|
|
other.model_price,
|
|
|
|
|
|
other.completion_ratio,
|
|
|
|
|
|
other.group_ratio,
|
|
|
|
|
|
other.cache_tokens || 0,
|
|
|
|
|
|
other.cache_ratio || 1.0,
|
|
|
|
|
|
other.cache_creation_tokens || 0,
|
|
|
|
|
|
other.cache_creation_ratio || 1.0,
|
|
|
|
|
|
);
|
2024-11-07 16:12:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
content = renderModelPrice(
|
2024-11-05 20:44:22 +08:00
|
|
|
|
logs[i].prompt_tokens,
|
|
|
|
|
|
logs[i].completion_tokens,
|
2025-03-09 21:23:33 +08:00
|
|
|
|
other?.model_ratio,
|
|
|
|
|
|
other?.model_price,
|
|
|
|
|
|
other?.completion_ratio,
|
2025-03-09 21:24:19 +08:00
|
|
|
|
other?.group_ratio,
|
2025-03-09 21:23:33 +08:00
|
|
|
|
other?.cache_tokens || 0,
|
|
|
|
|
|
other?.cache_ratio || 1.0,
|
2025-04-28 11:06:32 +08:00
|
|
|
|
other?.image || false,
|
|
|
|
|
|
other?.image_ratio || 0,
|
|
|
|
|
|
other?.image_output || 0,
|
2025-05-07 01:08:20 +08:00
|
|
|
|
other?.web_search || false,
|
|
|
|
|
|
other?.web_search_call_count || 0,
|
|
|
|
|
|
other?.web_search_price || 0,
|
|
|
|
|
|
other?.file_search || false,
|
|
|
|
|
|
other?.file_search_call_count || 0,
|
|
|
|
|
|
other?.file_search_price || 0,
|
2024-11-07 16:12:09 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-11-05 20:44:22 +08:00
|
|
|
|
expandDataLocal.push({
|
2024-12-13 19:03:14 +08:00
|
|
|
|
key: t('计费过程'),
|
2024-11-05 20:44:22 +08:00
|
|
|
|
value: content,
|
|
|
|
|
|
});
|
2025-02-03 14:44:40 +08:00
|
|
|
|
if (other?.reasoning_effort) {
|
|
|
|
|
|
expandDataLocal.push({
|
|
|
|
|
|
key: t('Reasoning Effort'),
|
|
|
|
|
|
value: other.reasoning_effort,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-01-09 15:20:12 +08:00
|
|
|
|
}
|
2024-10-04 16:08:18 +08:00
|
|
|
|
expandDatesLocal[logs[i].key] = expandDataLocal;
|
2023-06-10 16:04:04 +08:00
|
|
|
|
}
|
2024-10-14 15:40:49 +08:00
|
|
|
|
|
2024-10-04 16:08:18 +08:00
|
|
|
|
setExpandData(expandDatesLocal);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setLogs(logs);
|
|
|
|
|
|
};
|
2023-06-10 16:04:04 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const loadLogs = async (startIdx, pageSize, logType = 0) => {
|
|
|
|
|
|
setLoading(true);
|
2023-06-10 16:04:04 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let url = '';
|
|
|
|
|
|
let localStartTimestamp = Date.parse(start_timestamp) / 1000;
|
|
|
|
|
|
let localEndTimestamp = Date.parse(end_timestamp) / 1000;
|
|
|
|
|
|
if (isAdminUser) {
|
2024-12-24 14:48:11 +08:00
|
|
|
|
url = `/api/log/?p=${startIdx}&page_size=${pageSize}&type=${logType}&username=${username}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&channel=${channel}&group=${group}`;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
2024-12-24 14:48:11 +08:00
|
|
|
|
url = `/api/log/self/?p=${startIdx}&page_size=${pageSize}&type=${logType}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&group=${group}`;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
2024-08-01 18:06:25 +08:00
|
|
|
|
url = encodeURI(url);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const res = await API.get(url);
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
2024-08-11 11:25:32 +08:00
|
|
|
|
const newPageData = data.items;
|
|
|
|
|
|
setActivePage(data.page);
|
|
|
|
|
|
setPageSize(data.page_size);
|
|
|
|
|
|
setLogCount(data.total);
|
|
|
|
|
|
|
|
|
|
|
|
setLogsFormat(newPageData);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
};
|
2023-06-10 16:04:04 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const handlePageChange = (page) => {
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setActivePage(page);
|
2025-05-23 13:06:53 +08:00
|
|
|
|
loadLogs(page, pageSize, logType).then((r) => { });
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-06-10 16:04:04 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const handlePageSizeChange = async (size) => {
|
|
|
|
|
|
localStorage.setItem('page-size', size + '');
|
|
|
|
|
|
setPageSize(size);
|
|
|
|
|
|
setActivePage(1);
|
2024-08-11 11:25:32 +08:00
|
|
|
|
loadLogs(activePage, size)
|
2024-03-15 16:05:33 +08:00
|
|
|
|
.then()
|
|
|
|
|
|
.catch((reason) => {
|
|
|
|
|
|
showError(reason);
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2024-03-15 15:07:14 +08:00
|
|
|
|
|
2024-04-03 23:57:49 +08:00
|
|
|
|
const refresh = async () => {
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setActivePage(1);
|
2024-08-01 17:39:18 +08:00
|
|
|
|
handleEyeClick();
|
2024-08-11 11:25:32 +08:00
|
|
|
|
await loadLogs(activePage, pageSize, logType);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-06-10 16:04:04 +08:00
|
|
|
|
|
2024-12-28 15:34:28 +08:00
|
|
|
|
const copyText = async (e, text) => {
|
|
|
|
|
|
e.stopPropagation();
|
2024-03-15 16:05:33 +08:00
|
|
|
|
if (await copy(text)) {
|
|
|
|
|
|
showSuccess('已复制:' + text);
|
|
|
|
|
|
} else {
|
2024-12-28 15:34:28 +08:00
|
|
|
|
Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
|
2023-11-09 17:08:32 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
useEffect(() => {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const localPageSize =
|
|
|
|
|
|
parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setPageSize(localPageSize);
|
2024-08-11 11:25:32 +08:00
|
|
|
|
loadLogs(activePage, localPageSize)
|
2024-03-15 16:05:33 +08:00
|
|
|
|
.then()
|
|
|
|
|
|
.catch((reason) => {
|
|
|
|
|
|
showError(reason);
|
|
|
|
|
|
});
|
2024-08-01 16:13:08 +08:00
|
|
|
|
handleEyeClick();
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}, []);
|
2024-03-15 15:07:14 +08:00
|
|
|
|
|
2024-10-04 16:08:18 +08:00
|
|
|
|
const expandRowRender = (record, index) => {
|
2024-10-14 15:40:49 +08:00
|
|
|
|
return <Descriptions data={expandData[record.key]} />;
|
2024-10-04 16:08:18 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-06-07 03:09:44 +08:00
|
|
|
|
// 检查是否有任何记录有展开内容
|
|
|
|
|
|
const hasExpandableRows = () => {
|
|
|
|
|
|
return logs.some(log => expandData[log.key] && expandData[log.key].length > 0);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
2025-03-08 19:53:07 +08:00
|
|
|
|
{renderColumnSelector()}
|
2025-05-23 13:06:53 +08:00
|
|
|
|
<Card
|
2025-06-07 02:45:07 +08:00
|
|
|
|
className="!rounded-2xl mb-4"
|
2025-05-23 13:06:53 +08:00
|
|
|
|
title={
|
|
|
|
|
|
<div className="flex flex-col w-full">
|
2025-05-26 00:07:14 +08:00
|
|
|
|
<Spin spinning={loadingStat}>
|
2025-05-26 00:45:31 +08:00
|
|
|
|
<Space>
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color='blue'
|
|
|
|
|
|
size='large'
|
|
|
|
|
|
style={{
|
|
|
|
|
|
padding: 15,
|
2025-05-26 23:30:26 +08:00
|
|
|
|
borderRadius: '9999px',
|
2025-05-26 00:45:31 +08:00
|
|
|
|
fontWeight: 500,
|
|
|
|
|
|
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.1)',
|
|
|
|
|
|
}}
|
2025-05-26 00:07:14 +08:00
|
|
|
|
>
|
2025-05-26 00:45:31 +08:00
|
|
|
|
{t('消耗额度')}: {renderQuota(stat.quota)}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color='pink'
|
|
|
|
|
|
size='large'
|
|
|
|
|
|
style={{
|
|
|
|
|
|
padding: 15,
|
2025-05-26 23:30:26 +08:00
|
|
|
|
borderRadius: '9999px',
|
2025-05-26 00:45:31 +08:00
|
|
|
|
fontWeight: 500,
|
|
|
|
|
|
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.1)',
|
|
|
|
|
|
}}
|
2025-05-26 00:07:14 +08:00
|
|
|
|
>
|
2025-05-26 00:45:31 +08:00
|
|
|
|
RPM: {stat.rpm}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color='white'
|
|
|
|
|
|
size='large'
|
|
|
|
|
|
style={{
|
|
|
|
|
|
padding: 15,
|
|
|
|
|
|
border: 'none',
|
|
|
|
|
|
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.1)',
|
2025-05-26 23:30:26 +08:00
|
|
|
|
borderRadius: '9999px',
|
2025-05-26 00:45:31 +08:00
|
|
|
|
fontWeight: 500,
|
|
|
|
|
|
}}
|
2025-05-26 00:07:14 +08:00
|
|
|
|
>
|
2025-05-26 00:45:31 +08:00
|
|
|
|
TPM: {stat.tpm}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
</Space>
|
2025-05-26 00:07:14 +08:00
|
|
|
|
</Spin>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
|
|
|
|
|
|
<Divider margin="12px" />
|
|
|
|
|
|
|
|
|
|
|
|
{/* 搜索表单区域 */}
|
|
|
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
|
|
|
|
|
{/* 时间选择器 */}
|
|
|
|
|
|
<div className="col-span-1 lg:col-span-2">
|
|
|
|
|
|
<DatePicker
|
|
|
|
|
|
className="w-full"
|
|
|
|
|
|
value={[start_timestamp, end_timestamp]}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
type='dateTimeRange'
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
if (Array.isArray(value) && value.length === 2) {
|
|
|
|
|
|
handleInputChange(value[0], 'start_timestamp');
|
|
|
|
|
|
handleInputChange(value[1], 'end_timestamp');
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 日志类型选择器 */}
|
|
|
|
|
|
<Select
|
|
|
|
|
|
value={logType.toString()}
|
|
|
|
|
|
placeholder={t('日志类型')}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
setLogType(parseInt(value));
|
|
|
|
|
|
loadLogs(0, pageSize, parseInt(value));
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Select.Option value='0'>{t('全部')}</Select.Option>
|
|
|
|
|
|
<Select.Option value='1'>{t('充值')}</Select.Option>
|
|
|
|
|
|
<Select.Option value='2'>{t('消费')}</Select.Option>
|
|
|
|
|
|
<Select.Option value='3'>{t('管理')}</Select.Option>
|
|
|
|
|
|
<Select.Option value='4'>{t('系统')}</Select.Option>
|
|
|
|
|
|
<Select.Option value='5'>{t('错误')}</Select.Option>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 其他搜索字段 */}
|
|
|
|
|
|
<Input
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('令牌名称')}
|
|
|
|
|
|
value={token_name}
|
|
|
|
|
|
onChange={(value) => handleInputChange(value, 'token_name')}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
showClear
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('模型名称')}
|
|
|
|
|
|
value={model_name}
|
|
|
|
|
|
onChange={(value) => handleInputChange(value, 'model_name')}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
showClear
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('分组')}
|
|
|
|
|
|
value={group}
|
|
|
|
|
|
onChange={(value) => handleInputChange(value, 'group')}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
showClear
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
{isAdminUser && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('渠道 ID')}
|
|
|
|
|
|
value={channel}
|
|
|
|
|
|
onChange={(value) => handleInputChange(value, 'channel')}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
showClear
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('用户名称')}
|
|
|
|
|
|
value={username}
|
|
|
|
|
|
onChange={(value) => handleInputChange(value, 'username')}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
showClear
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 操作按钮区域 */}
|
|
|
|
|
|
<div className="flex justify-between items-center pt-2">
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type='primary'
|
|
|
|
|
|
onClick={refresh}
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('查询')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='tertiary'
|
|
|
|
|
|
icon={<IconSetting />}
|
|
|
|
|
|
onClick={() => setShowColumnSelector(true)}
|
|
|
|
|
|
className="!rounded-full"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('列设置')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
2025-06-07 00:53:29 +08:00
|
|
|
|
shadows='always'
|
|
|
|
|
|
bordered={false}
|
2025-05-23 13:06:53 +08:00
|
|
|
|
>
|
2025-06-07 02:51:38 +08:00
|
|
|
|
<Table
|
|
|
|
|
|
columns={getVisibleColumns()}
|
2025-06-07 03:09:44 +08:00
|
|
|
|
{...(hasExpandableRows() && {
|
|
|
|
|
|
expandedRowRender: expandRowRender,
|
|
|
|
|
|
expandRowByClick: true
|
|
|
|
|
|
})}
|
2025-06-07 02:51:38 +08:00
|
|
|
|
dataSource={logs}
|
|
|
|
|
|
rowKey='key'
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
scroll={{ x: 'max-content' }}
|
|
|
|
|
|
className="rounded-xl overflow-hidden"
|
|
|
|
|
|
size="middle"
|
|
|
|
|
|
pagination={{
|
|
|
|
|
|
formatPageText: (page) =>
|
|
|
|
|
|
t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
|
|
|
|
|
|
start: page.currentStart,
|
|
|
|
|
|
end: page.currentEnd,
|
|
|
|
|
|
total: logCount,
|
|
|
|
|
|
}),
|
|
|
|
|
|
currentPage: activePage,
|
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
|
total: logCount,
|
|
|
|
|
|
pageSizeOptions: [10, 20, 50, 100],
|
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
|
onPageSizeChange: (size) => {
|
|
|
|
|
|
handlePageSizeChange(size);
|
|
|
|
|
|
},
|
|
|
|
|
|
onPageChange: handlePageChange,
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2025-05-23 13:06:53 +08:00
|
|
|
|
</Card>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</>
|
|
|
|
|
|
);
|
2023-06-10 16:04:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default LogsTable;
|