diff --git a/apps/web/src/api/client.ts b/apps/web/src/api/client.ts index 042e54a64..a6de7f408 100644 --- a/apps/web/src/api/client.ts +++ b/apps/web/src/api/client.ts @@ -54,11 +54,20 @@ apiClient.interceptors.response.use( handled = true; } else { const status = error.response?.status; - if (status && status >= 500) { + if (status === 413) { + message.error('文件过大,请缩小后重试'); + handled = true; + } else if (status === 415) { + message.error('不支持的文件格式'); + handled = true; + } else if (status === 503) { + message.error('服务暂不可用,请稍后再试'); + handled = true; + } else if (status && status >= 500) { message.error('服务器繁忙,请稍后再试'); handled = true; } - // 4xx 且无具体信息时不弹通用提示,由各组件自行处理 + // 其他 4xx 且无具体信息时不弹通用提示,由各组件自行处理 } // 标记已展示过提示,组件 onError 可据此跳过重复 toast diff --git a/apps/web/src/pages/assets/AssetLibrary.tsx b/apps/web/src/pages/assets/AssetLibrary.tsx index e3506f61a..173f620b4 100644 --- a/apps/web/src/pages/assets/AssetLibrary.tsx +++ b/apps/web/src/pages/assets/AssetLibrary.tsx @@ -38,6 +38,7 @@ import { deleteAsset, uploadAsset, } from '@/api/assets'; +import { getOrCreateDefaultProject } from '@/api/projects'; const { Title, Text } = Typography; const { Dragger } = Upload; @@ -71,6 +72,7 @@ const AssetLibrary: React.FC = () => { const [newLibKind, setNewLibKind] = useState<'video' | 'voice' | 'image'>( 'video' ); + const [uploading, setUploading] = useState(false); // 获取素材库列表 const { data: libraries = [], isLoading: libsLoading } = useQuery({ @@ -125,10 +127,19 @@ const AssetLibrary: React.FC = () => { message.warning('请先选择素材库'); return false; } - const formData = new FormData(); - formData.append('file', file); - formData.append('library_id', activeLibrary); - await uploadMutation.mutateAsync(formData); + setUploading(true); + try { + const project = await getOrCreateDefaultProject(); + const formData = new FormData(); + formData.append('file', file); + formData.append('library_id', activeLibrary); + formData.append('project_id', project.id); + await uploadMutation.mutateAsync(formData); + } catch { + // uploadMutation.onError 已处理错误提示 + } finally { + setUploading(false); + } return false; }; @@ -205,12 +216,15 @@ const AssetLibrary: React.FC = () => { beforeUpload={handleUpload} showUploadList={false} multiple + disabled={uploading || uploadMutation.isPending} style={{ marginBottom: 24 }} >
-
+ {uploading ? '正在上传,请稍候...' : '点击或拖拽文件到此区域上传'}
-点击或拖拽文件到此区域上传
支持 {kindLabel[currentLib?.kind || 'video']} 格式文件
diff --git a/apps/web/src/pages/generate/GeneratePage.tsx b/apps/web/src/pages/generate/GeneratePage.tsx index 2002645ae..8f5fc8279 100644 --- a/apps/web/src/pages/generate/GeneratePage.tsx +++ b/apps/web/src/pages/generate/GeneratePage.tsx @@ -326,14 +326,14 @@ const GeneratePage: React.FC = () => { }} > + + )} + ) : (