'use client'; import React, { useRef, useEffect, useState } from 'react'; import { motion } from 'framer-motion'; import { Skeleton } from '@/components/ui/skeleton'; import { ProgressiveReveal, presets } from '@/components/ui/progressive-reveal'; interface ThumbnailGridProps { isLoading: boolean; currentStep: string; currentSketchIndex: number; taskSketch: any[]; taskVideos: any[]; isGeneratingSketch: boolean; sketchCount: number; onSketchSelect: (index: number) => void; } const MOCK_SKETCH_COUNT = 8; export function ThumbnailGrid({ isLoading, currentStep, currentSketchIndex, taskSketch, taskVideos, isGeneratingSketch, sketchCount, onSketchSelect }: ThumbnailGridProps) { const thumbnailsRef = useRef(null); const [isDragging, setIsDragging] = useState(false); const [startX, setStartX] = useState(0); const [scrollLeft, setScrollLeft] = useState(0); // 监听当前选中索引变化,自动滚动到对应位置 useEffect(() => { if (thumbnailsRef.current && taskSketch.length > 0) { const container = thumbnailsRef.current; const thumbnailWidth = container.offsetWidth / 4; // 每个缩略图宽度(包含间距) const scrollPosition = currentSketchIndex * thumbnailWidth; container.scrollTo({ left: scrollPosition, behavior: 'smooth' }); } }, [currentSketchIndex, taskSketch.length]); // 处理鼠标/触摸拖动事件 const handleMouseDown = (e: React.MouseEvent) => { setIsDragging(true); setStartX(e.pageX - thumbnailsRef.current!.offsetLeft); setScrollLeft(thumbnailsRef.current!.scrollLeft); }; const handleMouseMove = (e: React.MouseEvent) => { if (!isDragging) return; e.preventDefault(); const x = e.pageX - thumbnailsRef.current!.offsetLeft; const walk = (x - startX) * 2; thumbnailsRef.current!.scrollLeft = scrollLeft - walk; }; const handleMouseUp = (e: React.MouseEvent) => { setIsDragging(false); if (!isDragging) return; const container = thumbnailsRef.current!; const thumbnailWidth = container.offsetWidth / 4; const currentScroll = container.scrollLeft; const nearestIndex = Math.round(currentScroll / thumbnailWidth); // 只有在拖动距离较小时才触发选中 const x = e.pageX - container.offsetLeft; const walk = Math.abs(x - startX); if (walk < 10) { return; // 如果拖动距离太小,保持原有的点击选中逻辑 } onSketchSelect(Math.min(Math.max(0, nearestIndex), taskSketch.length - 1)); }; // 渲染加载状态 if (isLoading) { return ( <> ); } // 最终成片阶段不显示缩略图 if (Number(currentStep) === 6) { return null; } // 渲染生成中的缩略图 const renderGeneratingThumbnail = () => ( {/* 动态渐变背景 */} {/* 动态光效 */}
场景 {sketchCount + 1}
); // 渲染视频阶段的缩略图 const renderVideoThumbnails = () => ( taskSketch.map((sketch, index) => (
!isDragging && onSketchSelect(index)} >
{taskVideos[index] ? (
场景 {index + 1}
)) ); // 渲染分镜草图阶段的缩略图 const renderSketchThumbnails = () => ( <> {taskSketch.map((sketch, index) => (
!isDragging && onSketchSelect(index)} >
{`缩略图
场景 {index + 1}
))} {isGeneratingSketch && sketchCount < MOCK_SKETCH_COUNT && renderGeneratingThumbnail()} ); return (
setIsDragging(false)} > {Number(currentStep) > 2 && Number(currentStep) < 6 ? renderVideoThumbnails() : renderSketchThumbnails() }
); }