feat(experience-center): 统一侧栏与页头,优化云端大脑、图片和视频生成界面

This commit is contained in:
zhanjunhao
2026-11-20 21:38:32 +08:00
parent 436195a229
commit ef67244aea
18 changed files with 1045 additions and 678 deletions
@@ -1,5 +1,4 @@
import {
Play as ActionPlay,
Download as ActionDownload,
RefreshCw as ActionRefreshCw,
Trash2 as ActionTrash2,
@@ -7,23 +6,18 @@ import {
ChevronDown as ActionChevronDown,
} from '@/components/common/icons/ActionIcons';
import React, { useState, useId } from 'react';
import { Button as AntButton } from 'antd';
import {
Table,
Button,
Space,
Tag,
Progress,
Tooltip,
Modal,
Badge,
Pagination,
} from '@/components/ui';
import {
ListVideo,
CheckCircle2,
AlertCircle,
Clock,
Loader2,
} from 'lucide-react';
import { ListVideo } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useIsMobile } from '../../../../../hooks/common/useIsMobile';
import {
@@ -47,55 +41,37 @@ const VideoTaskQueue = ({
// 8 列合计 1190px 塞进 ~340px 容器、按钮全带文字,实际完全用不了。
const isCompact = useIsMobile();
const [selectedTasks, setSelectedTasks] = useState([]);
// 前端分页:分页器放在表格滚动区之外(与密钥管理一致),切换每页条数时不再在滚动区内撑出滚动条造成抖动
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const queueId = useId();
const pageCount = Math.max(1, Math.ceil(tasks.length / pageSize));
const currentPage = Math.min(page, pageCount);
const pagedTasks = tasks.slice(
(currentPage - 1) * pageSize,
currentPage * pageSize,
);
// 状态标签映射
const getStatusTag = (status) => {
// 统一转换为小写进行比较
const normalizedStatus = normalizeVideoTaskStatus(status);
// 状态统一为“文字 + 边框”标签,不带图标;居中由列 align 与 .video-queue-status 控制
const statusMap = {
queued: { color: 'blue', text: t('排队中'), icon: <Clock size={12} /> },
in_progress: {
color: 'cyan',
text: t('生成中'),
icon: <Loader2 size={12} className='animate-spin' />,
},
success: {
color: 'green',
text: t('已完成'),
icon: <CheckCircle2 size={12} />,
},
completed: {
color: 'green',
text: t('已完成'),
icon: <CheckCircle2 size={12} />,
},
failure: {
color: 'red',
text: t('失败'),
icon: <AlertCircle size={12} />,
},
failed: {
color: 'red',
text: t('失败'),
icon: <AlertCircle size={12} />,
},
canceled: {
color: 'grey',
text: t('已取消'),
icon: <AlertCircle size={12} />,
},
queued: { color: 'blue', text: t('排队中') },
in_progress: { color: 'cyan', text: t('生成中') },
success: { color: 'green', text: t('已完成') },
completed: { color: 'green', text: t('已完成') },
failure: { color: 'red', text: t('失败') },
failed: { color: 'red', text: t('失败') },
canceled: { color: 'grey', text: t('已取消') },
};
const config = statusMap[normalizedStatus] || {
color: 'grey',
text: status,
};
return (
<Tag
color={config.color}
style={{ display: 'inline-flex', alignItems: 'center', gap: '4px' }}
>
{config.icon}
<Tag color={config.color} className='video-queue-status'>
{config.text}
</Tag>
);
@@ -128,12 +104,9 @@ const VideoTaskQueue = ({
{
title: t('任务ID'),
dataIndex: 'task_id',
width: !isCompact ? 120 : 100,
render: (text) => (
<Tooltip content={text}>
<span style={{ cursor: 'pointer' }}>{text?.substring(0, 8)}...</span>
</Tooltip>
),
width: 200,
// 完整展示任务 ID(纯文本,不截断)
render: (text) => text || '-',
},
{
title: t('模式'),
@@ -166,6 +139,7 @@ const VideoTaskQueue = ({
title: t('状态'),
dataIndex: 'status',
width: !isCompact ? 120 : 100,
align: 'center',
render: (status) => getStatusTag(status),
},
{
@@ -193,51 +167,53 @@ const VideoTaskQueue = ({
{
title: t('操作'),
dataIndex: 'operate',
width: !isCompact ? 220 : 180,
width: 200,
fixed: 'right',
render: (text, record) => {
const normalizedStatus = normalizeVideoTaskStatus(record.status);
return (
<Space>
// 操作列与密钥管理列表一致:文字链接按钮(主色 / 删除为危险色),不带图标与描边
<div className='video-queue-actions'>
{/* 播放和下载按钮:仅根据状态显示,视频URL在点击时才获取 */}
{normalizedStatus === 'success' && (
<>
<Button
<AntButton
type='link'
size='small'
type='tertiary'
icon={<ActionPlay size={14} />}
className='video-queue-link'
onClick={() => onPlay && onPlay(record)}
>
{!isCompact ? t('播放') : ''}
</Button>
<Button
{t('播放')}
</AntButton>
<AntButton
type='link'
size='small'
type='tertiary'
icon={<ActionDownload size={14} />}
className='video-queue-link'
onClick={() => onDownload(record)}
>
{!isCompact ? t('下载') : ''}
</Button>
{t('下载')}
</AntButton>
</>
)}
{/* 再生成按钮 - 对所有已完成或失败的任务显示 */}
{(normalizedStatus === 'success' ||
normalizedStatus === 'failure') &&
canRegenerateVideoTask(record) && (
<Button
<AntButton
type='link'
size='small'
type='primary'
icon={<ActionRefreshCw size={14} />}
className='video-queue-link'
onClick={() => onRegenerate && onRegenerate(record)}
>
{!isCompact ? t('再生成') : ''}
</Button>
{t('再生成')}
</AntButton>
)}
<Button
<AntButton
type='link'
size='small'
type='danger'
icon={<ActionTrash2 size={14} />}
danger
className='video-queue-link'
onClick={() => {
Modal.warning({
title: t('确定删除此任务?'),
@@ -253,9 +229,9 @@ const VideoTaskQueue = ({
});
}}
>
{!isCompact ? t('删除') : ''}
</Button>
</Space>
{t('删除')}
</AntButton>
</div>
);
},
},
@@ -278,112 +254,146 @@ const VideoTaskQueue = ({
};
return (
<section className='video-queue'>
<h2 className='video-queue-heading'>
<button
type='button'
className='video-queue-toggle'
aria-expanded={visible}
aria-controls={queueId}
onClick={() => setVisible(!visible)}
>
<ListVideo size={19} aria-hidden='true' />
<span>{t('任务队列')}</span>
<span className='video-queue-count'>{taskStats.total}</span>
{taskStats.in_progress > 0 && (
<Badge count={taskStats.in_progress} type='danger' />
)}
<ActionChevronDown
size={16}
className='video-queue-chevron'
aria-hidden='true'
/>
</button>
</h2>
<div id={queueId} className='video-queue-content' hidden={!visible}>
<div className='video-queue-toolbar'>
<Space wrap>
<Button
size={!isCompact ? 'default' : 'small'}
icon={<ActionRefreshCw size={14} />}
onClick={onRefresh}
>
{t('刷新')}
</Button>
{selectedTasks.length > 0 && (
<>
<Button
size={!isCompact ? 'default' : 'small'}
icon={<ActionDownload size={14} />}
onClick={handleBatchDownload}
>
{t('批量下载')} ({selectedTasks.length})
</Button>
<Button
size={!isCompact ? 'default' : 'small'}
type='danger'
icon={<ActionTrash2 size={14} />}
onClick={() => {
Modal.warning({
title: t('确定删除选中的任务?'),
content: t('将删除 {{count}} 个任务,删除后将无法恢复', {
count: selectedTasks.length,
}),
icon: (
<ActionAlertCircle
size={24}
style={{ color: '#f59e0b' }}
/>
),
okText: t('确定删除'),
cancelText: t('取消'),
onOk: handleBatchDelete,
centered: true,
okButtonProps: { type: 'danger' },
});
}}
>
{t('批量删除')} ({selectedTasks.length})
</Button>
</>
// 外层 section 在桌面端只占折叠条高度;展开内容由 .video-queue-panel 自底向上浮层覆盖,
// 不挤压上方的参数 / 预览区域(样式见 VideoWorkspace.css)。Esc 收起并把焦点还给切换按钮。
<section
className='video-queue'
data-expanded={visible || undefined}
onKeyDown={(event) => {
if (event.key === 'Escape' && visible) {
event.stopPropagation();
setVisible(false);
event.currentTarget.querySelector('.video-queue-toggle')?.focus();
}
}}
>
<div className='video-queue-panel'>
<h2 className='video-queue-heading'>
<button
type='button'
className='video-queue-toggle'
aria-expanded={visible}
aria-controls={queueId}
onClick={() => setVisible(!visible)}
>
<ListVideo size={19} aria-hidden='true' />
<span>{t('任务队列')}</span>
<span className='video-queue-count'>{taskStats.total}</span>
{taskStats.in_progress > 0 && (
<Badge count={taskStats.in_progress} type='danger' />
)}
</Space>
<ActionChevronDown
size={16}
className='video-queue-chevron'
aria-hidden='true'
/>
</button>
</h2>
<div id={queueId} className='video-queue-content' hidden={!visible}>
<div className='video-queue-toolbar'>
<Space wrap>
<Button
size={!isCompact ? 'default' : 'small'}
icon={<ActionRefreshCw size={14} />}
onClick={onRefresh}
>
{t('刷新')}
</Button>
{selectedTasks.length > 0 && (
<>
<Button
size={!isCompact ? 'default' : 'small'}
icon={<ActionDownload size={14} />}
onClick={handleBatchDownload}
>
{t('批量下载')} ({selectedTasks.length})
</Button>
<Button
size={!isCompact ? 'default' : 'small'}
type='danger'
icon={<ActionTrash2 size={14} />}
onClick={() => {
Modal.warning({
title: t('确定删除选中的任务?'),
content: t(
'将删除 {{count}} 个任务,删除后将无法恢复',
{
count: selectedTasks.length,
},
),
icon: (
<ActionAlertCircle
size={24}
style={{ color: '#f59e0b' }}
/>
),
okText: t('确定删除'),
cancelText: t('取消'),
onOk: handleBatchDelete,
centered: true,
okButtonProps: { type: 'danger' },
});
}}
>
{t('批量删除')} ({selectedTasks.length})
</Button>
</>
)}
</Space>
{/* 统计信息 */}
<Space wrap>
<Tag size={!isCompact ? 'default' : 'small'} color='blue'>
{t('排队')}: {taskStats.queued}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='cyan'>
{t('生成中')}: {taskStats.in_progress}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='green'>
{t('完成')}: {taskStats.completed}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='red'>
{t('失败')}: {taskStats.failed}
</Tag>
</Space>
</div>
{/* 统计信息 */}
<Space wrap>
<Tag size={!isCompact ? 'default' : 'small'} color='blue'>
{t('排队')}: {taskStats.queued}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='cyan'>
{t('生成中')}: {taskStats.in_progress}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='green'>
{t('完成')}: {taskStats.completed}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='red'>
{t('失败')}: {taskStats.failed}
</Tag>
</Space>
</div>
{/* 任务表格 */}
<div className='video-queue-table app-scrollbar'>
<Table
columns={columns}
dataSource={tasks}
rowKey='task_id'
scroll={{ x: 'max-content' }}
pagination={{ pageSize: 10 }}
rowSelection={{
selectedRowKeys: selectedTasks,
onChange: setSelectedTasks,
getCheckboxProps: (record) => ({
disabled: record.status === 'in_progress',
}),
}}
size='small'
empty={t('暂无任务')}
/>
{/* 任务表格 */}
<div className='video-queue-table app-scrollbar'>
<Table
className='video-queue-grid'
columns={columns}
dataSource={pagedTasks}
rowKey='task_id'
tableLayout='fixed'
scroll={{
x: columns.reduce((sum, column) => sum + column.width, 0),
}}
pagination={false}
rowSelection={{
selectedRowKeys: selectedTasks,
onChange: setSelectedTasks,
getCheckboxProps: (record) => ({
disabled: record.status === 'in_progress',
}),
}}
size='middle'
empty={t('暂无任务')}
/>
</div>
{tasks.length > 0 ? (
<Pagination
className='video-queue-pagination'
total={tasks.length}
currentPage={currentPage}
pageSize={pageSize}
onPageChange={setPage}
onPageSizeChange={(size) => {
setPageSize(size);
setPage(1);
}}
/>
) : null}
</div>
</div>
</section>