"use client"; import { useState, useEffect, useRef } from 'react'; import { Card } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { ArrowLeft, ChevronDown, ChevronUp, Video, ListOrdered, Play, Loader2, Pause, MoreHorizontal, Edit2, Check, X, RefreshCw, Lightbulb, Package, Crown, ArrowUp } from 'lucide-react'; import { useRouter } from 'next/navigation'; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger, SheetClose } from "@/components/ui/sheet"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import './style/create-to-video2.css'; import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable"; import { Skeleton } from "@/components/ui/skeleton"; import LiquidGlass from '@/plugins/liquid-glass/index' import { Dropdown } from 'antd'; import type { MenuProps } from 'antd'; import Image from 'next/image'; import dynamic from 'next/dynamic'; const JoyrideNoSSR = dynamic(() => import('react-joyride'), { ssr: false, }); // 添加自定义滚动条样式 const scrollbarStyles = ` .custom-scrollbar::-webkit-scrollbar { width: 4px; } .custom-scrollbar::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.05); border-radius: 2px; } .custom-scrollbar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; } .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); } `; interface SceneVideo { id: number; video_url: string; script: any; } const ideaText = 'a cute capybara with an orange on its head, staring into the distance and walking forward'; export function CreateToVideo2() { const router = useRouter(); const [isClient, setIsClient] = useState(false); const [isExpanded, setIsExpanded] = useState(false); const [videoUrl, setVideoUrl] = useState(''); const containerRef = useRef(null); const [activeTab, setActiveTab] = useState('script'); const [isFocus, setIsFocus] = useState(false); const [selectedMode, setSelectedMode] = useState('auto'); const [selectedResolution, setSelectedResolution] = useState('720P'); const [inputText, setInputText] = useState(''); const editorRef = useRef(null); const [runTour, setRunTour] = useState(true); const handleUploadVideo = () => { console.log('upload video'); // 打开文件选择器 const input = document.createElement('input'); input.type = 'file'; input.accept = 'video/*'; input.onchange = (e) => { const file = (e.target as HTMLInputElement).files?.[0]; if (file) { setVideoUrl(URL.createObjectURL(file)); } } input.click(); } const handleCreateVideo = async () => { if (videoUrl || inputText) { if (activeTab === 'script') { router.push('/create/work-flow'); } } } // 下拉菜单项配置 const modeItems: MenuProps['items'] = [ { type: 'group', label: (
Mode
), children: [ { key: 'auto', label: (
Auto
Automatically selects the best model for optimal efficiency
), }, { key: 'stable', label: (
Stable
Offers reliable, consistent performance every time
), }, { key: 'inspire', label: (
Inspire
Unleash your creativity with diverse outputs
), }, ], }, ]; // 分辨率选项配置 const resolutionItems: MenuProps['items'] = [ { type: 'group', label: (
Resolution
), children: [ { key: '720P', label: (
720P
), }, { key: '1080P', label: (
1080P
), }, { key: '2K', label: (
2K
), }, { key: '4K', label: (
4K
), }, ], }, ]; // 处理模式选择 const handleModeSelect: MenuProps['onClick'] = ({ key }) => { setSelectedMode(key); }; // 处理分辨率选择 const handleResolutionSelect: MenuProps['onClick'] = ({ key }) => { setSelectedResolution(key as string); }; const handleStartCreating = () => { setActiveTab('script'); setInputText(ideaText); } // 处理编辑器聚焦 const handleEditorFocus = () => { setIsFocus(true); if (editorRef.current && inputText) { // 创建范围对象 const range = document.createRange(); const selection = window.getSelection(); // 获取编辑器内的文本节点 const textNode = Array.from(editorRef.current.childNodes).find( node => node.nodeType === Node.TEXT_NODE ) || editorRef.current.appendChild(document.createTextNode(inputText)); // 设置范围到文本末尾 range.setStart(textNode, inputText.length); range.setEnd(textNode, inputText.length); // 应用选择 selection?.removeAllRanges(); selection?.addRange(range); } }; // 处理编辑器内容变化 const handleEditorChange = (e: React.FormEvent) => { const newText = e.currentTarget.textContent || ''; setInputText(newText); }; // 引导步骤 const steps: Step[] = [ { target: '.video-storyboard-tools', content: 'Welcome to AI Video Creation Tool! This is the main creation area.', placement: 'top', }, { target: '.storyboard-tools-tab', content: 'Choose between Script mode to create videos from text, or Clone mode to recreate existing videos.', placement: 'bottom', }, { target: '.video-prompt-editor', content: 'Describe your video content here. Our AI will generate videos based on your description.', placement: 'top', }, { target: '.tool-operation-button', content: 'Select different creation modes and video resolutions to customize your output.', placement: 'top', }, { target: '.tool-submit-button', content: 'Click here to start creating your video once you are ready!', placement: 'left', }, ]; // 处理引导结束 const handleJoyrideCallback = (data: any) => { const { status } = data; if (status === 'finished' || status === 'skipped') { setRunTour(false); // 可以在这里存储用户已完成引导的状态 localStorage.setItem('hasCompletedTour', 'true'); } }; // 检查是否需要显示引导 useEffect(() => { const hasCompletedTour = localStorage.getItem('hasCompletedTour'); if (hasCompletedTour) { setRunTour(false); } }, []); useEffect(() => { setIsClient(true); }, []); return (
{isClient && ( )}
empty_video
Generated videos will appear here. handleStartCreating()}>Start creating!
{/* 工具栏 */}
{isExpanded ? (
setIsExpanded(false)}> {/* 图标 展开按钮 */} Click to create
) : (
setIsExpanded(true)}> {/* 图标 折叠按钮 */}
)}
setActiveTab('script')}> script
setActiveTab('clone')}> clone
{activeTab === 'clone' && (
{/* 图标 添加视频 */}
Add Video
{videoUrl && (
)}
)} {activeTab === 'script' && (
setIsFocus(false)} onInput={handleEditorChange} suppressContentEditableWarning > {inputText}
Describe the content you want to create. Get an setInputText(ideaText)} > idea
)}
{selectedMode.charAt(0).toUpperCase() + selectedMode.slice(1)}
Create
); }