feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -18,7 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button } from '@douyinfe/semi-ui';
|
||||
import { Button } from '@/components/ui';
|
||||
import {
|
||||
ListTodo,
|
||||
Clock,
|
||||
@@ -26,23 +26,61 @@ import {
|
||||
Download,
|
||||
XCircle,
|
||||
Loader2,
|
||||
FileDown,
|
||||
} from 'lucide-react';
|
||||
import { exportToCsv, formatTimestampForCsv } from '../../../helpers/exportCsv';
|
||||
|
||||
const TaskLogsActions = ({
|
||||
t,
|
||||
logs = [],
|
||||
isAdminUser,
|
||||
usageRecordMode = false,
|
||||
}) => {
|
||||
const ExportIcon = usageRecordMode ? FileDown : Download;
|
||||
const exportButtonClass = usageRecordMode
|
||||
? 'usage-record-action-button usage-record-action-button-soft'
|
||||
: 'hover:!bg-gray-100 dark:hover:!bg-neutral-800 !transition-all !duration-300';
|
||||
// CSV 导出:仅当前页已加载的数据,避免一次性拉取全量产生巨大请求
|
||||
export const exportTaskLogsPageCsv = (logs, isAdminUser, t) => {
|
||||
if (!logs || logs.length === 0) return;
|
||||
const columns = [
|
||||
{
|
||||
key: 'submit_time',
|
||||
title: t('提交时间'),
|
||||
format: (r) => formatTimestampForCsv(r.submit_time),
|
||||
},
|
||||
{
|
||||
key: 'finish_time',
|
||||
title: t('结束时间'),
|
||||
format: (r) => formatTimestampForCsv(r.finish_time),
|
||||
},
|
||||
{
|
||||
key: 'duration',
|
||||
title: t('耗时(秒)'),
|
||||
format: (r) =>
|
||||
r.submit_time && r.finish_time ? r.finish_time - r.submit_time : '',
|
||||
},
|
||||
...(isAdminUser
|
||||
? [
|
||||
{ key: 'channel_id', title: t('渠道ID') },
|
||||
{ key: 'channel_name', title: t('渠道名称') },
|
||||
]
|
||||
: []),
|
||||
{ key: 'platform', title: t('平台') },
|
||||
{ key: 'action', title: t('类型') },
|
||||
{
|
||||
key: 'model',
|
||||
title: t('模型'),
|
||||
format: (r) =>
|
||||
r.properties?.origin_model_name ||
|
||||
r.properties?.upstream_model_name ||
|
||||
'',
|
||||
},
|
||||
{ key: 'task_id', title: t('任务ID') },
|
||||
{ key: 'status', title: t('状态') },
|
||||
{ key: 'progress', title: t('进度') },
|
||||
{ key: 'quota', title: t('费用'), format: (r) => r.quota || '' },
|
||||
{ key: 'fail_reason', title: t('详情') },
|
||||
];
|
||||
const ts = formatTimestampForCsv(Math.floor(Date.now() / 1000)).replace(
|
||||
/[: ]/g,
|
||||
'-',
|
||||
);
|
||||
exportToCsv(columns, logs, `task-logs-${ts}.csv`);
|
||||
};
|
||||
|
||||
// 计算任务统计
|
||||
const stats = React.useMemo(() => {
|
||||
// 本页任务统计:仅统计当前页已加载数据
|
||||
export const useTaskPageStats = (logs = []) =>
|
||||
React.useMemo(() => {
|
||||
const successCount = logs.filter((log) => log.status === 'SUCCESS').length;
|
||||
const failureCount = logs.filter((log) => log.status === 'FAILURE').length;
|
||||
const pendingCount = logs.filter(
|
||||
@@ -55,54 +93,19 @@ const TaskLogsActions = ({
|
||||
return { successCount, failureCount, pendingCount, total: logs.length };
|
||||
}, [logs]);
|
||||
|
||||
// CSV 导出:仅当前页已加载的数据,避免一次性拉取全量产生巨大请求
|
||||
const handleExportCsv = () => {
|
||||
if (!logs || logs.length === 0) return;
|
||||
const columns = [
|
||||
{
|
||||
key: 'submit_time',
|
||||
title: t('提交时间'),
|
||||
format: (r) => formatTimestampForCsv(r.submit_time),
|
||||
},
|
||||
{
|
||||
key: 'finish_time',
|
||||
title: t('结束时间'),
|
||||
format: (r) => formatTimestampForCsv(r.finish_time),
|
||||
},
|
||||
{
|
||||
key: 'duration',
|
||||
title: t('耗时(秒)'),
|
||||
format: (r) =>
|
||||
r.submit_time && r.finish_time ? r.finish_time - r.submit_time : '',
|
||||
},
|
||||
...(isAdminUser
|
||||
? [
|
||||
{ key: 'channel_id', title: t('渠道ID') },
|
||||
{ key: 'channel_name', title: t('渠道名称') },
|
||||
]
|
||||
: []),
|
||||
{ key: 'platform', title: t('平台') },
|
||||
{ key: 'action', title: t('类型') },
|
||||
{
|
||||
key: 'model',
|
||||
title: t('模型'),
|
||||
format: (r) =>
|
||||
r.properties?.origin_model_name ||
|
||||
r.properties?.upstream_model_name ||
|
||||
'',
|
||||
},
|
||||
{ key: 'task_id', title: t('任务ID') },
|
||||
{ key: 'status', title: t('状态') },
|
||||
{ key: 'progress', title: t('进度') },
|
||||
{ key: 'quota', title: t('费用'), format: (r) => r.quota || '' },
|
||||
{ key: 'fail_reason', title: t('详情') },
|
||||
];
|
||||
const ts = formatTimestampForCsv(Math.floor(Date.now() / 1000)).replace(
|
||||
/[: ]/g,
|
||||
'-',
|
||||
);
|
||||
exportToCsv(columns, logs, `task-logs-${ts}.csv`);
|
||||
};
|
||||
const TaskLogsActions = ({
|
||||
t,
|
||||
logs = [],
|
||||
isAdminUser,
|
||||
usageRecordMode = false,
|
||||
}) => {
|
||||
const exportButtonClass =
|
||||
'hover:!bg-gray-100 dark:hover:!bg-neutral-800 !transition-all !duration-300';
|
||||
|
||||
// 计算任务统计
|
||||
const stats = useTaskPageStats(logs);
|
||||
|
||||
const handleExportCsv = () => exportTaskLogsPageCsv(logs, isAdminUser, t);
|
||||
|
||||
const StatBadge = ({ icon: Icon, label, value, gradient, iconBg }) => (
|
||||
<div className='relative group'>
|
||||
@@ -139,6 +142,26 @@ const TaskLogsActions = ({
|
||||
</div>
|
||||
);
|
||||
|
||||
// 个人端使用记录:原型为三张本页统计卡;导出本页移至“任务记录”表格卡标题栏
|
||||
if (usageRecordMode) {
|
||||
return (
|
||||
<div className='usage-record-task-stats'>
|
||||
<div className='usage-record-task-stat is-success'>
|
||||
<span>{t('本页成功')}</span>
|
||||
<strong>{stats.successCount}</strong>
|
||||
</div>
|
||||
<div className='usage-record-task-stat is-failure'>
|
||||
<span>{t('本页失败')}</span>
|
||||
<strong>{stats.failureCount}</strong>
|
||||
</div>
|
||||
<div className='usage-record-task-stat is-pending'>
|
||||
<span>{t('本页进行中')}</span>
|
||||
<strong>{stats.pendingCount}</strong>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex flex-col lg:flex-row justify-between items-start lg:items-center gap-4 w-full'>
|
||||
{/* 左侧:标题和统计 */}
|
||||
@@ -202,7 +225,7 @@ const TaskLogsActions = ({
|
||||
{/* 导出当前页为 CSV,空列表时禁用避免生成只有表头的无用文件 */}
|
||||
<Button
|
||||
size='small'
|
||||
icon={<ExportIcon className='w-3.5 h-3.5' />}
|
||||
icon={<Download className='w-3.5 h-3.5' />}
|
||||
onClick={handleExportCsv}
|
||||
disabled={!logs || logs.length === 0}
|
||||
className={exportButtonClass}
|
||||
|
||||
Reference in New Issue
Block a user