import React, { useState, useEffect } from 'react';
import { Heart, Camera, Film, Scissors } from 'lucide-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 { scriptwriterData, storyboardData, productionData, editorData } from './mock-data';
interface Stage {
id: string;
title: string;
icon: React.ElementType;
color: string;
profession: string;
duration: number; // 加载持续时间(毫秒)
}
const stages: Stage[] = [
{
id: 'script',
title: '编剧工作台',
icon: Heart,
color: '#8b5cf6',
profession: '编剧',
duration: 3 * 60 * 1000 // 3分钟
},
{
id: 'storyboard',
title: '分镜设计台',
icon: Camera,
color: '#06b6d4',
profession: '分镜师',
duration: 8 * 60 * 1000 // 8分钟
},
{
id: 'production',
title: '制作渲染台',
icon: Film,
color: '#10b981',
profession: '视觉导演',
duration: 10 * 60 * 1000 // 10分钟
},
{
id: 'editing',
title: '剪辑调色台',
icon: Scissors,
color: '#f59e0b',
profession: '剪辑师',
duration: 15 * 60 * 1000 // 15分钟
}
];
// 思考指示器组件
const ThinkingDots = ({ show, text, color }: { show: boolean; text: string; color: string }) => {
if (!show) return null;
return (
{[0, 1, 2].map((i) => (
))}
{text}
);
};
const WorkOffice: React.FC = () => {
const [currentStage, setCurrentStage] = useState(0);
const [isPlaying, setIsPlaying] = useState(true);
const [progress, setProgress] = useState(0);
const [currentContent, setCurrentContent] = useState>(scriptwriterData);
const [thinkingText, setThinkingText] = useState(`${stages[0].profession}正在思考...`);
const [startTime, setStartTime] = useState(null);
// 模拟数据加载过程
useEffect(() => {
if (!isPlaying) 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]);
// 根据当前阶段加载对应数据
useEffect(() => {
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;
}
// 重置状态并开始新的加载
setProgress(0);
setIsPlaying(true);
setStartTime(Date.now());
setCurrentContent({});
setThinkingText(`${stages[currentStage].profession}正在思考...`);
// 模拟数据加载延迟
const loadingTimeout = setTimeout(() => {
setCurrentContent(data);
}, 1000);
return () => clearTimeout(loadingTimeout);
}, [currentStage]);
// 渲染当前工作台组件
const renderCurrentWorkstation = () => {
switch (currentStage) {
case 0:
return ;
case 1:
return ;
case 2:
return ;
case 3:
return ;
default:
return null;
}
};
// 计算剩余时间
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 (
{/* 正在加载的部分 文字显示 */}
{/* 工作台内容区域 */}
{renderCurrentWorkstation()}
{/* 底部控制栏 */}
{stages[currentStage].title}
剩余时间: {getRemainingTime()}
{Math.round(progress)}% 完成
{/* 工作台切换按钮组 */}
{stages.map((stage, index) => (
))}
);
};
export default WorkOffice;