Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
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 } from 'react';
|
||||
import VideoInputPanel from './Video/VideoInputPanel';
|
||||
import VideoPreviewPanel from './Video/VideoPreviewPanel';
|
||||
import VideoTaskQueue from './Video/VideoTaskQueue';
|
||||
import VideoRegenerateModal from './Video/VideoRegenerateModal';
|
||||
import { useVideoGeneration } from '../../../../hooks/video/useVideoGeneration';
|
||||
|
||||
const VideoGenerationTab = () => {
|
||||
const [leftPanelCollapsed, setLeftPanelCollapsed] = useState(false);
|
||||
const [taskQueueVisible, setTaskQueueVisible] = useState(false);
|
||||
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
|
||||
const [selectedTaskForPlay, setSelectedTaskForPlay] = useState(null);
|
||||
const [regenerateModalVisible, setRegenerateModalVisible] = useState(false);
|
||||
const [taskToRegenerate, setTaskToRegenerate] = useState(null);
|
||||
|
||||
// 监听窗口大小变化
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setWindowWidth(window.innerWidth);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', handleResize);
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, []);
|
||||
|
||||
const {
|
||||
// 表单数据
|
||||
formData,
|
||||
setFormData,
|
||||
// 模型相关
|
||||
selectedModel,
|
||||
setSelectedModel,
|
||||
modelInfo,
|
||||
// 生成相关
|
||||
generating,
|
||||
currentTask,
|
||||
handleGenerate,
|
||||
submitVideo,
|
||||
handleCancel,
|
||||
// 任务列表
|
||||
tasks,
|
||||
refreshTasks,
|
||||
deleteTask,
|
||||
getRegenerationTask,
|
||||
downloadTask,
|
||||
getTaskVideoUrl,
|
||||
} = useVideoGeneration();
|
||||
|
||||
// 处理任务列表的播放按钮
|
||||
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) return;
|
||||
setTaskToRegenerate(detail);
|
||||
setRegenerateModalVisible(true);
|
||||
};
|
||||
|
||||
// 确认再生成
|
||||
const handleRegenerateConfirm = async (requestData) => {
|
||||
const submitted = await submitVideo(requestData, requestData.model);
|
||||
if (submitted) {
|
||||
setRegenerateModalVisible(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 响应式布局配置 - 两列布局(左侧配置区 + 右侧预览区)
|
||||
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
|
||||
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(--semi-color-bg-1)',
|
||||
borderRight:
|
||||
layoutConfig.direction === 'row'
|
||||
? '1px solid var(--semi-color-border)'
|
||||
: 'none',
|
||||
borderBottom:
|
||||
layoutConfig.direction === 'column'
|
||||
? '1px solid var(--semi-color-border)'
|
||||
: 'none',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className='app-scrollbar'
|
||||
style={{
|
||||
height: '100%',
|
||||
overflow: 'auto',
|
||||
paddingBottom: layoutConfig.direction === 'row' ? '16px' : '16px',
|
||||
}}
|
||||
>
|
||||
<VideoInputPanel
|
||||
formData={formData}
|
||||
setFormData={setFormData}
|
||||
onCollapse={() => setLeftPanelCollapsed(!leftPanelCollapsed)}
|
||||
collapsed={leftPanelCollapsed}
|
||||
collapsible={layoutConfig.direction === 'row'}
|
||||
selectedModel={selectedModel}
|
||||
setSelectedModel={setSelectedModel}
|
||||
modelInfo={modelInfo}
|
||||
/>
|
||||
</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(--semi-color-bg-0)',
|
||||
padding: windowWidth > 768 ? '16px' : '12px',
|
||||
overflow: 'auto',
|
||||
}}
|
||||
>
|
||||
<VideoPreviewPanel
|
||||
formData={formData}
|
||||
generating={generating}
|
||||
currentTask={currentTask}
|
||||
onGenerate={handleGenerate}
|
||||
onCancel={handleCancel}
|
||||
selectedModel={selectedModel}
|
||||
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>
|
||||
|
||||
{/* 再生成弹窗 */}
|
||||
<VideoRegenerateModal
|
||||
visible={regenerateModalVisible}
|
||||
onCancel={() => setRegenerateModalVisible(false)}
|
||||
onConfirm={handleRegenerateConfirm}
|
||||
task={taskToRegenerate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoGenerationTab;
|
||||
Reference in New Issue
Block a user