'use client'; import React, { useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Trash2, RefreshCw } from 'lucide-react'; import { GlassIconButton } from './glass-icon-button'; import { cn } from '@/lib/utils'; interface ScriptTabContentProps { taskSketch: any[]; currentSketchIndex: number; onSketchSelect: (index: number) => void; } export function ScriptTabContent({ taskSketch = [], currentSketchIndex = 0, onSketchSelect }: ScriptTabContentProps) { const thumbnailsRef = useRef(null); const scriptsRef = useRef(null); // 确保 taskSketch 是数组 const sketches = Array.isArray(taskSketch) ? taskSketch : []; // 模拟脚本数据 const mockScripts = sketches.map((_, index) => ({ id: `script-${index}`, content: `这是第 ${index + 1} 个分镜的脚本内容,描述了场景中的主要动作和对话。这里可以添加更多细节来丰富场景表现。` })); // 自动滚动到选中项 useEffect(() => { if (thumbnailsRef.current && scriptsRef.current) { const thumbnailContainer = thumbnailsRef.current; const scriptContainer = scriptsRef.current; // 计算缩略图滚动位置 const thumbnailWidth = thumbnailContainer.children[0]?.clientWidth ?? 0; const thumbnailGap = 16; // gap-4 = 16px const thumbnailScrollPosition = (thumbnailWidth + thumbnailGap) * currentSketchIndex; // 计算脚本文字滚动位置 const scriptElement = scriptContainer.children[currentSketchIndex] as HTMLElement; const scriptScrollPosition = scriptElement?.offsetLeft ?? 0; // 平滑滚动到目标位置 thumbnailContainer.scrollTo({ left: thumbnailScrollPosition - thumbnailContainer.clientWidth / 2 + thumbnailWidth / 2, behavior: 'smooth' }); scriptContainer.scrollTo({ left: scriptScrollPosition - scriptContainer.clientWidth / 2 + scriptElement?.clientWidth / 2, behavior: 'smooth' }); } }, [currentSketchIndex]); // 如果没有数据,显示空状态 if (sketches.length === 0) { return (

暂无分镜数据

); } return (
{/* 上部分 */} {/* 分镜缩略图行 */}
{sketches.map((sketch, index) => ( onSketchSelect(index)} whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }} > {`分镜
场景 {index + 1}
))}
{/* 脚本预览行 - 单行滚动 */}
{mockScripts.map((script, index) => { const isActive = currentSketchIndex === index; return ( onSketchSelect(index)} initial={false} animate={{ scale: isActive ? 1.02 : 1, }} >
{script.content} {index < mockScripts.length - 1 && ( | )}
); })}
{/* 渐变遮罩 */}
{/* 下部分 */} {/* 左列:脚本编辑器 */}
{}} layoutId="script-editor" />
{/* 右列:预览和操作 */}
{/* 选中的分镜预览 */} {`分镜 {/* 操作按钮 */}
); }