'use client'; import React, { useState, useEffect, useMemo, useRef } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ScriptModal } from '@/components/ui/script-modal'; import { Image, Video, CheckCircle, Music, Loader2, User, Tv, Airplay, Heart, Camera, Film, Scissors } from 'lucide-react'; interface TaskInfoProps { isLoading: boolean; taskObject: any; currentLoadingText: string; dataLoadError?: string | null; roles: any[]; } const stageIconMap = { 0: { icon: Heart, color: '#8b5cf6' }, 1: { icon: Camera, color: '#06b6d4' }, 2: { icon: Film, color: '#10b981' }, 3: { icon: Scissors, color: '#f59e0b' } } const TAG_COLORS = ['#FF5733', '#126821', '#8d3913', '#FF33A1', '#A133FF', '#FF3333', '#3333FF', '#A1A1A1', '#a1115e', '#30527f']; // 阶段图标组件 const StageIcons = ({ currentStage, isExpanded }: { currentStage: number, isExpanded: boolean }) => { // 根据当前阶段重新排序图标 const orderedStages = useMemo(() => { const stages = Object.entries(stageIconMap).map(([stage, data]) => ({ stage: parseInt(stage), ...data })); // 将当前阶段移到第一位 // return stages.sort((a, b) => { // if (a.stage === currentStage) return -1; // if (b.stage === currentStage) return 1; // return a.stage - b.stage; // }); return stages; }, [currentStage]); return ( {orderedStages.map((stage, index) => { const isCurrentStage = stage.stage === currentStage; const Icon = stage.icon; // 只显示当前阶段或展开状态 if (!isExpanded && !isCurrentStage) return null; return ( 0 ? '8px' : '0px', zIndex: isCurrentStage ? 2 : 1 }} > ); })} ); }; export function TaskInfo({ isLoading, taskObject, currentLoadingText, dataLoadError, roles }: TaskInfoProps) { const [isScriptModalOpen, setIsScriptModalOpen] = useState(false); const [currentStage, setCurrentStage] = useState(0); const [isShowScriptIcon, setIsShowScriptIcon] = useState(true); const [isStageIconsExpanded, setIsStageIconsExpanded] = useState(false); const timerRef = useRef(null); const stageColor = useMemo(() => { return stageIconMap[currentStage as keyof typeof stageIconMap].color; }, [currentStage]); // 监听 currentLoadingText useEffect(() => { // 清理之前的定时器 if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; } if (currentLoadingText.includes('Task completed')) { console.log('Closing modal at completion'); setIsScriptModalOpen(false); setIsShowScriptIcon(false); } if (currentLoadingText.includes('Post-production')) { if (isScriptModalOpen) { setIsScriptModalOpen(false); } console.log('isScriptModalOpen-Post-production', currentLoadingText, isScriptModalOpen); setIsScriptModalOpen(true); setCurrentStage(3); } if (currentLoadingText.includes('video')) { console.log('isScriptModalOpen-video', currentLoadingText, isScriptModalOpen); if (isScriptModalOpen) { setIsScriptModalOpen(false); // 延迟8s 再次打开 timerRef.current = setTimeout(() => { setIsScriptModalOpen(true); setCurrentStage(2); }, 8000); } else { setIsScriptModalOpen(true); setCurrentStage(2); } } if (currentLoadingText.includes('video status')) { if (isScriptModalOpen) { setIsScriptModalOpen(false); } setIsScriptModalOpen(true); setCurrentStage(2); } if (currentLoadingText.includes('sketch')) { console.log('isScriptModalOpen-sketch', currentLoadingText, isScriptModalOpen); if (isScriptModalOpen) { setIsScriptModalOpen(false); // 延迟8s 再次打开 timerRef.current = setTimeout(() => { setIsScriptModalOpen(true); setCurrentStage(1); }, 8000); } else { setIsScriptModalOpen(true); setCurrentStage(1); } } if (currentLoadingText.includes('sketch status')) { if (isScriptModalOpen) { setIsScriptModalOpen(false); } setIsScriptModalOpen(true); setCurrentStage(1); } if (currentLoadingText.includes('character')) { console.log('isScriptModalOpen-character', currentLoadingText, isScriptModalOpen); if (isScriptModalOpen) { setIsScriptModalOpen(false); // 延迟8s 再次打开 timerRef.current = setTimeout(() => { setIsScriptModalOpen(true); setCurrentStage(0); }, 8000); } else { setIsScriptModalOpen(true); setCurrentStage(0); } } if (currentLoadingText.includes('initializing')) { console.log('isScriptModalOpen-initializing', currentLoadingText, isScriptModalOpen); setIsScriptModalOpen(true); setCurrentStage(0); } return () => { if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; } } }, [currentLoadingText]); // 使用 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]); return ( <>
{taskObject?.title ? ( <> {taskObject?.title || 'loading project info...'} ) : 'loading project info...'}
{/* 主题 彩色标签tags */}
{taskObject?.tags?.map((tag: string) => (
{tag}
))}
{ console.log('Modal manually closed'); setIsScriptModalOpen(false); }} currentStage={currentStage} roles={roles} /> {currentLoadingText === 'Task completed' ? (
{currentLoadingText}
) : ( setIsScriptModalOpen(true)} > {/* 阶段图标 */} setIsStageIconsExpanded(true)} onMouseLeave={() => setIsStageIconsExpanded(false)} > {/* 背景发光效果 */} {currentLoadingText} {/* 主文字 - 颜色填充动画 */} {currentLoadingText} {/* 动态光点效果 */} {/* 文字底部装饰线 */} )} ); }