Files
monkey-ai-web/src/pages/ExperienceCenter/components/AICreation/VideoGenerationTab.jsx
T
qiubaishen e3b82b981a merge: 合入总仓库 weiyuan(bfdfb339) web/ 新功能,保留 ui-optimization 的 UI 重构
来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2

冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
  OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
2026-11-10 12:01:21 +08:00

313 lines
9.4 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import VideoInputPanel from './Video/VideoInputPanel';
import VideoPreviewPanel from './Video/VideoPreviewPanel';
import VideoTaskQueue from './Video/VideoTaskQueue';
import { useVideoGeneration } from '../../../../hooks/video/useVideoGeneration';
import { showInfo } from '../../../../helpers';
const VideoGenerationTab = () => {
const { t } = useTranslation();
const [leftPanelCollapsed, setLeftPanelCollapsed] = useState(false);
const [taskQueueVisible, setTaskQueueVisible] = useState(false);
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const [selectedTaskForPlay, setSelectedTaskForPlay] = useState(null);
// 输入面板容器:再生成回填后滚动到面板顶部
const inputPanelRef = useRef(null);
const inputScrollRef = useRef(null);
// 监听窗口大小变化
useEffect(() => {
const handleResize = () => {
setWindowWidth(window.innerWidth);
};
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
const creation = useVideoGeneration();
const {
// 表单数据
formData,
// 模型相关
selectedModel,
// 生成相关
generating,
currentTask,
handleGenerate,
handleCancel,
submitBlock,
submitting,
quote,
quoteLoading,
quoteFailed,
estSeconds,
// 任务列表
tasks,
refreshTasks,
deleteTask,
getRegenerationTask,
prefillFromTask,
downloadTask,
getTaskVideoUrl,
} = creation;
// 处理任务列表的播放按钮
const handlePlayTask = async (task) => {
// 获取最新的预签名URL
const videoUrl = await getTaskVideoUrl(task.task_id);
if (videoUrl) {
// 更新 task 对象中的 video_url
const updatedTask = { ...task };
// 解析或初始化 data 对象
let data = {};
if (updatedTask.data) {
try {
data =
typeof updatedTask.data === 'string'
? JSON.parse(updatedTask.data)
: { ...updatedTask.data };
} catch (e) {
console.error('Failed to parse task data:', e);
}
}
// 设置 video_url
data.video_url = videoUrl;
updatedTask.data = data;
setSelectedTaskForPlay(updatedTask);
} else {
setSelectedTaskForPlay(task);
}
};
// 处理关闭视频播放(清除选中的任务)
const handleClearSelectedTask = () => {
setSelectedTaskForPlay(null);
};
// 处理再生成按钮:用原任务参数回填输入面板,由用户确认后再点击生成
const handleRegenerate = async (task) => {
const detail = await getRegenerationTask(task.task_id);
if (!detail || !prefillFromTask(detail)) return;
setLeftPanelCollapsed(false);
setTaskQueueVisible(false);
showInfo(t('已回填原参数,确认后点击生成'));
// 等面板展开渲染后再滚动
requestAnimationFrame(() => {
inputScrollRef.current?.scrollTo?.({ top: 0, behavior: 'smooth' });
inputPanelRef.current?.scrollIntoView?.({
behavior: 'smooth',
block: 'start',
});
});
};
// 响应式布局配置 - 两列布局(左侧配置区 + 右侧预览区)
const getLayoutConfig = () => {
// 超大屏幕 (>1920px): 25% - 75%
if (windowWidth > 1920) {
return {
leftWidth: '25%',
centerWidth: '75%',
minLeftWidth: '350px',
minCenterWidth: '800px',
direction: 'row',
};
}
// 大屏幕 (1600-1920px): 28% - 72%
if (windowWidth > 1600) {
return {
leftWidth: '28%',
centerWidth: '72%',
minLeftWidth: '320px',
minCenterWidth: '700px',
direction: 'row',
};
}
// 中等屏幕 (1280-1600px): 32% - 68%
if (windowWidth > 1280) {
return {
leftWidth: '32%',
centerWidth: '68%',
minLeftWidth: '300px',
minCenterWidth: '600px',
direction: 'row',
};
}
// 小屏幕 (1024-1280px): 35% - 65%
if (windowWidth > 1024) {
return {
leftWidth: '35%',
centerWidth: '65%',
minLeftWidth: '280px',
minCenterWidth: '500px',
direction: 'row',
};
}
// 超小屏幕 (<1024px): 单列布局
return {
leftWidth: '100%',
centerWidth: '100%',
minLeftWidth: '100%',
minCenterWidth: '100%',
direction: 'column',
};
};
const layoutConfig = getLayoutConfig();
return (
<div
style={{
height: '100%',
display: 'flex',
flexDirection: 'column',
position: 'relative',
overflow: 'hidden',
}}
>
<div
style={{
flex: 1,
overflow: layoutConfig.direction === 'row' ? 'hidden' : 'auto',
display: 'flex',
flexDirection: layoutConfig.direction === 'row' ? 'row' : 'column',
gap: layoutConfig.direction === 'column' ? '16px' : '0',
position: 'relative',
paddingBottom: '40px', // 为任务队列触发器留出空间
}}
>
{/* 左侧:输入区域(区域1) */}
<div
ref={inputPanelRef}
style={{
width:
layoutConfig.direction === 'row'
? layoutConfig.leftWidth
: '100%',
minWidth: layoutConfig.minLeftWidth,
height: layoutConfig.direction === 'row' ? '100%' : 'auto',
// 折叠态不能再预留 500px:面板收起后只剩一个 fixed 定位的浮动箭头,
// 这 500px 会变成页面顶部一整块空白
minHeight:
layoutConfig.direction === 'column' && !leftPanelCollapsed
? '500px'
: 'auto',
flexShrink: layoutConfig.direction === 'row' ? 0 : 1,
backgroundColor: 'var(--ui-color-bg-1)',
borderRight:
layoutConfig.direction === 'row'
? '1px solid var(--ui-color-border)'
: 'none',
borderBottom:
layoutConfig.direction === 'column'
? '1px solid var(--ui-color-border)'
: 'none',
display: 'flex',
flexDirection: 'column',
}}
>
<div
ref={inputScrollRef}
className='app-scrollbar'
style={{
height: '100%',
overflow: 'auto',
paddingBottom: layoutConfig.direction === 'row' ? '16px' : '16px',
}}
>
<VideoInputPanel
creation={creation}
onCollapse={() => setLeftPanelCollapsed(!leftPanelCollapsed)}
collapsed={leftPanelCollapsed}
collapsible={layoutConfig.direction === 'row'}
/>
</div>
</div>
{/* 右侧:预览+生成区域 */}
<div
style={{
flex: 1,
height: layoutConfig.direction === 'row' ? '100%' : 'auto',
minHeight: layoutConfig.direction === 'column' ? '600px' : 'auto',
minWidth: 0,
}}
>
<div
className='app-scrollbar'
style={{
height: '100%',
backgroundColor: 'var(--ui-color-bg-0)',
padding: windowWidth > 768 ? '16px' : '12px',
overflow: 'auto',
}}
>
<VideoPreviewPanel
formData={formData}
generating={generating}
currentTask={currentTask}
onGenerate={handleGenerate}
onCancel={handleCancel}
selectedModel={selectedModel}
submitBlock={submitBlock}
submitting={submitting}
quote={quote}
quoteLoading={quoteLoading}
quoteFailed={quoteFailed}
estSeconds={estSeconds}
selectedTaskForPlay={selectedTaskForPlay}
onRegenerate={handleRegenerate}
onClearSelectedTask={handleClearSelectedTask}
/>
</div>
</div>
</div>
{/* 底部:任务队列(区域4) - 使用 absolute 定位,相对于父容器 */}
<div
style={{
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
zIndex: 1000,
}}
>
<VideoTaskQueue
visible={taskQueueVisible}
setVisible={setTaskQueueVisible}
tasks={tasks}
onRefresh={refreshTasks}
onDelete={deleteTask}
onDownload={downloadTask}
onPlay={handlePlayTask}
onRegenerate={handleRegenerate}
/>
</div>
</div>
);
};
export default VideoGenerationTab;