From 1cff5d52fdd23b8b93c50bfdb451b7b20ae7f7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E5=BA=94?= Date: Tue, 7 Jul 2026 23:20:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=87=E9=A2=98=E5=BA=93API=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E7=9B=B4=E6=8E=A5=E6=95=B0=E7=BB=84=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=20+=20=E7=B4=A0=E6=9D=90=E4=B8=8A=E4=BC=A0=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E9=97=AA=E9=80=80=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue 2: getTitles() 兼容后端返回直接数组 [...] 和 {items:[...]} 两种格式 Issue 5: beforeUpload 改为同步返回 false(避免 async Promise 不稳定); 上传失败时延迟1.5秒关闭弹窗,让用户能看到错误提示 --- apps/web/src/api/titles.ts | 12 ++++++++---- apps/web/src/pages/assets/AssetLibrary.tsx | 15 +++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/web/src/api/titles.ts b/apps/web/src/api/titles.ts index 68dec6a90..63fd0f2b4 100644 --- a/apps/web/src/api/titles.ts +++ b/apps/web/src/api/titles.ts @@ -68,10 +68,14 @@ export interface CreateTitleRequest { /** 获取当前用户的所有标题 */ export const getTitles = async (): Promise => { - const response = await apiClient.get<{ items: BackendTitleResponse[] }>( - "/titles", - ); - return (response.data.items || []).map(toTitleItem); + const response = await apiClient.get< + { items: BackendTitleResponse[] } | BackendTitleResponse[] + >("/titles"); + // 兼容两种后端返回格式:{ items: [...] } 或直接 [...] + const items = Array.isArray(response.data) + ? response.data + : response.data.items || []; + return items.map(toTitleItem); }; /** 创建标题 */ diff --git a/apps/web/src/pages/assets/AssetLibrary.tsx b/apps/web/src/pages/assets/AssetLibrary.tsx index fa618d8ba..867bc2686 100644 --- a/apps/web/src/pages/assets/AssetLibrary.tsx +++ b/apps/web/src/pages/assets/AssetLibrary.tsx @@ -421,11 +421,11 @@ const AssetLibrary: React.FC = () => { const handleUpload = async (file: File) => { if (file.size > MAX_FILE_SIZE) { message.error(`文件 "${file.name}" 超过 2GB 限制`); - return false; + return; } if (!effectiveLibId) { message.warning("请先选择或创建一个素材库"); - return false; + return; } setUploading(true); @@ -444,12 +444,14 @@ const AssetLibrary: React.FC = () => { queryClient.invalidateQueries({ queryKey: ["asset-libraries"] }); } catch (err: unknown) { const detail = err instanceof Error ? err.message : ""; + console.error("[handleUpload] 上传失败:", err); message.error(`"${file.name}" 上传失败${detail ? `:${detail}` : ""}`); + // 错误时延迟关闭弹窗,让用户能看到错误提示 + await new Promise((r) => setTimeout(r, 1500)); } finally { setUploading(false); setUploadProgress(0); } - return false; }; /* 新建素材库 */ @@ -635,7 +637,12 @@ const AssetLibrary: React.FC = () => {
{/* 上传区域 */} { + // 同步返回 false 阻止 antd 默认上传行为 + // 异步上传由 handleUpload 处理 + handleUpload(file as File); + return false; + }} showUploadList={false} multiple accept="video/*,image/*"