"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 { createScriptEpisodeNew, getScriptEpisodeListNew, CreateScriptEpisodeRequest } from "@/api/script_episode"; import { EmptyStateAnimation } from '@/components/common/EmptyStateAnimation2'; import { ChatInputBox } from '@/components/common/ChatInputBox'; // ideaText已迁移到ChatInputBox组件中 export 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 renderEpisodeCard = (episode: any) => { return (
router.push(`/create/work-flow?episodeId=${episode.project_id}`)} > {/* 视频缩略图 */}
{episode.final_video_url ? (
{/* 内容区域 */}

{episode.name || episode.title || 'Unnamed episode'}

{/* 元数据 */}
{new Date(episode.created_at).toLocaleDateString()}
{new Date(episode.updated_at).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}
{/* 操作按钮 */}
); }; return ( <>
{/* 优化后的主要内容区域 */}
{isLoading && episodeList.length === 0 ? ( /* 优化的加载状态 */
{[...Array(10)].map((_, index) => (
))}
) : episodeList.length > 0 ? ( /* 优化的剧集网格 */
{episodeList.map(renderEpisodeCard)}
{/* 加载更多指示器 */} {isLoadingMore && (
Loading more episodes...
)} {/* 到底提示 */} {!hasMore && episodeList.length > 0 && (

All episodes loaded

)}
) : ( <> )}
{/* 视频工具组件 - 使用独立组件 */} {episodeList.length === 0 && !isLoading && (
)} ); }