'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; } // 根据加载文本返回对应的图标 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 }: TaskInfoProps) { const StageIcon = getStageIcon(currentLoadingText); const [isScriptModalOpen, setIsScriptModalOpen] = useState(false); // 使用 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}
))}
setIsScriptModalOpen(false)} /> {currentLoadingText === 'Task completed' ? (
{currentLoadingText}
) : ( {/* 阶段图标 */} {/* 背景发光效果 */} {currentLoadingText} {/* 主文字 - 颜色填充动画 */} {currentLoadingText} {/* 动态光点效果 */} {/* 文字底部装饰线 */} )} ); }