'use client'; import React, { useState, useEffect, useRef, useMemo } from 'react'; import { motion } from 'framer-motion'; import { ScriptModal } from '@/components/ui/script-modal'; import { Image, Video, CheckCircle, Music, Loader2, User, Scissors, Tv, Airplay } from 'lucide-react'; interface TaskInfoProps { isLoading: boolean; taskObject: any; currentLoadingText: string; dataLoadError?: string | null; currentStep: string; sketchCount: number; isGeneratingVideo: boolean; taskVideos: any[]; } // 根据加载文本返回对应的图标 const getStageIcon = (loadingText: string) => { const text = loadingText.toLowerCase(); if (text.includes('sketch') || text.includes('草图')) { return Image; } else if (text.includes('video') || text.includes('视频')) { return Video; } else if (text.includes('character') || text.includes('角色')) { return User; } else if (text.includes('audio') || text.includes('音频')) { return Music; } else if (text.includes('post') || text.includes('后期')) { return Scissors; } else if (text.includes('final') || text.includes('最终')) { return Tv; } else if (text.includes('complete') || text.includes('完成')) { return CheckCircle; } else { return Loader2; } }; const TAG_COLORS = ['#FF5733', '#126821', '#8d3913', '#FF33A1', '#A133FF', '#FF3333', '#3333FF', '#A1A1A1', '#a1115e', '#30527f']; export function TaskInfo({ isLoading, taskObject, currentLoadingText, dataLoadError, currentStep, sketchCount, isGeneratingVideo, taskVideos }: TaskInfoProps) { const StageIcon = getStageIcon(currentLoadingText); const [isScriptModalOpen, setIsScriptModalOpen] = useState(false); const [currentStage, setCurrentStage] = useState(0); const prevSketchCountRef = useRef(sketchCount); const prevIsGeneratingVideoRef = useRef(isGeneratingVideo); const prevTaskVideosLengthRef = useRef(taskVideos?.length || 0); const timerRef = useRef(null); // 清理定时器 useEffect(() => { return () => { if (timerRef.current) { clearTimeout(timerRef.current); } }; }, []); // 监听 currentStep 为 '1' 的情况 useEffect(() => { console.log('Current Step Effect:', { currentStep, hasTitle: !!taskObject?.title }); // 清除之前的定时器 if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; } if (currentStep === '1' && taskObject?.title) { console.log('Setting up timer for script modal...'); timerRef.current = setTimeout(() => { console.log('Opening script modal with stage 0'); setIsScriptModalOpen(true); setCurrentStage(0); }, 5000); } }, [currentStep, taskObject?.title]); // 监听 sketchCount 变化 useEffect(() => { console.log('SketchCount Effect:', { prevCount: prevSketchCountRef.current, currentCount: sketchCount, isModalOpen: isScriptModalOpen }); // 从 0 变为 1 时关闭弹窗 if (prevSketchCountRef.current === 0 && sketchCount === 1) { console.log('Closing modal: sketchCount changed from 0 to 1'); setIsScriptModalOpen(false); } // 从 1 变为其他非 0 值时切换弹窗 else if (prevSketchCountRef.current === 1 && sketchCount !== 0 && sketchCount !== 1) { console.log('Toggling modal: sketchCount changed from 1 to other value'); setIsScriptModalOpen(prev => { const newState = !prev; if (newState) { setCurrentStage(1); } return newState; }); } prevSketchCountRef.current = sketchCount; }, [sketchCount]); // 监听视频生成状态变化 useEffect(() => { const currentTaskVideosLength = taskVideos?.length || 0; console.log('Video Generation Effect:', { prevGenerating: prevIsGeneratingVideoRef.current, currentGenerating: isGeneratingVideo, prevVideosLength: prevTaskVideosLengthRef.current, currentVideosLength: currentTaskVideosLength, isModalOpen: isScriptModalOpen }); if ( (prevIsGeneratingVideoRef.current === false && isGeneratingVideo === true) || prevTaskVideosLengthRef.current !== currentTaskVideosLength ) { console.log('Toggling modal due to video generation changes'); setIsScriptModalOpen(prev => { const newState = !prev; if (newState) { setCurrentStage(2); } return newState; }); } prevIsGeneratingVideoRef.current = isGeneratingVideo; prevTaskVideosLengthRef.current = currentTaskVideosLength; }, [isGeneratingVideo, taskVideos]); // 监听最终步骤 useEffect(() => { console.log('Final Steps Effect:', { currentStep, isModalOpen: isScriptModalOpen }); if (currentStep === '5') { console.log('Opening modal for final review'); setIsScriptModalOpen(true); setCurrentStage(3); } else if (currentStep === '6') { console.log('Closing modal at completion'); setIsScriptModalOpen(false); } }, [currentStep]); // 弹窗状态变化时的日志 useEffect(() => { console.log('Modal State Changed:', { isOpen: isScriptModalOpen, currentStage, currentStep, sketchCount }); }, [isScriptModalOpen, currentStage, currentStep, sketchCount]); // 使用 useMemo 缓存标签颜色映射 const tagColors = useMemo(() => { if (!taskObject?.tags) return {}; return taskObject.tags.reduce((acc: Record, tag: string) => { acc[tag] = TAG_COLORS[Math.floor(Math.random() * TAG_COLORS.length)]; return acc; }, {}); }, [taskObject?.tags]); // 只在 tags 改变时重新计算 // 自动触发打开 剧本 弹窗 延迟5秒 // useEffect(() => { // if (taskObject?.title && currentLoadingText !== 'Task completed') { // setTimeout(() => { // setIsScriptModalOpen(true); // }, 5000); // } // }, [taskObject?.title]); if (isLoading) { return ( <> {taskObject?.title || 'loading project info...'} {/* 加载状态显示 */} {/* 阶段图标 */} {currentLoadingText} {/* 错误提示 */} {dataLoadError && ( {dataLoadError} )} ); } return ( <>
{taskObject?.title ? ( <> {taskObject?.title || 'loading project info...'}
setIsScriptModalOpen(true)} >
) : 'loading project info...'}
{/* 主题 彩色标签tags */}
{taskObject?.tags?.map((tag: string) => (
{tag}
))}
{ console.log('Modal manually closed'); setIsScriptModalOpen(false); }} currentStage={currentStage} /> {currentLoadingText === 'Task completed' ? (
{currentLoadingText}
) : ( {/* 阶段图标 */} {/* 背景发光效果 */} {currentLoadingText} {/* 主文字 - 颜色填充动画 */} {currentLoadingText} {/* 动态光点效果 */} {/* 文字底部装饰线 */} )} ); }