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);