import React, { useState, useEffect, useMemo } from 'react'; import { motion } from 'framer-motion'; import Scriptwriter from './scriptwriter'; import StoryboardArtist from './storyboard-artist'; import VisualDirector from './visual-director'; import Editor from './editor'; import { storyboardData, productionData, editorData } from './mock-data'; // 思考指示器组件 const ThinkingDots = ({ show, text, color }: { show: boolean; text: string; color: string }) => { if (!show) return null; return (
{[0, 1, 2].map((i) => ( ))}
{text}
); }; interface WorkOfficeProps { initialStage?: number; currentContent: Record; thinkingText: string; thinkingColor: string; sketchType: string; } const WorkOffice: React.FC = ({ initialStage = 0, currentContent, thinkingText, thinkingColor, sketchType }) => { const [currentStage, setCurrentStage] = useState(initialStage); const [isPlaying, setIsPlaying] = useState(false); useEffect(() => { setCurrentStage(initialStage); setIsPlaying(true); }, [initialStage]); // 使用 useMemo 缓存工作台组件 const currentWorkstation = useMemo(() => { console.log('工作台组件重新渲染', currentContent); switch (currentStage) { case 0: return ; case 1: return ; case 2: return ; case 3: return ; default: return null; } }, [currentStage, isPlaying, currentContent]); // 使用 useMemo 缓存 ThinkingDots 组件 const thinkingDots = useMemo(() => ( ), [isPlaying, thinkingText, thinkingColor]); return (
{/* 正在加载的部分 文字显示 */}
{thinkingDots}
{/* 工作台内容区域 */}
{currentWorkstation}
); }; // 使用 React.memo 包装组件 export default React.memo(WorkOffice);