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

feat: build ResourcePanel with script, character, and scene blocks

Connor05127ea6aed0
diff --git a/web/src/views/drama/episode/workbench/CharacterBlock.vue b/web/src/views/drama/episode/workbench/CharacterBlock.vue
new file mode 100644
index 0000000..eaa962b
--- /dev/null
+++ b/web/src/views/drama/episode/workbench/CharacterBlock.vue
@@ -0,0 +1,312 @@
+<script setup lang="ts">
+import { Button } from '@/components/ui/button'
+import { Badge } from '@/components/ui/badge'
+import {
+ User,
+ ChevronDown,
+ ChevronRight,
+ ImagePlus,
+ Sparkles,
+ Loader2,
+} from 'lucide-vue-next'
+import type { Character } from '@/types/drama'
+
+defineProps<{
+ characters: Character[]
+ expanded: boolean
+ hasContent: boolean
+}>()
+
+const emit = defineEmits<{
+ toggle: []
+ generateImage: [id: number]
+ batchGenerate: []
+}>()
+
+function statusLabel(status?: string) {
+ switch (status) {
+ case 'completed':
+ return '已生成'
+ case 'generating':
+ return '生成中'
+ case 'failed':
+ return '失败'
+ default:
+ return '待生成'
+ }
+}
+
+function statusVariant(status?: string): 'default' | 'secondary' | 'destructive' | 'outline' {
+ switch (status) {
+ case 'completed':
+ return 'default'
+ case 'generating':
+ return 'secondary'
+ case 'failed':
+ return 'destructive'
+ default:
+ return 'outline'
+ }
+}
+</script>
+
+<template>
+ <div
+ class="character-block"
+ :class="{ 'is-disabled': !hasContent }"
+ >
+ <!-- Header -->
+ <button class="block-header" @click="emit('toggle')">
+ <div class="block-header__left">
+ <component
+ :is="expanded ? ChevronDown : ChevronRight"
+ :size="14"
+ class="block-header__chevron"
+ />
+ <User :size="14" class="block-header__icon" />
+ <span class="block-header__title">角色</span>
+ </div>
+ <span v-if="hasContent && !expanded" class="block-header__count">
+ ({{ characters.length }})
+ </span>
+ </button>
+
+ <!-- Expanded -->
+ <div v-if="expanded && hasContent" class="block-body">
+ <div class="character-list">
+ <div
+ v-for="char in characters"
+ :key="char.id"
+ class="character-item"
+ >
+ <div class="character-avatar">
+ <img
+ v-if="char.image_url"
+ :src="char.image_url"
+ :alt="char.name"
+ class="character-avatar__img"
+ />
+ <User v-else :size="16" class="character-avatar__placeholder" />
+ </div>
+ <div class="character-info">
+ <span class="character-name">{{ char.name }}</span>
+ <span v-if="char.role" class="character-role">{{ char.role }}</span>
+ </div>
+ <div class="character-actions">
+ <Badge
+ :variant="statusVariant(char.image_generation_status)"
+ class="character-badge"
+ >
+ <Loader2
+ v-if="char.image_generation_status === 'generating'"
+ :size="10"
+ class="animate-spin mr-1"
+ />
+ {{ statusLabel(char.image_generation_status) }}
+ </Badge>
+ <button
+ v-if="char.image_generation_status !== 'completed' && char.image_generation_status !== 'generating'"
+ class="gen-btn"
+ title="生成形象"
+ @click.stop="emit('generateImage', char.id)"
+ >
+ <ImagePlus :size="13" />
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <Button
+ variant="ghost"
+ size="sm"
+ class="batch-btn"
+ @click="emit('batchGenerate')"
+ >
+ <Sparkles :size="13" />
+ 批量生成形象
+ </Button>
+ </div>
+
+ <div v-if="expanded && !hasContent" class="block-empty">
+ 请先提取角色
+ </div>
+ </div>
+</template>
+
+<style scoped>
+.character-block {
+ border-bottom: 1px solid var(--border-primary);
+}
+
+.is-disabled {
+ opacity: 0.45;
+ pointer-events: none;
+}
+
+.block-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+ padding: 10px 12px;
+ background: transparent;
+ border: none;
+ cursor: pointer;
+ color: var(--text-primary);
+ transition: background var(--transition-fast);
+}
+
+.block-header:hover {
+ background: var(--bg-card-hover);
+}
+
+.block-header__left {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 13px;
+ font-weight: 500;
+}
+
+.block-header__chevron {
+ color: var(--text-muted);
+ flex-shrink: 0;
+}
+
+.block-header__icon {
+ color: var(--accent);
+ flex-shrink: 0;
+}
+
+.block-header__title {
+ white-space: nowrap;
+}
+
+.block-header__count {
+ font-size: 11px;
+ color: var(--text-secondary);
+}
+
+.block-body {
+ padding: 0 12px 10px;
+}
+
+.block-empty {
+ padding: 12px;
+ font-size: 12px;
+ color: var(--text-muted);
+ text-align: center;
+}
+
+.character-list {
+ max-height: 240px;
+ overflow-y: auto;
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+}
+
+.character-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 6px 8px;
+ border-radius: var(--radius-sm);
+ transition: background var(--transition-fast);
+}
+
+.character-item:hover {
+ background: var(--bg-card-hover);
+}
+
+.character-avatar {
+ width: 28px;
+ height: 28px;
+ border-radius: var(--radius-full);
+ background: var(--bg-primary);
+ border: 1px solid var(--border-primary);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+ overflow: hidden;
+}
+
+.character-avatar__img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.character-avatar__placeholder {
+ color: var(--text-muted);
+}
+
+.character-info {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ flex-direction: column;
+}
+
+.character-name {
+ font-size: 12px;
+ font-weight: 500;
+ color: var(--text-primary);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.character-role {
+ font-size: 10px;
+ color: var(--text-muted);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.character-actions {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ flex-shrink: 0;
+}
+
+.character-badge {
+ font-size: 10px !important;
+ padding: 1px 6px !important;
+ height: auto !important;
+}
+
+.gen-btn {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 22px;
+ height: 22px;
+ border: none;
+ border-radius: var(--radius-sm);
+ background: transparent;
+ color: var(--text-muted);
+ cursor: pointer;
+ transition: all var(--transition-fast);
+}
+
+.gen-btn:hover {
+ background: var(--bg-card-hover);
+ color: var(--accent);
+}
+
+.batch-btn {
+ width: 100%;
+ margin-top: 6px;
+ font-size: 11px !important;
+ height: 28px !important;
+ color: var(--text-secondary) !important;
+}
+
+.batch-btn:hover {
+ color: var(--text-primary) !important;
+}
+</style>
diff --git a/web/src/views/drama/episode/workbench/ResourcePanel.vue b/web/src/views/drama/episode/workbench/ResourcePanel.vue
new file mode 100644
index 0000000..06dee0e
--- /dev/null
+++ b/web/src/views/drama/episode/workbench/ResourcePanel.vue
@@ -0,0 +1,62 @@
+<script setup lang="ts">
+import ScriptBlock from './ScriptBlock.vue'
+import CharacterBlock from './CharacterBlock.vue'
+import SceneBlock from './SceneBlock.vue'
+import type { useResourcePanel } from '@/composables/useResourcePanel'
+
+const props = defineProps<{
+ resource: ReturnType<typeof useResourcePanel>
+}>()
+
+defineEmits<{
+ extract: []
+ uploadScript: []
+ rewriteScript: []
+ generateCharacterImage: [id: number]
+ batchGenerateCharacters: []
+ generateSceneImage: [id: number]
+ batchGenerateScenes: []
+}>()
+</script>
+
+<template>
+ <aside class="resource-panel">
+ <ScriptBlock
+ :script-content="resource.scriptContent.value"
+ :expanded="resource.expandedBlock.value === 'script'"
+ :has-content="resource.hasScript.value"
+ @toggle="resource.toggleBlock('script')"
+ @save="resource.saveScript"
+ @extract="$emit('extract')"
+ @upload="$emit('uploadScript')"
+ @rewrite="$emit('rewriteScript')"
+ />
+ <CharacterBlock
+ :characters="resource.characters.value"
+ :expanded="resource.expandedBlock.value === 'characters'"
+ :has-content="resource.hasCharacters.value"
+ @toggle="resource.toggleBlock('characters')"
+ @generate-image="$emit('generateCharacterImage', $event)"
+ @batch-generate="$emit('batchGenerateCharacters')"
+ />
+ <SceneBlock
+ :scenes="resource.scenes.value"
+ :expanded="resource.expandedBlock.value === 'scenes'"
+ :has-content="resource.hasScenes.value"
+ @toggle="resource.toggleBlock('scenes')"
+ @generate-image="$emit('generateSceneImage', $event)"
+ @batch-generate="$emit('batchGenerateScenes')"
+ />
+ </aside>
+</template>
+
+<style scoped>
+.resource-panel {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ background: var(--bg-card);
+ border-right: 1px solid var(--border-primary);
+ overflow-y: auto;
+}
+</style>
diff --git a/web/src/views/drama/episode/workbench/SceneBlock.vue b/web/src/views/drama/episode/workbench/SceneBlock.vue
new file mode 100644
index 0000000..a1ac6ed
--- /dev/null
+++ b/web/src/views/drama/episode/workbench/SceneBlock.vue
@@ -0,0 +1,313 @@
+<script setup lang="ts">
+import { Button } from '@/components/ui/button'
+import { Badge } from '@/components/ui/badge'
+import {
+ MapPin,
+ ChevronDown,
+ ChevronRight,
+ ImagePlus,
+ Sparkles,
+ Loader2,
+} from 'lucide-vue-next'
+import type { Scene } from '@/types/drama'
+
+defineProps<{
+ scenes: Scene[]
+ expanded: boolean
+ hasContent: boolean
+}>()
+
+const emit = defineEmits<{
+ toggle: []
+ generateImage: [id: number]
+ batchGenerate: []
+}>()
+
+function statusLabel(status?: string) {
+ switch (status) {
+ case 'completed':
+ return '已生成'
+ case 'generating':
+ return '生成中'
+ case 'failed':
+ return '失败'
+ default:
+ return '待生成'
+ }
+}
+
+function statusVariant(status?: string): 'default' | 'secondary' | 'destructive' | 'outline' {
+ switch (status) {
+ case 'completed':
+ return 'default'
+ case 'generating':
+ return 'secondary'
+ case 'failed':
+ return 'destructive'
+ default:
+ return 'outline'
+ }
+}
+</script>
+
+<template>
+ <div
+ class="scene-block"
+ :class="{ 'is-disabled': !hasContent }"
+ >
+ <!-- Header -->
+ <button class="block-header" @click="emit('toggle')">
+ <div class="block-header__left">
+ <component
+ :is="expanded ? ChevronDown : ChevronRight"
+ :size="14"
+ class="block-header__chevron"
+ />
+ <MapPin :size="14" class="block-header__icon" />
+ <span class="block-header__title">场景</span>
+ </div>
+ <span v-if="hasContent && !expanded" class="block-header__count">
+ ({{ scenes.length }})
+ </span>
+ </button>
+
+ <!-- Expanded -->
+ <div v-if="expanded && hasContent" class="block-body">
+ <div class="scene-list">
+ <div
+ v-for="scene in scenes"
+ :key="scene.id"
+ class="scene-item"
+ >
+ <div class="scene-thumb">
+ <img
+ v-if="scene.image_url"
+ :src="scene.image_url"
+ :alt="scene.location"
+ class="scene-thumb__img"
+ />
+ <MapPin v-else :size="14" class="scene-thumb__placeholder" />
+ </div>
+ <div class="scene-info">
+ <span class="scene-location">{{ scene.location }}</span>
+ <span class="scene-time">{{ scene.time }}</span>
+ </div>
+ <div class="scene-actions">
+ <Badge
+ :variant="statusVariant(scene.image_generation_status)"
+ class="scene-badge"
+ >
+ <Loader2
+ v-if="scene.image_generation_status === 'generating'"
+ :size="10"
+ class="animate-spin mr-1"
+ />
+ {{ statusLabel(scene.image_generation_status) }}
+ </Badge>
+ <button
+ v-if="scene.image_generation_status !== 'completed' && scene.image_generation_status !== 'generating'"
+ class="gen-btn"
+ title="生成场景图"
+ @click.stop="emit('generateImage', Number(scene.id))"
+ >
+ <ImagePlus :size="13" />
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <Button
+ variant="ghost"
+ size="sm"
+ class="batch-btn"
+ @click="emit('batchGenerate')"
+ >
+ <Sparkles :size="13" />
+ 批量生成场景图
+ </Button>
+ </div>
+
+ <div v-if="expanded && !hasContent" class="block-empty">
+ 请先提取场景
+ </div>
+ </div>
+</template>
+
+<style scoped>
+.scene-block {
+ border-bottom: 1px solid var(--border-primary);
+}
+
+.scene-block:last-child {
+ border-bottom: none;
+}
+
+.is-disabled {
+ opacity: 0.45;
+ pointer-events: none;
+}
+
+.block-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+ padding: 10px 12px;
+ background: transparent;
+ border: none;
+ cursor: pointer;
+ color: var(--text-primary);
+ transition: background var(--transition-fast);
+}
+
+.block-header:hover {
+ background: var(--bg-card-hover);
+}
+
+.block-header__left {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 13px;
+ font-weight: 500;
+}
+
+.block-header__chevron {
+ color: var(--text-muted);
+ flex-shrink: 0;
+}
+
+.block-header__icon {
+ color: var(--accent);
+ flex-shrink: 0;
+}
+
+.block-header__title {
+ white-space: nowrap;
+}
+
+.block-header__count {
+ font-size: 11px;
+ color: var(--text-secondary);
+}
+
+.block-body {
+ padding: 0 12px 10px;
+}
+
+.block-empty {
+ padding: 12px;
+ font-size: 12px;
+ color: var(--text-muted);
+ text-align: center;
+}
+
+.scene-list {
+ max-height: 240px;
+ overflow-y: auto;
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+}
+
+.scene-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 6px 8px;
+ border-radius: var(--radius-sm);
+ transition: background var(--transition-fast);
+}
+
+.scene-item:hover {
+ background: var(--bg-card-hover);
+}
+
+.scene-thumb {
+ width: 36px;
+ height: 24px;
+ border-radius: var(--radius-xs);
+ background: var(--bg-primary);
+ border: 1px solid var(--border-primary);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+ overflow: hidden;
+}
+
+.scene-thumb__img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.scene-thumb__placeholder {
+ color: var(--text-muted);
+}
+
+.scene-info {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ flex-direction: column;
+}
+
+.scene-location {
+ font-size: 12px;
+ font-weight: 500;
+ color: var(--text-primary);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.scene-time {
+ font-size: 10px;
+ color: var(--text-muted);
+}
+
+.scene-actions {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ flex-shrink: 0;
+}
+
+.scene-badge {
+ font-size: 10px !important;
+ padding: 1px 6px !important;
+ height: auto !important;
+}
+
+.gen-btn {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 22px;
+ height: 22px;
+ border: none;
+ border-radius: var(--radius-sm);
+ background: transparent;
+ color: var(--text-muted);
+ cursor: pointer;
+ transition: all var(--transition-fast);
+}
+
+.gen-btn:hover {
+ background: var(--bg-card-hover);
+ color: var(--accent);
+}
+
+.batch-btn {
+ width: 100%;
+ margin-top: 6px;
+ font-size: 11px !important;
+ height: 28px !important;
+ color: var(--text-secondary) !important;
+}
+
+.batch-btn:hover {
+ color: var(--text-primary) !important;
+}
+</style>
diff --git a/web/src/views/drama/episode/workbench/ScriptBlock.vue b/web/src/views/drama/episode/workbench/ScriptBlock.vue
new file mode 100644
index 0000000..98b2bc7
--- /dev/null
+++ b/web/src/views/drama/episode/workbench/ScriptBlock.vue
@@ -0,0 +1,244 @@
+<script setup lang="ts">
+import { ref, watch, computed } from 'vue'
+import { Button } from '@/components/ui/button'
+import {
+ FileText,
+ Upload,
+ Wand2,
+ ChevronDown,
+ ChevronRight,
+ Check,
+ Save,
+} from 'lucide-vue-next'
+
+const props = defineProps<{
+ scriptContent: string
+ expanded: boolean
+ hasContent: boolean
+}>()
+
+const emit = defineEmits<{
+ toggle: []
+ save: [content: string]
+ extract: []
+ upload: []
+ rewrite: []
+}>()
+
+const localContent = ref(props.scriptContent)
+const isDirty = ref(false)
+
+watch(
+ () => props.scriptContent,
+ (val) => {
+ localContent.value = val
+ isDirty.value = false
+ },
+)
+
+function onInput(e: Event) {
+ localContent.value = (e.target as HTMLTextAreaElement).value
+ isDirty.value = localContent.value !== props.scriptContent
+}
+
+function handleSave() {
+ emit('save', localContent.value)
+ isDirty.value = false
+}
+
+const wordCount = computed(() => {
+ return props.scriptContent.replace(/\s/g, '').length
+})
+</script>
+
+<template>
+ <div
+ class="script-block"
+ :class="{ 'is-disabled': !hasContent && !expanded }"
+ >
+ <!-- Header / Collapsed -->
+ <button class="block-header" @click="emit('toggle')">
+ <div class="block-header__left">
+ <component
+ :is="expanded ? ChevronDown : ChevronRight"
+ :size="14"
+ class="block-header__chevron"
+ />
+ <FileText :size="14" class="block-header__icon" />
+ <span class="block-header__title">剧本</span>
+ </div>
+ <div v-if="hasContent && !expanded" class="block-header__meta">
+ <Check :size="12" class="block-header__check" />
+ <span>{{ wordCount.toLocaleString() }}字</span>
+ </div>
+ </button>
+
+ <!-- Expanded Content -->
+ <div v-if="expanded" class="block-body">
+ <textarea
+ class="script-textarea"
+ :value="localContent"
+ placeholder="粘贴或输入剧本内容..."
+ @input="onInput"
+ />
+ <div class="block-actions">
+ <Button
+ variant="ghost"
+ size="sm"
+ class="block-action-btn"
+ @click="emit('upload')"
+ >
+ <Upload :size="13" />
+ 上传剧本
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ class="block-action-btn"
+ @click="emit('rewrite')"
+ >
+ <Wand2 :size="13" />
+ Agent 改写
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ class="block-action-btn"
+ :disabled="!hasContent"
+ @click="emit('extract')"
+ >
+ <FileText :size="13" />
+ 提取角色&场景
+ </Button>
+ <Button
+ v-if="isDirty"
+ size="sm"
+ class="block-action-btn block-action-btn--save"
+ @click="handleSave"
+ >
+ <Save :size="13" />
+ 保存
+ </Button>
+ </div>
+ </div>
+ </div>
+</template>
+
+<style scoped>
+.script-block {
+ border-bottom: 1px solid var(--border-primary);
+}
+
+.is-disabled {
+ opacity: 0.45;
+ pointer-events: none;
+}
+
+.block-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+ padding: 10px 12px;
+ background: transparent;
+ border: none;
+ cursor: pointer;
+ color: var(--text-primary);
+ transition: background var(--transition-fast);
+}
+
+.block-header:hover {
+ background: var(--bg-card-hover);
+}
+
+.block-header__left {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 13px;
+ font-weight: 500;
+}
+
+.block-header__chevron {
+ color: var(--text-muted);
+ flex-shrink: 0;
+}
+
+.block-header__icon {
+ color: var(--accent);
+ flex-shrink: 0;
+}
+
+.block-header__title {
+ white-space: nowrap;
+}
+
+.block-header__meta {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 11px;
+ color: var(--text-secondary);
+}
+
+.block-header__check {
+ color: var(--success);
+}
+
+.block-body {
+ padding: 0 12px 10px;
+}
+
+.script-textarea {
+ width: 100%;
+ min-height: 160px;
+ max-height: 320px;
+ padding: 8px 10px;
+ font-size: 12px;
+ line-height: 1.6;
+ color: var(--text-primary);
+ background: var(--bg-primary);
+ border: 1px solid var(--border-primary);
+ border-radius: var(--radius-md);
+ resize: vertical;
+ outline: none;
+ transition: border-color var(--transition-fast);
+ font-family: inherit;
+}
+
+.script-textarea:focus {
+ border-color: var(--accent);
+ box-shadow: var(--shadow-glow);
+}
+
+.script-textarea::placeholder {
+ color: var(--text-muted);
+}
+
+.block-actions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+ margin-top: 8px;
+}
+
+.block-action-btn {
+ font-size: 11px !important;
+ height: 28px !important;
+ padding: 0 8px !important;
+ color: var(--text-secondary) !important;
+}
+
+.block-action-btn:hover {
+ color: var(--text-primary) !important;
+}
+
+.block-action-btn--save {
+ color: var(--text-inverse) !important;
+ background: var(--accent) !important;
+}
+
+.block-action-btn--save:hover {
+ background: var(--accent-hover) !important;
+}
+</style>