'use client'; import { motion, AnimatePresence } from 'framer-motion'; import { X } from 'lucide-react'; import WorkOffice from '@/components/workflow/work-office/work-office'; import { useState, useEffect, useRef } from 'react'; import { useWorkofficeData } from '@/components/pages/work-flow/use-workoffice-data'; import { useAppSelector } from '@/lib/store/hooks'; import { storyboardData, productionData, editorData } from '@/components/workflow/work-office/mock-data'; interface ScriptModalProps { isOpen: boolean; onClose: () => void; currentStage?: number; roles: any[]; currentLoadingText: string; } const stages = [ { id: 'script', title: 'Scriptwriter', color: '#8b5cf6', duration: 3 * 60 * 1000 // 3分钟 }, { id: 'storyboard', title: 'Storyboard artist', color: '#06b6d4', duration: 4 * 60 * 1000 // 4分钟 }, { id: 'production', title: 'Visual director', color: '#10b981', duration: 5 * 60 * 1000 // 5分钟 }, { id: 'editing', title: 'Editor', color: '#f59e0b', duration: 15 * 60 * 1000 // 15分钟 } ]; export function ScriptModal({ isOpen, onClose, currentStage = 0, roles, currentLoadingText }: ScriptModalProps) { const [isPlaying, setIsPlaying] = useState(true); const [progress, setProgress] = useState(0); const [startTime, setStartTime] = useState(null); const prevStageRef = useRef(currentStage); const [currentContent, setCurrentContent] = useState>({}); // 将 hook 调用移到组件顶层 const { scriptwriterData, thinkingText, thinkingColor, sketchType } = useWorkofficeData(currentStage, isOpen, currentLoadingText); // 根据当前阶段加载对应数据 useEffect(() => { if (!isOpen) return; let data: Record = {}; switch (currentStage) { case 0: data = scriptwriterData; break; case 1: data = storyboardData; break; case 2: data = productionData; break; case 3: data = editorData; break; } console.log('data', data); setCurrentContent(data); }, [currentStage, isOpen, scriptwriterData]); // 每次打开都重置进度条和时间 useEffect(() => { setProgress(0); setIsPlaying(true); setStartTime(Date.now()); }, [isOpen, currentStage]); // 处理进度条和时间更新 useEffect(() => { if (!isPlaying || !isOpen) return; if (startTime === null) { setStartTime(Date.now()); } const currentDuration = stages[currentStage].duration; const updateInterval = 50; // 更新间隔(毫秒) const interval = setInterval(() => { const now = Date.now(); const elapsed = now - (startTime || now); const newProgress = Math.min((elapsed / currentDuration) * 100, 100); setProgress(newProgress); if (newProgress >= 100) { setIsPlaying(false); setStartTime(null); } }, updateInterval); return () => clearInterval(interval); }, [isPlaying, currentStage, startTime, isOpen]); // 计算剩余时间 const getRemainingTime = () => { if (!isPlaying || startTime === null) return '0:00'; const currentDuration = stages[currentStage].duration; const elapsed = Date.now() - startTime; const remaining = Math.max(0, currentDuration - elapsed); const minutes = Math.floor(remaining / 60000); const seconds = Math.floor((remaining % 60000) / 1000); return `${minutes}:${seconds.toString().padStart(2, '0')}`; }; return ( {isOpen && ( <> {/* 背景遮罩 */} {/* 弹窗内容 */} {/* 关闭按钮 */} {/* 进度条和时间显示 */}
{stages[currentStage].title}
Remaining time: {getRemainingTime()} {Math.round(progress)}% completed
{/* 内容区域 */}
)}
); }