Skip to content

🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"

TypeScript

refactor: 创建 useVideoMerge composable + StoryboardList/PreviewPane 子组件

Connor1c63e921c604
diff --git a/web/src/composables/useVideoMerge.ts b/web/src/composables/useVideoMerge.ts
new file mode 100644
index 0000000..40d47f9
--- /dev/null
+++ b/web/src/composables/useVideoMerge.ts
@@ -0,0 +1,155 @@
+import { ref, type Ref } from 'vue'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import { videoMergeAPI, type VideoMerge } from '@/api/videoMerge'
+
+export function useVideoMerge(episodeId: Ref<string | number>) {
+ const videoMerges = ref<VideoMerge[]>([])
+ const loadingMerges = ref(false)
+ let mergePollingTimer: any = null
+
+ const loadVideoMerges = async () => {
+ if (!episodeId.value) return
+
+ try {
+ loadingMerges.value = true
+ const result = await videoMergeAPI.listMerges({
+ episode_id: episodeId.value.toString(),
+ page: 1,
+ page_size: 20,
+ })
+ videoMerges.value = result.merges
+
+ const hasProcessingTasks = result.merges.some(
+ (merge: any) =>
+ merge.status === 'pending' || merge.status === 'processing',
+ )
+
+ if (hasProcessingTasks) {
+ startMergePolling()
+ } else {
+ stopMergePolling()
+ }
+ } catch (error: any) {
+ console.error('加载视频合成列表失败:', error)
+ ElMessage.error('加载视频合成列表失败')
+ } finally {
+ loadingMerges.value = false
+ }
+ }
+
+ const startMergePolling = () => {
+ if (mergePollingTimer) return
+
+ mergePollingTimer = setInterval(async () => {
+ if (!episodeId.value) {
+ stopMergePolling()
+ return
+ }
+
+ try {
+ const result = await videoMergeAPI.listMerges({
+ episode_id: episodeId.value.toString(),
+ page: 1,
+ page_size: 20,
+ })
+ videoMerges.value = result.merges
+
+ const hasProcessingTasks = result.merges.some(
+ (merge: any) =>
+ merge.status === 'pending' || merge.status === 'processing',
+ )
+
+ if (!hasProcessingTasks) {
+ stopMergePolling()
+ }
+ } catch (error) {}
+ }, 3000)
+ }
+
+ const stopMergePolling = () => {
+ if (mergePollingTimer) {
+ clearInterval(mergePollingTimer)
+ mergePollingTimer = null
+ }
+ }
+
+ const handleMergeCompleted = async () => {
+ await loadVideoMerges()
+ }
+
+ const downloadVideo = async (url: string, title: string) => {
+ try {
+ const loadingMsg = ElMessage.info({
+ message: '正在准备下载...',
+ duration: 0,
+ })
+
+ const videoUrl = url.startsWith('http') ? url : `/static/${url}`
+
+ const response = await fetch(videoUrl)
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`)
+ }
+
+ const blob = await response.blob()
+ const blobUrl = window.URL.createObjectURL(blob)
+
+ const link = document.createElement('a')
+ link.href = blobUrl
+ link.download = `${title}.mp4`
+ link.style.display = 'none'
+ document.body.appendChild(link)
+ link.click()
+
+ setTimeout(() => {
+ document.body.removeChild(link)
+ window.URL.revokeObjectURL(blobUrl)
+ }, 100)
+
+ loadingMsg.close()
+ ElMessage.success('视频下载已开始')
+ } catch (error) {
+ console.error('下载视频失败:', error)
+ ElMessage.error('视频下载失败,请稍后重试')
+ }
+ }
+
+ const previewMergedVideo = (url: string) => {
+ const videoUrl = url.startsWith('http') ? url : `/static/${url}`
+ window.open(videoUrl, '_blank')
+ }
+
+ const deleteMerge = async (mergeId: number) => {
+ try {
+ await ElMessageBox.confirm(
+ '确定要删除此合成记录吗?此操作不可恢复。',
+ '删除确认',
+ {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning',
+ },
+ )
+
+ await videoMergeAPI.deleteMerge(mergeId)
+ ElMessage.success('删除成功')
+ await loadVideoMerges()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ console.error('删除失败:', error)
+ ElMessage.error(error.response?.data?.message || '删除失败')
+ }
+ }
+ }
+
+ return {
+ videoMerges,
+ loadingMerges,
+ loadVideoMerges,
+ handleMergeCompleted,
+ downloadVideo,
+ previewMergedVideo,
+ deleteMerge,
+ stopMergePolling,
+ }
+}
diff --git a/web/src/views/drama/professional/PreviewPane.vue b/web/src/views/drama/professional/PreviewPane.vue
new file mode 100644
index 0000000..ba62e66
--- /dev/null
+++ b/web/src/views/drama/professional/PreviewPane.vue
@@ -0,0 +1,79 @@
+<template>
+ <div class="preview-area-v2">
+ <template v-if="currentStoryboard">
+ <video
+ v-if="currentPreviewVideo"
+ :src="currentPreviewVideo"
+ class="preview-media"
+ controls
+ preload="metadata"
+ />
+ <img
+ v-else-if="currentPreviewUrl"
+ :src="currentPreviewUrl"
+ class="preview-media"
+ alt="当前分镜预览"
+ />
+ <div v-else class="preview-placeholder">
+ <el-icon :size="48" color="#444"><Picture /></el-icon>
+ <p>暂无预览图,请先生成图片</p>
+ </div>
+ <div class="preview-info-overlay">
+ <span class="preview-shot-num">#{{ currentStoryboard.storyboard_number }}</span>
+ <span class="preview-shot-title">{{ currentStoryboard.title || $t('storyboard.untitled') }}</span>
+ <span class="preview-shot-duration">{{ currentStoryboard.duration }}s</span>
+ </div>
+ </template>
+ <div v-else class="preview-placeholder">
+ <el-icon :size="48" color="#444"><Picture /></el-icon>
+ <p>请从左侧选择分镜</p>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { Picture } from '@element-plus/icons-vue'
+import type { Storyboard } from '@/types/drama'
+
+defineProps<{
+ currentStoryboard: Storyboard | null
+ currentPreviewUrl: string | null
+ currentPreviewVideo: string | null
+}>()
+</script>
+
+<style scoped lang="scss">
+.preview-area-v2 {
+ flex: 1;
+ min-height: 80px;
+ background: #000;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ position: relative;
+ overflow: hidden;
+
+ .preview-media {
+ max-width: 100%; max-height: 100%;
+ object-fit: contain; display: block;
+ }
+ .preview-placeholder {
+ display: flex; flex-direction: column;
+ align-items: center; gap: 10px; color: #555;
+ p { font-size: 13px; margin: 0; }
+ }
+ .preview-info-overlay {
+ position: absolute; bottom: 8px; left: 8px;
+ display: flex; gap: 6px; align-items: center;
+ .preview-shot-num {
+ background: rgba(0,0,0,.7); color: #fff;
+ font-size: 11px; padding: 2px 6px; border-radius: 4px; font-weight: 600;
+ }
+ .preview-shot-title { color: rgba(255,255,255,.8); font-size: 12px; }
+ .preview-shot-duration {
+ background: rgba(64,158,255,.8); color: #fff;
+ font-size: 11px; padding: 2px 6px; border-radius: 4px;
+ }
+ }
+}
+</style>
diff --git a/web/src/views/drama/professional/StoryboardList.vue b/web/src/views/drama/professional/StoryboardList.vue
new file mode 100644
index 0000000..bc8cd66
--- /dev/null
+++ b/web/src/views/drama/professional/StoryboardList.vue
@@ -0,0 +1,165 @@
+<template>
+ <div class="storyboard-panel-v2">
+ <div class="panel-header-v2">
+ <span class="panel-title">{{ $t('storyboard.scriptStructure') }}</span>
+ <el-button text :icon="Plus" size="small" @click="$emit('add')">{{ $t('storyboard.add') }}</el-button>
+ </div>
+ <div class="storyboard-cards">
+ <div
+ v-for="shot in storyboards"
+ :key="shot.id"
+ class="storyboard-card"
+ :class="{ active: currentStoryboardId === shot.id }"
+ @click="$emit('select', shot.id)"
+ >
+ <!-- 缩略图 -->
+ <div class="card-thumbnail">
+ <img
+ v-if="getStoryboardThumbnail(shot)"
+ :src="getStoryboardThumbnail(shot) ?? undefined"
+ alt=""
+ class="thumbnail-img"
+ />
+ <div v-else class="thumbnail-placeholder">
+ <el-icon :size="18" color="#aaa"><Picture /></el-icon>
+ </div>
+ <div class="shot-number-badge">#{{ shot.storyboard_number }}</div>
+ </div>
+ <!-- 信息区 -->
+ <div class="card-info">
+ <div class="card-title">{{ shot.title || $t('storyboard.untitled') }}</div>
+ <div class="card-meta">
+ <span class="card-duration">{{ shot.duration }}s</span>
+ <span
+ class="status-dot"
+ :class="(shot as any).background?.image_url ? 'dot-image' : 'dot-empty'"
+ >图</span>
+ </div>
+ </div>
+ <!-- 删除按钮 -->
+ <el-button
+ link type="danger" :icon="Delete" size="small"
+ class="card-delete-btn"
+ @click.stop="$emit('delete', shot)"
+ />
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { Plus, Picture, Delete } from '@element-plus/icons-vue'
+import type { Storyboard } from '@/types/drama'
+
+defineProps<{
+ storyboards: Storyboard[]
+ currentStoryboardId: string | null
+ getStoryboardThumbnail: (s: any) => string | null
+}>()
+
+defineEmits<{
+ select: [id: string]
+ add: []
+ delete: [storyboard: Storyboard]
+}>()
+</script>
+
+<style scoped lang="scss">
+.storyboard-panel-v2 {
+ display: flex;
+ flex-direction: column;
+ background: var(--bg-secondary, #f0f2f5);
+ border-right: 1px solid var(--border-color, #e4e7ed);
+ overflow: hidden;
+ width: 220px;
+ flex-shrink: 0;
+}
+
+.panel-header-v2 {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 8px 10px;
+ border-bottom: 1px solid var(--border-color, #e4e7ed);
+ flex-shrink: 0;
+
+ .panel-title {
+ font-size: 13px;
+ font-weight: 600;
+ color: var(--text-primary, #303133);
+ }
+}
+
+.storyboard-cards {
+ flex: 1;
+ overflow-y: auto;
+ padding: 6px;
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+}
+
+.storyboard-card {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ background: #fff;
+ border: 2px solid transparent;
+ border-radius: 7px;
+ padding: 5px;
+ cursor: pointer;
+ transition: border-color 0.15s, box-shadow 0.15s;
+ position: relative;
+
+ &:hover { border-color: #a0cfff; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
+ &.active { border-color: #409eff; background: #ecf5ff; }
+}
+
+.card-thumbnail {
+ width: 68px;
+ height: 44px;
+ border-radius: 4px;
+ overflow: hidden;
+ flex-shrink: 0;
+ position: relative;
+ background: #e0e0e0;
+
+ .thumbnail-img { width: 100%; height: 100%; object-fit: cover; }
+ .thumbnail-placeholder {
+ width: 100%; height: 100%;
+ display: flex; align-items: center; justify-content: center;
+ background: #e8e8e8;
+ }
+ .shot-number-badge {
+ position: absolute; bottom: 2px; left: 2px;
+ background: rgba(0,0,0,.6); color: #fff;
+ font-size: 9px; padding: 0 3px; border-radius: 2px; line-height: 15px;
+ }
+}
+
+.card-info {
+ flex: 1;
+ min-width: 0;
+
+ .card-title {
+ font-size: 12px; font-weight: 500;
+ color: var(--text-primary, #303133);
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
+ margin-bottom: 3px;
+ }
+ .card-meta {
+ display: flex; align-items: center; justify-content: space-between;
+ .card-duration { font-size: 11px; color: #909399; }
+ }
+ .status-dot {
+ font-size: 10px; padding: 1px 4px; border-radius: 3px; font-weight: 500;
+ &.dot-image { background: #ecf5ff; color: #409eff; }
+ &.dot-empty { background: #f4f4f5; color: #c0c4cc; }
+ }
+}
+
+.card-delete-btn {
+ flex-shrink: 0; opacity: 0; transition: opacity 0.15s;
+}
+.storyboard-card:hover .card-delete-btn { opacity: 1; }
+</style>