forked from 77media/video-flow
更新剧集处理
This commit is contained in:
parent
f2ba3fa628
commit
724bbc6c8f
@ -1,5 +1,5 @@
|
|||||||
// import { redirect } from 'next/navigation';
|
// import { redirect } from 'next/navigation';
|
||||||
import { CreateToVideo2 } from '@/components/pages/create-to-video';
|
import { CreateToVideo2 } from '@/components/pages/create-to-video2';
|
||||||
|
|
||||||
export default function CreatePage() {
|
export default function CreatePage() {
|
||||||
// redirect('/create/video-to-video');
|
// redirect('/create/video-to-video');
|
||||||
|
|||||||
@ -66,7 +66,7 @@ export function CreateToVideo2() {
|
|||||||
const [isFocus, setIsFocus] = useState(false);
|
const [isFocus, setIsFocus] = useState(false);
|
||||||
const [selectedMode, setSelectedMode] = useState<ModeEnum>(ModeEnum.AUTOMATIC);
|
const [selectedMode, setSelectedMode] = useState<ModeEnum>(ModeEnum.AUTOMATIC);
|
||||||
const [selectedResolution, setSelectedResolution] = useState<ResolutionEnum>(ResolutionEnum.HD_720P);
|
const [selectedResolution, setSelectedResolution] = useState<ResolutionEnum>(ResolutionEnum.HD_720P);
|
||||||
const [inputText, setInputText] = useState('');
|
const [script, setInputText] = useState('');
|
||||||
const editorRef = useRef<HTMLDivElement>(null);
|
const editorRef = useRef<HTMLDivElement>(null);
|
||||||
const [runTour, setRunTour] = useState(true);
|
const [runTour, setRunTour] = useState(true);
|
||||||
|
|
||||||
@ -103,18 +103,18 @@ export function CreateToVideo2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleCreateVideo = async () => {
|
const handleCreateVideo = async () => {
|
||||||
if (videoUrl || inputText) {
|
if (videoUrl || script) {
|
||||||
try {
|
try {
|
||||||
let convertResponse;
|
let convertResponse;
|
||||||
|
|
||||||
// 根据选中的选项卡调用相应的API
|
// 根据选中的选项卡调用相应的API
|
||||||
if (activeTab === 'script') {
|
if (activeTab === 'script') {
|
||||||
// 剧本模式:调用convertScriptToScene (第43-56行)
|
// 剧本模式:调用convertScriptToScene (第43-56行)
|
||||||
if (!inputText.trim()) {
|
if (!script.trim()) {
|
||||||
alert('请输入剧本内容');
|
alert('请输入剧本内容');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
convertResponse = await convertScriptToScene(inputText);
|
convertResponse = await convertScriptToScene(script);
|
||||||
} else {
|
} else {
|
||||||
// 视频模式:调用convertVideoToScene (第56-69行)
|
// 视频模式:调用convertVideoToScene (第56-69行)
|
||||||
if (!videoUrl) {
|
if (!videoUrl) {
|
||||||
@ -147,6 +147,10 @@ export function CreateToVideo2() {
|
|||||||
|
|
||||||
// 创建剧集数据
|
// 创建剧集数据
|
||||||
const episodeData: CreateScriptEpisodeRequest = {
|
const episodeData: CreateScriptEpisodeRequest = {
|
||||||
|
title: "episode 1",
|
||||||
|
script_id: projectId,
|
||||||
|
status: 1,
|
||||||
|
summary: script
|
||||||
};
|
};
|
||||||
|
|
||||||
// 调用创建剧集API
|
// 调用创建剧集API
|
||||||
@ -272,7 +276,7 @@ export function CreateToVideo2() {
|
|||||||
// 处理编辑器聚焦
|
// 处理编辑器聚焦
|
||||||
const handleEditorFocus = () => {
|
const handleEditorFocus = () => {
|
||||||
setIsFocus(true);
|
setIsFocus(true);
|
||||||
if (editorRef.current && inputText) {
|
if (editorRef.current && script) {
|
||||||
// 创建范围对象
|
// 创建范围对象
|
||||||
const range = document.createRange();
|
const range = document.createRange();
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
@ -280,11 +284,11 @@ export function CreateToVideo2() {
|
|||||||
// 获取编辑器内的文本节点
|
// 获取编辑器内的文本节点
|
||||||
const textNode = Array.from(editorRef.current.childNodes).find(
|
const textNode = Array.from(editorRef.current.childNodes).find(
|
||||||
node => node.nodeType === Node.TEXT_NODE
|
node => node.nodeType === Node.TEXT_NODE
|
||||||
) || editorRef.current.appendChild(document.createTextNode(inputText));
|
) || editorRef.current.appendChild(document.createTextNode(script));
|
||||||
|
|
||||||
// 设置范围到文本末尾
|
// 设置范围到文本末尾
|
||||||
range.setStart(textNode, inputText.length);
|
range.setStart(textNode, script.length);
|
||||||
range.setEnd(textNode, inputText.length);
|
range.setEnd(textNode, script.length);
|
||||||
|
|
||||||
// 应用选择
|
// 应用选择
|
||||||
selection?.removeAllRanges();
|
selection?.removeAllRanges();
|
||||||
@ -294,8 +298,8 @@ export function CreateToVideo2() {
|
|||||||
|
|
||||||
// 处理编辑器内容变化
|
// 处理编辑器内容变化
|
||||||
const handleEditorChange = (e: React.FormEvent<HTMLDivElement>) => {
|
const handleEditorChange = (e: React.FormEvent<HTMLDivElement>) => {
|
||||||
const newText = e.currentTarget.textContent || '';
|
const script = e.currentTarget.textContent || '';
|
||||||
setInputText(newText);
|
setInputText(script);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 引导步骤
|
// 引导步骤
|
||||||
@ -484,10 +488,10 @@ export function CreateToVideo2() {
|
|||||||
onInput={handleEditorChange}
|
onInput={handleEditorChange}
|
||||||
suppressContentEditableWarning
|
suppressContentEditableWarning
|
||||||
>
|
>
|
||||||
{inputText}
|
{script}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`custom-placeholder absolute top-[50%] left-[10px] z-10 translate-y-[-50%] flex items-center gap-1 pointer-events-none text-[14px] leading-[26px] text-white/[0.40] ${inputText ? 'opacity-0' : 'opacity-100'}`}
|
className={`custom-placeholder absolute top-[50%] left-[10px] z-10 translate-y-[-50%] flex items-center gap-1 pointer-events-none text-[14px] leading-[26px] text-white/[0.40] ${script ? 'opacity-0' : 'opacity-100'}`}
|
||||||
>
|
>
|
||||||
<span>Describe the content you want to create. Get an </span>
|
<span>Describe the content you want to create. Get an </span>
|
||||||
<b
|
<b
|
||||||
@ -547,7 +551,7 @@ export function CreateToVideo2() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center gap-3'>
|
<div className='flex items-center gap-3'>
|
||||||
<div className={`tool-submit-button ${videoUrl || inputText ? '' : 'disabled'}`} onClick={handleCreateVideo}>
|
<div className={`tool-submit-button ${videoUrl || script ? '' : 'disabled'}`} onClick={handleCreateVideo}>
|
||||||
<ArrowUp className='w-4 h-4' />Create
|
<ArrowUp className='w-4 h-4' />Create
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -64,20 +64,6 @@ export function HomePage2() {
|
|||||||
if (projectResponse.code === 0 && projectResponse.data.id) {
|
if (projectResponse.code === 0 && projectResponse.data.id) {
|
||||||
const projectId = projectResponse.data.id;
|
const projectId = projectResponse.data.id;
|
||||||
setCreatedProjectId(projectId);
|
setCreatedProjectId(projectId);
|
||||||
|
|
||||||
// 创建剧集数据
|
|
||||||
const episodeData: CreateScriptEpisodeRequest = {
|
|
||||||
};
|
|
||||||
|
|
||||||
// 调用创建剧集API
|
|
||||||
const episodeResponse = await createScriptEpisode(episodeData);
|
|
||||||
|
|
||||||
if (episodeResponse.code === 0) {
|
|
||||||
// 成功创建后跳转到create页面
|
|
||||||
router.push("/create");
|
|
||||||
} else {
|
|
||||||
alert(`创建剧集失败: ${episodeResponse.message}`);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
alert(`创建项目失败: ${projectResponse.message}`);
|
alert(`创建项目失败: ${projectResponse.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user