fix(web): harden generated results page
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import React from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { Button, Card, Empty, List, Space, Tag, Typography, message } from 'antd';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { Alert, Button, Card, Empty, List, Space, Spin, Tag, Typography, message } from 'antd';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getGeneratedVideoDownloadUrl, getGeneratedVideos } from '@/api/generation';
|
||||
|
||||
const ProjectResults: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const location = useLocation();
|
||||
const projectId = id || '';
|
||||
const routedWorkspaceId = (location.state as { workspaceId?: string } | null)?.workspaceId || '';
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId && routedWorkspaceId) {
|
||||
sessionStorage.setItem(`project-workspace:${projectId}`, routedWorkspaceId);
|
||||
}
|
||||
}, [projectId, routedWorkspaceId]);
|
||||
|
||||
const videosQuery = useQuery({
|
||||
queryKey: ['generated-videos', projectId],
|
||||
@@ -19,28 +27,50 @@ const ProjectResults: React.FC = () => {
|
||||
try {
|
||||
const url = await getGeneratedVideoDownloadUrl(videoId);
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
} catch {
|
||||
message.error('获取下载地址失败');
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.detail || '获取下载地址失败');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<Card title="项目成片结果">
|
||||
{videosQuery.data?.length ? (
|
||||
{videosQuery.isError && (
|
||||
<Alert style={{ marginBottom: 16 }} type="error" showIcon message="生成结果加载失败" />
|
||||
)}
|
||||
|
||||
{videosQuery.isLoading ? (
|
||||
<Spin tip="加载生成结果..." />
|
||||
) : videosQuery.data?.length ? (
|
||||
<List
|
||||
dataSource={videosQuery.data}
|
||||
renderItem={(item) => (
|
||||
<List.Item
|
||||
actions={[
|
||||
<Button key="download" type="link" onClick={() => handleDownload(item.id)}>
|
||||
下载
|
||||
获取下载地址
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<List.Item.Meta
|
||||
title={<Space><Typography.Text>{item.name}</Typography.Text><Tag>{item.width}x{item.height}</Tag><Tag>{item.duration}s</Tag></Space>}
|
||||
description={item.file_url}
|
||||
title={
|
||||
<Space wrap>
|
||||
<Typography.Text>{item.name}</Typography.Text>
|
||||
<Tag>{item.width}x{item.height}</Tag>
|
||||
<Tag>{item.duration}s</Tag>
|
||||
<Tag>{Math.round(item.file_size / 1024)} KB</Tag>
|
||||
</Space>
|
||||
}
|
||||
description={
|
||||
<Space direction="vertical" size={4}>
|
||||
<Typography.Text copyable ellipsis style={{ maxWidth: 720 }}>
|
||||
{item.file_url}
|
||||
</Typography.Text>
|
||||
<Button type="link" href={item.file_url} target="_blank" rel="noreferrer" style={{ padding: 0 }}>
|
||||
直接查看公开文件
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user