"use client"; import { useState, useEffect, useRef, useCallback } from 'react'; import { ArrowLeft, ListOrdered, Play, Loader2, Pause, MoreHorizontal, Edit2, Check, X, RefreshCw, Calendar, Clock, Eye, Heart, Share2, Video } from 'lucide-react'; import { useRouter, useSearchParams } from 'next/navigation'; import './style/create-to-video2.css'; import { getScriptEpisodeListNew } from "@/api/script_episode"; import { EmptyStateAnimation } from '@/components/common/EmptyStateAnimation2'; import { ChatInputBox } from '@/components/ChatInputBox/ChatInputBox'; import cover_image1 from '@/public/assets/cover_image1.jpg'; import { motion } from 'framer-motion'; // ideaText已迁移到ChatInputBox组件中 export default function CreateToVideo2() { const router = useRouter(); const searchParams = useSearchParams(); const projectId = searchParams.get('projectId') ? parseInt(searchParams.get('projectId')!) : 0; const [isClient, setIsClient] = useState(false); const containerRef = useRef(null); const [runTour, setRunTour] = useState(true); const [episodeId, setEpisodeId] = useState(0); const [generatedVideoList, setGeneratedVideoList] = useState([]); const [projectName, setProjectName] = useState('默认名称'); const [episodeList, setEpisodeList] = useState([]); const [currentPage, setCurrentPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [limit, setLimit] = useState(12); const [isLoading, setIsLoading] = useState(false); const [hasMore, setHasMore] = useState(true); const [isLoadingMore, setIsLoadingMore] = useState(false); const scrollContainerRef = useRef(null); const [userId, setUserId] = useState(0); // 在客户端挂载后读取localStorage useEffect(() => { if (typeof window !== 'undefined') { const currentUser = JSON.parse(localStorage.getItem('currentUser') || '{}'); console.log('currentUser', currentUser); setUserId(currentUser.id); const savedProjectName = localStorage.getItem('projectName'); if (savedProjectName) { setProjectName(savedProjectName); } getEpisodeList(currentUser.id); } }, []); // 获取剧集列表 const getEpisodeList = async (userId: number) => { if (isLoading || isLoadingMore) return; console.log('getEpisodeList', userId); setIsLoading(true); try { const params = { user_id: String(userId), }; const episodeListResponse = await getScriptEpisodeListNew(params); console.log('episodeListResponse', episodeListResponse); if (episodeListResponse.code === 0) { setEpisodeList(episodeListResponse.data.movie_projects); // 每一项 有 // final_video_url: "", // 生成的视频地址 // last_message: "", // name: "After the Flood", // 剧集名称 // project_id: "9c34fcc4-c8d8-44fc-879e-9bd56f608c76", // 剧集ID // status: "INIT", // 剧集状态 INIT 初始化 // step: "INIT" // 剧集步骤 INIT 初始化 } } catch (error) { console.error('Failed to fetch episode list:', error); } finally { setIsLoading(false); setIsLoadingMore(false); } }; // 视频上传和创建功能已迁移到ChatInputBox组件中 // 所有视频工具相关的函数和配置已迁移到ChatInputBox组件中 // 检查是否需要显示引导 useEffect(() => { if (typeof window !== 'undefined') { const hasCompletedTour = localStorage.getItem('hasCompletedTour'); if (hasCompletedTour) { setRunTour(false); } } }, []); useEffect(() => { setIsClient(true); }, []); const StatusBadge = (status: string) => { return ( {/* 进行中 脉冲小圆点 */} {status === 'pending' && ( <> {/* 状态文字 */} )} {/* 失败 */} {status === 'failed' && ( <> FAILED )} ) } // 创建一个视频引用Map const videoRefs = useRef>(new Map()); const handleMouseEnter = (projectId: string) => { const videoElement = videoRefs.current.get(projectId); if (videoElement) { videoElement.play().catch(() => { console.log('Video autoplay prevented'); }); } }; const handleMouseLeave = (projectId: string) => { const videoElement = videoRefs.current.get(projectId); if (videoElement) { videoElement.pause(); videoElement.currentTime = 0; } }; const setVideoRef = (projectId: string, element: HTMLVideoElement | null) => { if (element) { videoRefs.current.set(projectId, element); } else { videoRefs.current.delete(projectId); } }; const renderProjectCard = (project: any) => { return (
router.push(`/create/work-flow?episodeId=${project.project_id}`)} onMouseEnter={() => handleMouseEnter(project.project_id)} onMouseLeave={() => handleMouseLeave(project.project_id)} data-alt="project-card" > {/* 视频/图片区域 */}
{project.final_video_url ? (
); }; return (
{episodeList.length > 0 && ( /* 优化的剧集网格 */
{episodeList.map(renderProjectCard)}
{/* 加载更多指示器 */} {isLoadingMore && (
Loading more projects...
)} {/* 到底提示 */} {!hasMore && episodeList.length > 0 && (

All projects loaded

)}
)}
{/* 视频工具组件 - 使用独立组件 */} {!isLoading && }
); }