'use client'; import React, { useState, useEffect, SetStateAction, useRef } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X, Image, Users, Video, Music, Settings, FileText, Undo2, TriangleAlert } from 'lucide-react'; import { cn } from '@/public/lib/utils'; import { ScriptTabContent } from './script-tab-content'; import { SceneTabContent } from './scene-tab-content'; import { ShotTabContent } from './shot-tab-content'; import { SettingsTabContent } from './settings-tab-content'; import { CharacterTabContent } from './character-tab-content'; import { MusicTabContent } from './music-tab-content'; import FloatingGlassPanel from './FloatingGlassPanel'; import { SaveEditUseCase } from '@/app/service/usecase/SaveEditUseCase'; import { TaskObject } from '@/api/DTO/movieEdit'; interface EditModalProps { isOpen: boolean; onClose: () => void; activeEditTab: string; currentSketchIndex: number; roles?: any[]; setIsPauseWorkFlow: (isPauseWorkFlow: boolean) => void; isPauseWorkFlow: boolean; fallbackToStep: any; originalText?: string; taskObject?: TaskObject; } const tabs = [ { id: '0', label: 'Script', icon: FileText }, { id: '1', label: 'Character', icon: Users }, // { id: '2', label: 'Scene', icon: Image }, { id: '3', label: 'Video', icon: Video }, { id: '4', label: 'Music', icon: Music }, // { id: '5', label: '剪辑', icon: Scissors }, // { id: 'settings', label: 'Settings', icon: Settings }, ]; export function EditModal({ isOpen, onClose, activeEditTab, currentSketchIndex, roles = [], setIsPauseWorkFlow, isPauseWorkFlow, fallbackToStep, originalText, taskObject }: EditModalProps) { const [activeTab, setActiveTab] = useState(activeEditTab); const [currentIndex, setCurrentIndex] = useState(currentSketchIndex); const [currentRoleIndex, setCurrentRoleIndex] = useState(0); const [isRemindFallbackOpen, setIsRemindFallbackOpen] = useState(false); const [isRemindResetOpen, setIsRemindResetOpen] = useState(false); const [resetKey, setResetKey] = useState(0); const [remindFallbackText, setRemindFallbackText] = useState('The task will be regenerated and edited. Do you want to continue?'); const scriptTabContentRef = useRef(null); const characterTabContentRef = useRef(null); const shotTabContentRef = useRef(null); // 添加一个状态来标记是否是从切换tab触发的提醒 const [pendingSwitchTabId, setPendingSwitchTabId] = useState(null); const [disabledBtn, setDisabledBtn] = useState(false); const [isRemindCloseOpen, setIsRemindCloseOpen] = useState(false); useEffect(() => { setCurrentIndex(currentSketchIndex); }, [isOpen]); // 当 activeEditTab 改变时更新 activeTab useEffect(() => { setActiveTab(activeEditTab); }, [activeEditTab]); const isTabDisabled = (tabId: string) => { if (tabId === 'settings') return false; // 换成 如果对应标签下 数据存在 就不禁用 if (tabId === '1') return taskObject?.roles.data.length === 0; // if (tabId === '2') return taskScenes.length === 0; if (tabId === '3') return taskObject?.videos.data.length === 0; if (tabId === '4') return false; return false; }; const hanldeChangeSelect = (index: number) => { if (activeTab === '1') { setCurrentRoleIndex(index); } else { setCurrentIndex(index); } } const checkUpdate = (tabId: string) => { if (activeTab === '0') { const scriptTabContent = scriptTabContentRef.current; if (scriptTabContent) { return scriptTabContent.switchBefore(tabId); } } else if (activeTab === '1') { const characterTabContent = characterTabContentRef.current; if (characterTabContent) { return characterTabContent.switchBefore(tabId); } } else if (activeTab === '3') { const shotTabContent = shotTabContentRef.current; if (shotTabContent) { return shotTabContent.switchBefore(tabId); } } return false; } const handleChangeTab = (tabId: string, disabled: boolean) => { if (disabled) return; // 切换前 检查是否更新 const isUpdate = checkUpdate(tabId); if (isUpdate) { return; } setActiveTab(tabId); setCurrentIndex(0); } const handleSave = () => { window.msg.error('No permission!'); return; console.log('handleSave'); // setIsRemindFallbackOpen(true); if (activeTab === '0') { scriptTabContentRef.current.saveOrCloseBefore(); } else if (activeTab === '1') { characterTabContentRef.current.saveOrCloseBefore(); } else if (activeTab === '3') { shotTabContentRef.current.saveOrCloseBefore('apply'); } } const handleApply = () => { console.log('handleApply'); handleConfirmGotoFallback(); } const handleConfirmGotoFallback = () => { window.msg.error('No permission!'); return; setDisabledBtn(true); console.log('handleConfirmGotoFallback'); SaveEditUseCase.saveData(); if (activeTab === '0') { fallbackToStep('script'); // 应用剧本 } else { fallbackToStep('video'); } setIsRemindFallbackOpen(false); // 关闭弹窗 onClose(); setDisabledBtn(false); } const handleCloseRemindFallbackPanel = () => { if (pendingSwitchTabId) { // 如果是从切换tab触发的提醒,关闭后执行tab切换 setActiveTab(pendingSwitchTabId); setCurrentIndex(0); setPendingSwitchTabId(null); // 清除记录 } setIsRemindFallbackOpen(false); } const handleReset = () => { window.msg.error('No permission!'); return; console.log('handleReset'); // 重置当前tab修改的数据 setIsRemindResetOpen(true); } const handleConfirmReset = () => { console.log('handleConfirmReset'); setIsRemindResetOpen(false); setResetKey(resetKey + 1); } const handleClickClose = () => { // TODO 关闭前 检查 当前tab 下是否有更新 如果有更新 则提醒用户 是否确认应用 // 暂时 默认弹出提醒 if (activeTab === '0') { scriptTabContentRef.current.saveOrCloseBefore(); } else if (activeTab === '1') { characterTabContentRef.current.saveOrCloseBefore(); } else if (activeTab === '3') { shotTabContentRef.current.saveOrCloseBefore('close'); } } const handleConfirmApply = () => { console.log('handleConfirmApply'); setIsRemindCloseOpen(false); handleConfirmGotoFallback(); } const handleCloseRemindClosePanel = () => { setIsRemindCloseOpen(false); onClose(); } const renderTabContent = () => { switch (activeTab) { case '0': return ( ); case '1': return ( ); case '2': return ( ); case '3': return ( ); case '4': return ( ); case 'settings': return ( { console.log('Setting changed:', key, value); // TODO: 实现设置更新逻辑 }} /> ); default: return (
{tabs.find(tab => tab.id === activeTab)?.label} Content area
); } }; return ( {isOpen && ( <> {/* 背景遮罩 */} {/* 弹窗内容 */}
{/* 标签栏 */}
{tabs.map((tab) => { const Icon = tab.icon; const disabled = isTabDisabled(tab.id); return ( handleChangeTab(tab.id, disabled)} whileHover={disabled ? undefined : { scale: 1.02 }} whileTap={disabled ? undefined : { scale: 0.98 }} > {tab.label} {activeTab === tab.id && ( )} ); })}
{/* 弹窗操作按钮 */}
{/* 关闭按钮 */}
{/* 内容区域 */}
{renderTabContent()}
{/* 底部操作栏 */}
Reset {handleSave()}} disabled={disabledBtn} > Apply
{/* 提醒用户 点击保存 工作流将回退 并重新执行工作流 */}

{remindFallbackText}

{/* 提醒用户 重置当前tab修改的数据 */}

Are you sure you want to reset the current tab?

{/* 提醒用户 关闭当前弹窗 是否确认应用 */}

If you have modified the content, closing it will lose the modified content. Do you want to apply the modifications?

)}
); }