From 1448cd54ab917d215426529b8ac1425ce6fd685a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B1=BC=E5=BC=80=E5=8F=91?= Date: Thu, 21 May 2026 21:32:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8C=B9=E9=85=8D=E7=B4=A0=E6=9D=90?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=90=8E=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VideoGeneration/hooks/useEmptyShotMaterials.ts | 11 ++++++++--- tauri-app/src/pages/VideoGeneration/index.tsx | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tauri-app/src/pages/VideoGeneration/hooks/useEmptyShotMaterials.ts b/tauri-app/src/pages/VideoGeneration/hooks/useEmptyShotMaterials.ts index 11ec907..efa0bbc 100644 --- a/tauri-app/src/pages/VideoGeneration/hooks/useEmptyShotMaterials.ts +++ b/tauri-app/src/pages/VideoGeneration/hooks/useEmptyShotMaterials.ts @@ -10,7 +10,7 @@ export interface UseEmptyShotMaterialsResult { materialMatchMap: Record; userUploadedMaterials: Record; matchMaterials: () => Promise; - matchSingleMaterial: (shotId: string) => Promise; + matchSingleMaterial: (shotId: string) => Promise<{ url: string; duration: number } | null>; switchMaterial: (shotId: string) => Promise<{ url: string; duration: number } | null>; uploadMaterial: (shotId: string) => Promise<{ path: string; duration: number } | null>; setMaterialMatchMap: React.Dispatch< @@ -96,11 +96,14 @@ export function useEmptyShotMaterials( /** * 单个镜头素材匹配 + * @returns 匹配结果或 null */ - const matchSingleMaterial = async (shotId: string) => { + const matchSingleMaterial = async ( + shotId: string + ): Promise<{ url: string; duration: number } | null> => { const shot = shots.find((s) => String(s.id) === shotId); if (!shot || shot.type !== 'empty_shot' || !shot.scene) { - return; + return null; } const assignedMap = computeAssignedIntervals(shots); @@ -116,10 +119,12 @@ export function useEmptyShotMaterials( if (!result) { toast.warning('暂无可用素材'); } + return result; } catch (err) { console.error('[VideoGeneration] 素材匹配失败:', err); toast.error(err instanceof Error ? err.message : '素材匹配失败'); setMaterialMatchMap((prev) => ({ ...prev, [shotId]: null })); + return null; } }; diff --git a/tauri-app/src/pages/VideoGeneration/index.tsx b/tauri-app/src/pages/VideoGeneration/index.tsx index 8e32fdd..98d188e 100644 --- a/tauri-app/src/pages/VideoGeneration/index.tsx +++ b/tauri-app/src/pages/VideoGeneration/index.tsx @@ -322,7 +322,10 @@ export default function VideoGeneration() { // 处理素材匹配(单个镜头触发匹配) const handleMatchMaterial = async (shotId: string) => { - await matchSingleMaterial(shotId); + const result = await matchSingleMaterial(shotId); + if (result && Number(shotId) === activeScene) { + setPreviewVideoUrl(result.url); + } }; const activeShot = shots.find((s) => Number(s.id) === activeScene);