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: management tabs use drama store directly instead of props

Connor9aeaa27947af
diff --git a/web/src/views/drama/management/CharactersTab.vue b/web/src/views/drama/management/CharactersTab.vue
index 887d645..9f68d9a 100644
--- a/web/src/views/drama/management/CharactersTab.vue
+++ b/web/src/views/drama/management/CharactersTab.vue
@@ -9,12 +9,12 @@
>{{ $t('common.batchMode') }}</el-button>
<el-button
:icon="Document"
- @click="$emit('extractCharacters')"
+ @click="openExtractCharacterDialog"
>{{ $t('prop.extract') }}</el-button>
<el-button
type="primary"
:icon="Plus"
- @click="$emit('addCharacter')"
+ @click="openAddCharacterDialog"
>{{ $t('character.add') }}</el-button>
</template>
<template #filter>
@@ -50,12 +50,12 @@
size="small"
type="danger"
:disabled="selectedCount === 0"
- @click="$emit('batchDeleteCharacters', selectedItems)"
+ @click="batchDeleteCharacters"
>{{ $t('common.batchDelete') }}</el-button>
<el-button
size="small"
:disabled="selectedCount === 0"
- @click="$emit('batchGenerateCharacterImages', selectedItems)"
+ @click="batchGenerateCharacterImages"
>{{ $t('common.batchGenerate') }}</el-button>
<el-button size="small" @click="clearSelection">{{ $t('common.cancelBatch') }}</el-button>
</div>
@@ -65,7 +65,7 @@
v-for="character in filteredItems"
:key="character.id"
class="list-row glass-list-row"
- @click="$emit('editCharacter', character)"
+ @click="editCharacter(character)"
>
<el-checkbox
v-if="isBatchMode"
@@ -73,8 +73,8 @@
@change="toggleItem(character.id)"
@click.stop
/>
- <div class="row-thumb" :class="{ 'row-thumb-icon': !hasImage(character) }">
- <img v-if="hasImage(character)" :src="getImageUrl(character)" :alt="character.name" />
+ <div class="row-thumb" :class="{ 'row-thumb-icon': !hasCharacterImage(character) }">
+ <img v-if="hasCharacterImage(character)" :src="getImageUrl(character)" :alt="character.name" />
<el-icon v-else :size="20"><User /></el-icon>
</div>
<div class="row-body">
@@ -87,9 +87,9 @@
</div>
</div>
<div class="row-actions" @click.stop>
- <ActionButton :icon="Edit" :tooltip="$t('common.edit')" variant="primary" @click="$emit('editCharacter', character)" />
- <ActionButton :icon="PictureFilled" :tooltip="$t('prop.generateImage')" @click="$emit('generateCharacterImage', character)" />
- <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="$emit('deleteCharacter', character)" />
+ <ActionButton :icon="Edit" :tooltip="$t('common.edit')" variant="primary" @click="editCharacter(character)" />
+ <ActionButton :icon="PictureFilled" :tooltip="$t('prop.generateImage')" @click="generateCharacterImage(character)" />
+ <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="deleteCharacter(character)" />
</div>
</div>
</div>
@@ -100,40 +100,152 @@
:description="$t('character.emptyTip')"
:icon="User"
>
- <el-button type="primary" :icon="Plus" @click="$emit('addCharacter')">{{ $t('character.add') }}</el-button>
+ <el-button type="primary" :icon="Plus" @click="openAddCharacterDialog">{{ $t('character.add') }}</el-button>
</EmptyState>
+
+ <!-- 添加/编辑角色对话框 -->
+ <el-dialog
+ v-model="addCharacterDialogVisible"
+ :title="editingCharacter ? $t('character.edit') : $t('character.add')"
+ width="600px"
+ >
+ <el-form :model="newCharacter" label-width="100px">
+ <el-form-item :label="$t('character.image')">
+ <el-upload
+ class="avatar-uploader"
+ :action="`/api/v1/upload/image`"
+ :show-file-list="false"
+ :on-success="handleCharacterAvatarSuccess"
+ :before-upload="beforeAvatarUpload"
+ >
+ <img
+ v-if="hasCharacterImage(newCharacter)"
+ :src="getImageUrl(newCharacter)"
+ class="avatar"
+ style="width: 100px; height: 100px; object-fit: cover"
+ />
+ <el-icon
+ v-else
+ class="avatar-uploader-icon"
+ style="border: 1px dashed #d9d9d9; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; width: 100px; height: 100px; font-size: 28px; color: #8c939d; text-align: center; line-height: 100px;"
+ ><Plus /></el-icon>
+ </el-upload>
+ </el-form-item>
+ <el-form-item :label="$t('character.name')">
+ <el-input v-model="newCharacter.name" :placeholder="$t('character.name')" />
+ </el-form-item>
+ <el-form-item :label="$t('character.role')">
+ <el-select v-model="newCharacter.role" :placeholder="$t('common.pleaseSelect')">
+ <el-option label="Main" value="main" />
+ <el-option label="Supporting" value="supporting" />
+ <el-option label="Minor" value="minor" />
+ </el-select>
+ </el-form-item>
+ <el-form-item :label="$t('character.appearance')">
+ <el-input v-model="newCharacter.appearance" type="textarea" :rows="3" :placeholder="$t('character.appearance')" />
+ </el-form-item>
+ <el-form-item :label="$t('character.personality')">
+ <el-input v-model="newCharacter.personality" type="textarea" :rows="3" :placeholder="$t('character.personality')" />
+ </el-form-item>
+ <el-form-item :label="$t('character.description')">
+ <el-input v-model="newCharacter.description" type="textarea" :rows="3" :placeholder="$t('common.description')" />
+ </el-form-item>
+ </el-form>
+ <template #footer>
+ <el-button @click="addCharacterDialogVisible = false">{{ $t('common.cancel') }}</el-button>
+ <el-button type="primary" @click="saveCharacter">{{ $t('common.confirm') }}</el-button>
+ </template>
+ </el-dialog>
+
+ <!-- 从剧本提取角色对话框 -->
+ <el-dialog
+ v-model="extractCharactersDialogVisible"
+ :title="$t('character.batchExtract')"
+ width="500px"
+ >
+ <el-form label-width="100px">
+ <el-form-item :label="$t('character.selectEpisodes')">
+ <div style="width: 100%">
+ <el-checkbox
+ v-model="selectAllEpisodes"
+ :indeterminate="isEpisodesIndeterminate"
+ @change="handleSelectAllEpisodes"
+ style="margin-bottom: 8px"
+ >{{ $t('common.selectAll') }}</el-checkbox>
+ <el-select
+ v-model="selectedExtractEpisodeIds"
+ multiple
+ collapse-tags
+ collapse-tags-tooltip
+ :placeholder="$t('common.pleaseSelect')"
+ style="width: 100%"
+ @change="handleEpisodeSelectionChange"
+ >
+ <el-option
+ v-for="ep in sortedEpisodes"
+ :key="ep.id"
+ :label="ep.title"
+ :value="ep.id"
+ />
+ </el-select>
+ </div>
+ </el-form-item>
+ <el-alert
+ :title="$t('character.batchExtractTip')"
+ type="info"
+ :closable="false"
+ show-icon
+ />
+ <div v-if="extractProgress.active" style="margin-top: 16px">
+ <el-progress :percentage="extractProgress.percent" :status="extractProgress.status" />
+ <p style="margin-top: 8px; color: var(--el-text-color-secondary); font-size: 13px">
+ {{ extractProgress.message }}
+ </p>
+ </div>
+ </el-form>
+ <template #footer>
+ <el-button @click="extractCharactersDialogVisible = false" :disabled="extractProgress.active">{{ $t('common.cancel') }}</el-button>
+ <el-button
+ type="primary"
+ @click="handleExtractCharacters"
+ :disabled="selectedExtractEpisodeIds.length === 0 || extractProgress.active"
+ :loading="extractProgress.active"
+ >{{ $t('prop.startExtract') }}</el-button>
+ </template>
+ </el-dialog>
</div>
</template>
<script setup lang="ts">
-import { computed } from 'vue'
+import { ref, computed, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
+import { ElMessage, ElMessageBox } from 'element-plus'
import { Document, Plus, Search, User, Edit, Delete, PictureFilled } from '@element-plus/icons-vue'
import { TabHeader, ActionButton, EmptyState } from '@/components/common'
import { getImageUrl } from '@/utils/image'
import { useFilteredList } from '@/composables/useFilteredList'
import { useBatchSelection } from '@/composables/useBatchSelection'
+import { useDramaStore } from '@/stores/drama'
+import { dramaAPI } from '@/api/drama'
+import { characterLibraryAPI } from '@/api/character-library'
+import { taskAPI } from '@/api/task'
import type { Character } from '@/types/drama'
const { t } = useI18n()
+const dramaStore = useDramaStore()
-const props = defineProps<{
- characters: Character[]
-}>()
+let pollingTimer: ReturnType<typeof setInterval> | null = null
-defineEmits<{
- extractCharacters: []
- addCharacter: []
- editCharacter: [character: Character]
- generateCharacterImage: [character: Character]
- deleteCharacter: [character: Character]
- batchDeleteCharacters: [characters: Character[]]
- batchGenerateCharacterImages: [characters: Character[]]
-}>()
+onUnmounted(() => {
+ if (pollingTimer) clearInterval(pollingTimer)
+})
-const charactersList = computed(() => props.characters)
+const charactersList = computed(() => dramaStore.characters)
+const sortedEpisodes = computed(() =>
+ [...dramaStore.episodes].sort((a, b) => a.episode_number - b.episode_number)
+)
-const hasImage = (character: Character) => !!(character.local_path || character.image_url)
+const hasCharacterImage = (character: { local_path?: string; image_url?: string }) => !!(character.local_path || character.image_url)
const roleChipClass = (role?: string) => {
if (role === 'main') return 'glass-chip-danger'
@@ -151,6 +263,275 @@ const {
selectedIds, isBatchMode, isAllSelected, isIndeterminate,
selectedItems, selectedCount, toggleItem, toggleAll, clearSelection,
} = useBatchSelection(filteredItems)
+
+// --- Dialog state ---
+const addCharacterDialogVisible = ref(false)
+const editingCharacter = ref<Character | null>(null)
+const newCharacter = ref({
+ name: '',
+ role: 'supporting',
+ appearance: '',
+ personality: '',
+ description: '',
+ image_url: '',
+ local_path: '',
+})
+
+const extractCharactersDialogVisible = ref(false)
+const selectedExtractEpisodeIds = ref<(string | number)[]>([])
+const selectAllEpisodes = ref(false)
+const isEpisodesIndeterminate = ref(false)
+const extractProgress = ref({
+ active: false,
+ percent: 0,
+ message: '',
+ status: '' as '' | 'success' | 'exception',
+})
+
+// --- Actions ---
+const reloadDrama = async () => {
+ await dramaStore.loadDrama(dramaStore.dramaId)
+}
+
+const startPolling = (callback: () => Promise<void>, maxAttempts = 20, interval = 3000) => {
+ if (pollingTimer) clearInterval(pollingTimer)
+ let attempts = 0
+ pollingTimer = setInterval(async () => {
+ attempts++
+ await callback()
+ if (attempts >= maxAttempts) {
+ if (pollingTimer) clearInterval(pollingTimer)
+ pollingTimer = null
+ }
+ }, interval)
+}
+
+const openAddCharacterDialog = () => {
+ editingCharacter.value = null
+ newCharacter.value = { name: '', role: 'supporting', appearance: '', personality: '', description: '', image_url: '', local_path: '' }
+ addCharacterDialogVisible.value = true
+}
+
+const editCharacter = (character: Character) => {
+ editingCharacter.value = character
+ newCharacter.value = {
+ name: character.name,
+ role: character.role || 'supporting',
+ appearance: character.appearance || '',
+ personality: character.personality || '',
+ description: character.description || '',
+ image_url: character.image_url || '',
+ local_path: character.local_path || '',
+ }
+ addCharacterDialogVisible.value = true
+}
+
+const handleCharacterAvatarSuccess = (response: any) => {
+ if (response.data && response.data.url) {
+ newCharacter.value.image_url = response.data.url
+ newCharacter.value.local_path = response.data.local_path || ''
+ }
+}
+
+const beforeAvatarUpload = (file: any) => {
+ const isImage = file.type.startsWith('image/')
+ const isLt10M = file.size / 1024 / 1024 < 10
+ if (!isImage) ElMessage.error(t('message.imageOnlyUpload'))
+ if (!isLt10M) ElMessage.error(t('message.imageSizeLimit'))
+ return isImage && isLt10M
+}
+
+const saveCharacter = async () => {
+ if (!newCharacter.value.name.trim()) {
+ ElMessage.warning(t('message.enterCharacterName'))
+ return
+ }
+
+ try {
+ if (editingCharacter.value) {
+ await dramaAPI.updateCharacter(editingCharacter.value.id, {
+ name: newCharacter.value.name,
+ role: newCharacter.value.role,
+ appearance: newCharacter.value.appearance,
+ personality: newCharacter.value.personality,
+ description: newCharacter.value.description,
+ image_url: newCharacter.value.image_url,
+ local_path: newCharacter.value.local_path,
+ })
+ ElMessage.success(t('message.characterUpdateSuccess'))
+ } else {
+ const allCharacters = [
+ ...dramaStore.characters.map((c) => ({
+ name: c.name,
+ role: c.role,
+ appearance: c.appearance,
+ personality: c.personality,
+ description: c.description,
+ image_url: c.image_url,
+ local_path: c.local_path,
+ })),
+ newCharacter.value,
+ ]
+ await dramaAPI.saveCharacters(dramaStore.dramaId, allCharacters)
+ ElMessage.success(t('message.characterAddSuccess'))
+ }
+
+ addCharacterDialogVisible.value = false
+ await reloadDrama()
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.operationFailed'))
+ }
+}
+
+const deleteCharacter = async (character: Character) => {
+ if (!character.id) {
+ ElMessage.error(t('message.characterIdNotExist'))
+ return
+ }
+
+ try {
+ await ElMessageBox.confirm(
+ t('message.characterDeleteConfirm', { name: character.name }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ await characterLibraryAPI.deleteCharacter(character.id)
+ ElMessage.success(t('message.characterDeleted'))
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const generateCharacterImage = async (character: Character) => {
+ try {
+ await characterLibraryAPI.generateCharacterImage(character.id)
+ ElMessage.success(t('message.imageTaskSubmitted'))
+ startPolling(reloadDrama)
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.generateFailed'))
+ }
+}
+
+const batchDeleteCharacters = async () => {
+ try {
+ await ElMessageBox.confirm(
+ t('common.batchDeleteConfirm', { count: selectedCount.value }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ for (const character of selectedItems.value) {
+ await characterLibraryAPI.deleteCharacter(character.id)
+ }
+ ElMessage.success(t('message.batchDeleteSuccess'))
+ clearSelection()
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const batchGenerateCharacterImages = async () => {
+ try {
+ const ids = selectedItems.value.map(c => c.id.toString())
+ await characterLibraryAPI.batchGenerateCharacterImages(ids)
+ ElMessage.success(t('message.imageTaskSubmitted'))
+ clearSelection()
+ startPolling(reloadDrama)
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.generateFailed'))
+ }
+}
+
+// --- Extract characters ---
+const openExtractCharacterDialog = () => {
+ extractCharactersDialogVisible.value = true
+ selectedExtractEpisodeIds.value = []
+ selectAllEpisodes.value = false
+ isEpisodesIndeterminate.value = false
+ extractProgress.value = { active: false, percent: 0, message: '', status: '' }
+}
+
+const handleSelectAllEpisodes = (val: boolean) => {
+ selectedExtractEpisodeIds.value = val ? sortedEpisodes.value.map(ep => ep.id) : []
+ isEpisodesIndeterminate.value = false
+}
+
+const handleEpisodeSelectionChange = (val: (string | number)[]) => {
+ const total = sortedEpisodes.value.length
+ selectAllEpisodes.value = val.length === total
+ isEpisodesIndeterminate.value = val.length > 0 && val.length < total
+}
+
+const handleExtractCharacters = async () => {
+ if (selectedExtractEpisodeIds.value.length === 0) return
+
+ try {
+ extractProgress.value = { active: true, percent: 0, message: t('character.extracting'), status: '' }
+
+ const res = await characterLibraryAPI.batchExtractFromEpisodes(
+ dramaStore.dramaId,
+ selectedExtractEpisodeIds.value.map(Number),
+ )
+
+ const taskId = res.task_id
+
+ const pollInterval = setInterval(async () => {
+ try {
+ const task = await taskAPI.getStatus(taskId)
+ if (task.progress !== undefined) {
+ extractProgress.value.percent = task.progress
+ }
+ if (task.message) {
+ extractProgress.value.message = task.message
+ }
+
+ if (task.status === 'completed') {
+ clearInterval(pollInterval)
+ const result = typeof task.result === 'string' ? JSON.parse(task.result) : task.result
+ extractProgress.value = {
+ active: false,
+ percent: 100,
+ message: t('character.extractComplete', {
+ characters: result?.characters || 0,
+ scenes: result?.dedup_scenes || 0,
+ }),
+ status: 'success',
+ }
+ await reloadDrama()
+ } else if (task.status === 'failed') {
+ clearInterval(pollInterval)
+ extractProgress.value = {
+ active: false,
+ percent: 0,
+ message: task.error || t('common.failed'),
+ status: 'exception',
+ }
+ }
+ } catch {
+ clearInterval(pollInterval)
+ extractProgress.value = { active: false, percent: 0, message: t('common.failed'), status: 'exception' }
+ }
+ }, 3000)
+ } catch (error: any) {
+ extractProgress.value = { active: false, percent: 0, message: '', status: '' }
+ ElMessage.error(error.message || t('message.extractFailed'))
+ }
+}
</script>
<style scoped>
diff --git a/web/src/views/drama/management/EpisodesTab.vue b/web/src/views/drama/management/EpisodesTab.vue
index 4a36c4b..553578c 100644
--- a/web/src/views/drama/management/EpisodesTab.vue
+++ b/web/src/views/drama/management/EpisodesTab.vue
@@ -4,12 +4,12 @@
<template #actions>
<el-button
:icon="Upload"
- @click="$emit('uploadNovel')"
+ @click="showUploadNovel = true"
>{{ $t('drama.management.uploadNovel') }}</el-button>
<el-button
type="primary"
:icon="Plus"
- @click="$emit('createEpisode')"
+ @click="createEpisode"
>{{ $t('drama.management.createEpisode') }}</el-button>
</template>
<template #filter>
@@ -38,7 +38,7 @@
v-for="episode in filteredItems"
:key="episode.id"
class="list-row glass-list-row"
- @click="$emit('enterEpisode', episode)"
+ @click="enterEpisode(episode)"
>
<div class="row-thumb row-thumb-icon">
<el-icon :size="20"><DocumentIcon /></el-icon>
@@ -58,8 +58,8 @@
</div>
</div>
<div class="row-actions" @click.stop>
- <ActionButton :icon="Edit" :tooltip="$t('drama.management.goToEdit')" variant="primary" @click="$emit('enterEpisode', episode)" />
- <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="$emit('deleteEpisode', episode)" />
+ <ActionButton :icon="Edit" :tooltip="$t('drama.management.goToEdit')" variant="primary" @click="enterEpisode(episode)" />
+ <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="deleteEpisode(episode)" />
</div>
</div>
</div>
@@ -70,7 +70,7 @@
:description="$t('drama.management.emptyTip')"
:icon="DocumentIcon"
>
- <el-button type="primary" :icon="Plus" @click="$emit('createEpisode')">{{ $t('drama.management.createEpisode') }}</el-button>
+ <el-button type="primary" :icon="Plus" @click="createEpisode">{{ $t('drama.management.createEpisode') }}</el-button>
</EmptyState>
<EmptyState
@@ -79,34 +79,101 @@
:description="$t('common.noData')"
:icon="Search"
/>
+
+ <!-- 上传小说对话框 -->
+ <UploadNovelDialog
+ v-model="showUploadNovel"
+ :drama-id="dramaStore.dramaId"
+ :existing-episode-count="episodes.length"
+ @success="reloadDrama"
+ />
</div>
</template>
<script setup lang="ts">
-import { computed } from 'vue'
+import { computed, ref } from 'vue'
+import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
+import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Upload, Search, Document as DocumentIcon, Edit, Delete } from '@element-plus/icons-vue'
import { TabHeader, ActionButton, EmptyState } from '@/components/common'
import { useFilteredList } from '@/composables/useFilteredList'
+import { useDramaStore } from '@/stores/drama'
+import { dramaAPI } from '@/api/drama'
+import UploadNovelDialog from '../components/UploadNovelDialog.vue'
import type { Episode } from '@/types/drama'
const { t } = useI18n()
+const router = useRouter()
+const dramaStore = useDramaStore()
-const props = defineProps<{
- episodes: Episode[]
-}>()
+const showUploadNovel = ref(false)
-defineEmits<{
- createEpisode: []
- enterEpisode: [episode: Episode]
- deleteEpisode: [episode: Episode]
- uploadNovel: []
-}>()
+const episodes = computed(() => dramaStore.episodes)
const sortedEpisodes = computed(() =>
- [...props.episodes].sort((a, b) => a.episode_number - b.episode_number)
+ [...episodes.value].sort((a, b) => a.episode_number - b.episode_number)
)
+const createEpisode = () => {
+ const nextEpisodeNumber = episodes.value.length + 1
+ router.push({
+ name: 'EpisodeWorkbench',
+ params: {
+ id: dramaStore.dramaId,
+ episodeNumber: nextEpisodeNumber,
+ },
+ })
+}
+
+const enterEpisode = (episode: Episode) => {
+ router.push({
+ name: 'EpisodeWorkbench',
+ params: {
+ id: dramaStore.dramaId,
+ episodeNumber: episode.episode_number,
+ },
+ })
+}
+
+const deleteEpisode = async (episode: Episode) => {
+ try {
+ await ElMessageBox.confirm(
+ t('message.episodeDeleteConfirm', { number: episode.episode_number }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ const existingEpisodes = dramaStore.episodes
+ const updatedEpisodes = existingEpisodes
+ .filter((ep) => ep.episode_number !== episode.episode_number)
+ .map((ep) => ({
+ episode_number: ep.episode_number,
+ title: ep.title,
+ script_content: ep.script_content,
+ description: ep.description,
+ duration: ep.duration,
+ status: ep.status,
+ }))
+
+ await dramaAPI.saveEpisodes(dramaStore.dramaId, updatedEpisodes)
+ ElMessage.success(t('message.episodeDeleteSuccess', { number: episode.episode_number }))
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const reloadDrama = async () => {
+ await dramaStore.loadDrama(dramaStore.dramaId)
+}
+
const getEpisodeStatus = (episode: Episode) => {
if (episode.shots && episode.shots.length > 0) return 'split'
if (episode.script_content) return 'created'
diff --git a/web/src/views/drama/management/OverviewTab.vue b/web/src/views/drama/management/OverviewTab.vue
index 182094b..782ab1b 100644
--- a/web/src/views/drama/management/OverviewTab.vue
+++ b/web/src/views/drama/management/OverviewTab.vue
@@ -50,7 +50,7 @@
<el-button
type="primary"
:icon="Plus"
- @click="$emit('createEpisode')"
+ @click="createEpisode"
>
{{ $t("drama.management.createFirstEpisode") }}
</el-button>
@@ -92,24 +92,33 @@
</template>
<script setup lang="ts">
+import { computed } from 'vue'
+import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { Document, User, Picture, Plus, Box } from '@element-plus/icons-vue'
import { StatCard, EmptyState } from '@/components/common'
-import type { Drama } from '@/types/drama'
+import { useDramaStore } from '@/stores/drama'
const { t } = useI18n()
-
-const props = defineProps<{
- drama: Drama | null
- episodesCount: number
- charactersCount: number
- scenesCount: number
- propsCount: number
-}>()
-
-defineEmits<{
- createEpisode: []
-}>()
+const router = useRouter()
+const dramaStore = useDramaStore()
+
+const drama = computed(() => dramaStore.currentDrama)
+const episodesCount = computed(() => dramaStore.episodes.length)
+const charactersCount = computed(() => dramaStore.characters.length)
+const scenesCount = computed(() => dramaStore.scenes.length)
+const propsCount = computed(() => dramaStore.props.length)
+
+const createEpisode = () => {
+ const nextEpisodeNumber = episodesCount.value + 1
+ router.push({
+ name: 'EpisodeWorkbench',
+ params: {
+ id: dramaStore.dramaId,
+ episodeNumber: nextEpisodeNumber,
+ },
+ })
+}
const getStatusType = (status?: string) => {
const map: Record<string, any> = {
diff --git a/web/src/views/drama/management/PropsTab.vue b/web/src/views/drama/management/PropsTab.vue
index 32b6453..6a1d2ff 100644
--- a/web/src/views/drama/management/PropsTab.vue
+++ b/web/src/views/drama/management/PropsTab.vue
@@ -9,12 +9,12 @@
>{{ $t('common.batchMode') }}</el-button>
<el-button
:icon="Document"
- @click="$emit('extractProps')"
+ @click="openExtractDialog"
>{{ $t('prop.extract') }}</el-button>
<el-button
type="primary"
:icon="Plus"
- @click="$emit('addProp')"
+ @click="openAddPropDialog"
>{{ $t('common.add') }}</el-button>
</template>
<template #filter>
@@ -53,12 +53,12 @@
size="small"
type="danger"
:disabled="selectedCount === 0"
- @click="$emit('batchDeleteProps', selectedItems)"
+ @click="batchDeleteProps"
>{{ $t('common.batchDelete') }}</el-button>
<el-button
size="small"
:disabled="selectedCount === 0"
- @click="$emit('batchGeneratePropImages', selectedItems)"
+ @click="batchGeneratePropImages"
>{{ $t('common.batchGenerate') }}</el-button>
<el-button size="small" @click="clearSelection">{{ $t('common.cancelBatch') }}</el-button>
</div>
@@ -68,7 +68,7 @@
v-for="prop in filteredItems"
:key="prop.id"
class="list-row glass-list-row"
- @click="$emit('editProp', prop)"
+ @click="editProp(prop)"
>
<el-checkbox
v-if="isBatchMode"
@@ -90,9 +90,9 @@
</div>
</div>
<div class="row-actions" @click.stop>
- <ActionButton :icon="Edit" :tooltip="$t('common.edit')" variant="primary" @click="$emit('editProp', prop)" />
- <ActionButton :icon="PictureFilled" :tooltip="$t('prop.generateImage')" :disabled="!prop.prompt" @click="$emit('generatePropImage', prop)" />
- <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="$emit('deleteProp', prop)" />
+ <ActionButton :icon="Edit" :tooltip="$t('common.edit')" variant="primary" @click="editProp(prop)" />
+ <ActionButton :icon="PictureFilled" :tooltip="$t('prop.generateImage')" :disabled="!prop.prompt" @click="generatePropImage(prop)" />
+ <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="deleteProp(prop)" />
</div>
</div>
</div>
@@ -103,7 +103,7 @@
:description="$t('prop.emptyTip')"
:icon="Box"
>
- <el-button type="primary" :icon="Plus" @click="$emit('addProp')">{{ $t('common.add') }}</el-button>
+ <el-button type="primary" :icon="Plus" @click="openAddPropDialog">{{ $t('common.add') }}</el-button>
</EmptyState>
<EmptyState
@@ -112,46 +112,150 @@
:description="$t('common.noData')"
:icon="Search"
/>
+
+ <!-- 添加/编辑道具对话框 -->
+ <el-dialog
+ v-model="addPropDialogVisible"
+ :title="editingProp ? $t('common.edit') : $t('common.add')"
+ width="600px"
+ >
+ <el-form :model="newProp" label-width="100px">
+ <el-form-item :label="$t('common.image')">
+ <el-upload
+ class="avatar-uploader"
+ :action="`/api/v1/upload/image`"
+ :show-file-list="false"
+ :on-success="handlePropImageSuccess"
+ :before-upload="beforeAvatarUpload"
+ >
+ <img
+ v-if="hasImage(newProp)"
+ :src="getImageUrl(newProp)"
+ class="avatar"
+ style="width: 100px; height: 100px; object-fit: cover"
+ />
+ <el-icon
+ v-else
+ class="avatar-uploader-icon"
+ style="border: 1px dashed #d9d9d9; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; width: 100px; height: 100px; font-size: 28px; color: #8c939d; text-align: center; line-height: 100px;"
+ ><Plus /></el-icon>
+ </el-upload>
+ </el-form-item>
+ <el-form-item :label="$t('prop.name')">
+ <el-input v-model="newProp.name" :placeholder="$t('prop.name')" />
+ </el-form-item>
+ <el-form-item :label="$t('prop.type')">
+ <el-input v-model="newProp.type" :placeholder="$t('prop.typePlaceholder')" />
+ </el-form-item>
+ <el-form-item :label="$t('prop.description')">
+ <el-input v-model="newProp.description" type="textarea" :rows="3" :placeholder="$t('prop.description')" />
+ </el-form-item>
+ <el-form-item :label="$t('prop.prompt')">
+ <el-input v-model="newProp.prompt" type="textarea" :rows="3" :placeholder="$t('prop.promptPlaceholder')" />
+ </el-form-item>
+ </el-form>
+ <template #footer>
+ <el-button @click="addPropDialogVisible = false">{{ $t('common.cancel') }}</el-button>
+ <el-button type="primary" @click="saveProp">{{ $t('common.confirm') }}</el-button>
+ </template>
+ </el-dialog>
+
+ <!-- 从剧本提取道具对话框 -->
+ <el-dialog
+ v-model="extractPropsDialogVisible"
+ :title="$t('prop.batchExtract')"
+ width="500px"
+ >
+ <el-form label-width="100px">
+ <el-form-item :label="$t('prop.selectEpisodes')">
+ <div style="width: 100%">
+ <el-checkbox
+ v-model="selectAllPropsEpisodes"
+ :indeterminate="isPropsIndeterminate"
+ @change="handleSelectAllPropsEpisodes"
+ style="margin-bottom: 8px"
+ >{{ $t('common.selectAll') }}</el-checkbox>
+ <el-select
+ v-model="selectedPropsEpisodeIds"
+ multiple
+ collapse-tags
+ collapse-tags-tooltip
+ :placeholder="$t('common.pleaseSelect')"
+ style="width: 100%"
+ @change="handlePropsEpisodeSelectionChange"
+ >
+ <el-option
+ v-for="ep in sortedEpisodes"
+ :key="ep.id"
+ :label="ep.title"
+ :value="ep.id"
+ />
+ </el-select>
+ </div>
+ </el-form-item>
+ <el-alert
+ :title="$t('prop.batchExtractTip')"
+ type="info"
+ :closable="false"
+ show-icon
+ />
+ <div v-if="propsExtractProgress.active" style="margin-top: 16px">
+ <el-progress :percentage="propsExtractProgress.percent" :status="propsExtractProgress.status" />
+ <p style="margin-top: 8px; color: var(--el-text-color-secondary); font-size: 13px">
+ {{ propsExtractProgress.message }}
+ </p>
+ </div>
+ </el-form>
+ <template #footer>
+ <el-button @click="extractPropsDialogVisible = false" :disabled="propsExtractProgress.active">{{ $t('common.cancel') }}</el-button>
+ <el-button
+ type="primary"
+ @click="handleExtractProps"
+ :disabled="selectedPropsEpisodeIds.length === 0 || propsExtractProgress.active"
+ :loading="propsExtractProgress.active"
+ >{{ $t('prop.startExtract') }}</el-button>
+ </template>
+ </el-dialog>
</div>
</template>
<script setup lang="ts">
-import { computed } from 'vue'
+import { ref, computed, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
+import { ElMessage, ElMessageBox } from 'element-plus'
import { Document, Plus, Search, Box, Edit, Delete, PictureFilled } from '@element-plus/icons-vue'
import { TabHeader, ActionButton, EmptyState } from '@/components/common'
import { getImageUrl } from '@/utils/image'
import { useFilteredList } from '@/composables/useFilteredList'
import { useBatchSelection } from '@/composables/useBatchSelection'
+import { useDramaStore } from '@/stores/drama'
+import { propAPI } from '@/api/prop'
+import { taskAPI } from '@/api/task'
import type { Prop } from '@/types/prop'
const { t } = useI18n()
+const dramaStore = useDramaStore()
-const props = defineProps<{
- propsList: Prop[]
-}>()
+let pollingTimer: ReturnType<typeof setInterval> | null = null
-defineEmits<{
- extractProps: []
- addProp: []
- editProp: [prop: Prop]
- generatePropImage: [prop: Prop]
- deleteProp: [prop: Prop]
- batchDeleteProps: [props: Prop[]]
- batchGeneratePropImages: [props: Prop[]]
-}>()
+onUnmounted(() => {
+ if (pollingTimer) clearInterval(pollingTimer)
+})
-const propsListRef = computed(() => props.propsList)
+const propsList = computed(() => dramaStore.props)
+const sortedEpisodes = computed(() =>
+ [...dramaStore.episodes].sort((a, b) => a.episode_number - b.episode_number)
+)
-const hasImage = (prop: Prop) => !!prop.image_url
+const hasImage = (prop: { image_url?: string }) => !!prop.image_url
const propTypes = computed(() => {
- const types = new Set(props.propsList.map(p => p.type).filter(Boolean))
+ const types = new Set(dramaStore.props.map(p => p.type).filter(Boolean))
return Array.from(types)
})
const { searchQuery, filterValue, filteredItems } = useFilteredList({
- items: propsListRef,
+ items: propsList,
searchFields: ['name', 'description'] as (keyof Prop)[],
filterField: 'type' as keyof Prop,
})
@@ -160,6 +264,267 @@ const {
selectedIds, isBatchMode, isAllSelected, isIndeterminate,
selectedItems, selectedCount, toggleItem, toggleAll, clearSelection,
} = useBatchSelection(filteredItems)
+
+// --- Dialog state ---
+const addPropDialogVisible = ref(false)
+const editingProp = ref<Prop | null>(null)
+const newProp = ref({
+ name: '',
+ description: '',
+ prompt: '',
+ type: '',
+ image_url: '',
+ local_path: '',
+})
+
+const extractPropsDialogVisible = ref(false)
+const selectedPropsEpisodeIds = ref<(string | number)[]>([])
+const selectAllPropsEpisodes = ref(false)
+const isPropsIndeterminate = ref(false)
+const propsExtractProgress = ref({
+ active: false,
+ percent: 0,
+ message: '',
+ status: '' as '' | 'success' | 'exception',
+})
+
+// --- Actions ---
+const reloadDrama = async () => {
+ await dramaStore.loadDrama(dramaStore.dramaId)
+}
+
+const startPolling = (callback: () => Promise<void>, maxAttempts = 20, interval = 3000) => {
+ if (pollingTimer) clearInterval(pollingTimer)
+ let attempts = 0
+ pollingTimer = setInterval(async () => {
+ attempts++
+ await callback()
+ if (attempts >= maxAttempts) {
+ if (pollingTimer) clearInterval(pollingTimer)
+ pollingTimer = null
+ }
+ }, interval)
+}
+
+const openAddPropDialog = () => {
+ editingProp.value = null
+ newProp.value = { name: '', description: '', prompt: '', type: '', image_url: '', local_path: '' }
+ addPropDialogVisible.value = true
+}
+
+const editProp = (prop: Prop) => {
+ editingProp.value = prop
+ newProp.value = {
+ name: prop.name,
+ description: prop.description || '',
+ prompt: prop.prompt || '',
+ type: prop.type || '',
+ image_url: prop.image_url || '',
+ local_path: prop.local_path || '',
+ }
+ addPropDialogVisible.value = true
+}
+
+const handlePropImageSuccess = (response: any) => {
+ if (response.data && response.data.url) {
+ newProp.value.image_url = response.data.url
+ newProp.value.local_path = response.data.local_path || ''
+ }
+}
+
+const beforeAvatarUpload = (file: any) => {
+ const isImage = file.type.startsWith('image/')
+ const isLt10M = file.size / 1024 / 1024 < 10
+ if (!isImage) ElMessage.error(t('message.imageOnlyUpload'))
+ if (!isLt10M) ElMessage.error(t('message.imageSizeLimit'))
+ return isImage && isLt10M
+}
+
+const saveProp = async () => {
+ if (!newProp.value.name.trim()) {
+ ElMessage.warning(t('message.enterPropName'))
+ return
+ }
+
+ try {
+ const propData = {
+ drama_id: dramaStore.dramaId,
+ name: newProp.value.name,
+ description: newProp.value.description,
+ prompt: newProp.value.prompt,
+ type: newProp.value.type,
+ image_url: newProp.value.image_url,
+ local_path: newProp.value.local_path,
+ }
+
+ if (editingProp.value) {
+ await propAPI.update(editingProp.value.id, propData)
+ ElMessage.success(t('message.propUpdateSuccess'))
+ } else {
+ await propAPI.create(propData as any)
+ ElMessage.success(t('message.propAddSuccess'))
+ }
+
+ addPropDialogVisible.value = false
+ await reloadDrama()
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.operationFailed'))
+ }
+}
+
+const deleteProp = async (prop: Prop) => {
+ try {
+ await ElMessageBox.confirm(
+ t('message.propDeleteConfirm', { name: prop.name }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ await propAPI.delete(prop.id)
+ ElMessage.success(t('message.propDeleted'))
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const generatePropImage = async (prop: Prop) => {
+ if (!prop.prompt) {
+ ElMessage.warning(t('message.setPropPromptFirst'))
+ editProp(prop)
+ return
+ }
+
+ try {
+ await propAPI.generateImage(prop.id)
+ ElMessage.success(t('message.imageTaskSubmitted'))
+ startPolling(reloadDrama)
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.generateFailed'))
+ }
+}
+
+const batchDeleteProps = async () => {
+ try {
+ await ElMessageBox.confirm(
+ t('common.batchDeleteConfirm', { count: selectedCount.value }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ for (const prop of selectedItems.value) {
+ await propAPI.delete(prop.id)
+ }
+ ElMessage.success(t('message.batchDeleteSuccess'))
+ clearSelection()
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const batchGeneratePropImages = async () => {
+ try {
+ for (const prop of selectedItems.value) {
+ if (prop.prompt) {
+ await propAPI.generateImage(prop.id)
+ }
+ }
+ ElMessage.success(t('message.imageTaskSubmitted'))
+ clearSelection()
+ startPolling(reloadDrama)
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.generateFailed'))
+ }
+}
+
+// --- Extract props ---
+const openExtractDialog = () => {
+ extractPropsDialogVisible.value = true
+ selectedPropsEpisodeIds.value = []
+ selectAllPropsEpisodes.value = false
+ isPropsIndeterminate.value = false
+ propsExtractProgress.value = { active: false, percent: 0, message: '', status: '' }
+}
+
+const handleSelectAllPropsEpisodes = (val: boolean) => {
+ selectedPropsEpisodeIds.value = val ? sortedEpisodes.value.map(ep => ep.id) : []
+ isPropsIndeterminate.value = false
+}
+
+const handlePropsEpisodeSelectionChange = (val: (string | number)[]) => {
+ const total = sortedEpisodes.value.length
+ selectAllPropsEpisodes.value = val.length === total
+ isPropsIndeterminate.value = val.length > 0 && val.length < total
+}
+
+const handleExtractProps = async () => {
+ if (selectedPropsEpisodeIds.value.length === 0) return
+
+ try {
+ propsExtractProgress.value = { active: true, percent: 0, message: t('prop.extracting') || t('character.extracting'), status: '' }
+
+ const res = await propAPI.batchExtractFromEpisodes(
+ dramaStore.dramaId,
+ selectedPropsEpisodeIds.value.map(Number),
+ )
+
+ const taskId = res.task_id
+
+ const pollInterval = setInterval(async () => {
+ try {
+ const task = await taskAPI.getStatus(taskId)
+ if (task.progress !== undefined) {
+ propsExtractProgress.value.percent = task.progress
+ }
+ if (task.message) {
+ propsExtractProgress.value.message = task.message
+ }
+
+ if (task.status === 'completed') {
+ clearInterval(pollInterval)
+ const result = typeof task.result === 'string' ? JSON.parse(task.result) : task.result
+ propsExtractProgress.value = {
+ active: false,
+ percent: 100,
+ message: t('prop.extractComplete', {
+ props: result?.props || 0,
+ dedup: result?.dedup_props || 0,
+ }),
+ status: 'success',
+ }
+ await reloadDrama()
+ } else if (task.status === 'failed') {
+ clearInterval(pollInterval)
+ propsExtractProgress.value = {
+ active: false,
+ percent: 0,
+ message: task.error || t('common.failed'),
+ status: 'exception',
+ }
+ }
+ } catch {
+ clearInterval(pollInterval)
+ propsExtractProgress.value = { active: false, percent: 0, message: t('common.failed'), status: 'exception' }
+ }
+ }, 3000)
+ } catch (error: any) {
+ propsExtractProgress.value = { active: false, percent: 0, message: '', status: '' }
+ ElMessage.error(error.message || t('common.failed'))
+ }
+}
</script>
<style scoped>
diff --git a/web/src/views/drama/management/ScenesTab.vue b/web/src/views/drama/management/ScenesTab.vue
index fd369fc..1edfbe2 100644
--- a/web/src/views/drama/management/ScenesTab.vue
+++ b/web/src/views/drama/management/ScenesTab.vue
@@ -9,12 +9,12 @@
>{{ $t('common.batchMode') }}</el-button>
<el-button
:icon="Document"
- @click="$emit('extractScenes')"
+ @click="openExtractSceneDialog"
>{{ $t('scene.extractTitle') }}</el-button>
<el-button
type="primary"
:icon="Plus"
- @click="$emit('addScene')"
+ @click="openAddSceneDialog"
>{{ $t('scene.addScene') }}</el-button>
</template>
<template #filter>
@@ -40,12 +40,12 @@
size="small"
type="danger"
:disabled="selectedCount === 0"
- @click="$emit('batchDeleteScenes', selectedItems)"
+ @click="batchDeleteScenes"
>{{ $t('common.batchDelete') }}</el-button>
<el-button
size="small"
:disabled="selectedCount === 0"
- @click="$emit('batchGenerateSceneImages', selectedItems)"
+ @click="batchGenerateSceneImages"
>{{ $t('common.batchGenerate') }}</el-button>
<el-button size="small" @click="clearSelection">{{ $t('common.cancelBatch') }}</el-button>
</div>
@@ -55,7 +55,7 @@
v-for="scene in filteredItems"
:key="scene.id"
class="list-row glass-list-row"
- @click="$emit('editScene', scene)"
+ @click="editScene(scene)"
>
<el-checkbox
v-if="isBatchMode"
@@ -63,8 +63,8 @@
@change="toggleItem(scene.id)"
@click.stop
/>
- <div class="row-thumb" :class="{ 'row-thumb-icon': !hasImage(scene) }">
- <img v-if="hasImage(scene)" :src="getImageUrl(scene)" :alt="scene.title || scene.location" />
+ <div class="row-thumb" :class="{ 'row-thumb-icon': !hasSceneImage(scene) }">
+ <img v-if="hasSceneImage(scene)" :src="getImageUrl(scene)" :alt="scene.title || scene.location" />
<el-icon v-else :size="20"><Picture /></el-icon>
</div>
<div class="row-body">
@@ -77,9 +77,9 @@
</div>
</div>
<div class="row-actions" @click.stop>
- <ActionButton :icon="Edit" :tooltip="$t('common.edit')" variant="primary" @click="$emit('editScene', scene)" />
- <ActionButton :icon="PictureFilled" :tooltip="$t('prop.generateImage')" @click="$emit('generateSceneImage', scene)" />
- <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="$emit('deleteScene', scene)" />
+ <ActionButton :icon="Edit" :tooltip="$t('common.edit')" variant="primary" @click="editScene(scene)" />
+ <ActionButton :icon="PictureFilled" :tooltip="$t('prop.generateImage')" @click="generateSceneImage(scene)" />
+ <ActionButton :icon="Delete" :tooltip="$t('common.delete')" variant="danger" @click="deleteScene(scene)" />
</div>
</div>
</div>
@@ -90,7 +90,7 @@
:description="$t('scene.emptyTip')"
:icon="Picture"
>
- <el-button type="primary" :icon="Plus" @click="$emit('addScene')">{{ $t('scene.addScene') }}</el-button>
+ <el-button type="primary" :icon="Plus" @click="openAddSceneDialog">{{ $t('scene.addScene') }}</el-button>
</EmptyState>
<EmptyState
@@ -99,41 +99,139 @@
:description="$t('common.noData')"
:icon="Search"
/>
+
+ <!-- 添加/编辑场景对话框 -->
+ <el-dialog
+ v-model="addSceneDialogVisible"
+ :title="editingScene ? $t('common.edit') : $t('common.add')"
+ width="600px"
+ >
+ <el-form :model="newScene" label-width="100px">
+ <el-form-item :label="$t('common.image')">
+ <el-upload
+ class="avatar-uploader"
+ :action="`/api/v1/upload/image`"
+ :show-file-list="false"
+ :on-success="handleSceneImageSuccess"
+ :before-upload="beforeAvatarUpload"
+ >
+ <img
+ v-if="hasSceneImage(newScene)"
+ :src="getImageUrl(newScene)"
+ class="avatar"
+ style="width: 160px; height: 90px; object-fit: cover"
+ />
+ <el-icon
+ v-else
+ class="avatar-uploader-icon"
+ style="border: 1px dashed #d9d9d9; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; width: 160px; height: 90px; font-size: 28px; color: #8c939d; text-align: center; line-height: 90px;"
+ ><Plus /></el-icon>
+ </el-upload>
+ </el-form-item>
+ <el-form-item :label="$t('scene.location')">
+ <el-input v-model="newScene.location" :placeholder="$t('scene.location')" />
+ </el-form-item>
+ <el-form-item :label="$t('scene.prompt')">
+ <el-input v-model="newScene.prompt" type="textarea" :rows="3" :placeholder="$t('scene.prompt')" />
+ </el-form-item>
+ </el-form>
+ <template #footer>
+ <el-button @click="addSceneDialogVisible = false">{{ $t('common.cancel') }}</el-button>
+ <el-button type="primary" @click="saveScene">{{ $t('common.confirm') }}</el-button>
+ </template>
+ </el-dialog>
+
+ <!-- 从剧本提取场景对话框 -->
+ <el-dialog
+ v-model="extractScenesDialogVisible"
+ :title="$t('scene.batchExtract')"
+ width="500px"
+ >
+ <el-form label-width="100px">
+ <el-form-item :label="$t('scene.selectEpisodes')">
+ <div style="width: 100%">
+ <el-checkbox
+ v-model="selectAllScenesEpisodes"
+ :indeterminate="isScenesIndeterminate"
+ @change="handleSelectAllScenesEpisodes"
+ style="margin-bottom: 8px"
+ >{{ $t('common.selectAll') }}</el-checkbox>
+ <el-select
+ v-model="selectedScenesEpisodeIds"
+ multiple
+ collapse-tags
+ collapse-tags-tooltip
+ :placeholder="$t('common.pleaseSelect')"
+ style="width: 100%"
+ @change="handleScenesEpisodeSelectionChange"
+ >
+ <el-option
+ v-for="ep in sortedEpisodes"
+ :key="ep.id"
+ :label="ep.title"
+ :value="ep.id"
+ />
+ </el-select>
+ </div>
+ </el-form-item>
+ <el-alert
+ :title="$t('scene.batchExtractTip')"
+ type="info"
+ :closable="false"
+ show-icon
+ />
+ <div v-if="scenesExtractProgress.active" style="margin-top: 16px">
+ <el-progress :percentage="scenesExtractProgress.percent" :status="scenesExtractProgress.status" />
+ <p style="margin-top: 8px; color: var(--el-text-color-secondary); font-size: 13px">
+ {{ scenesExtractProgress.message }}
+ </p>
+ </div>
+ </el-form>
+ <template #footer>
+ <el-button @click="extractScenesDialogVisible = false" :disabled="scenesExtractProgress.active">{{ $t('common.cancel') }}</el-button>
+ <el-button
+ type="primary"
+ @click="handleExtractScenes"
+ :disabled="selectedScenesEpisodeIds.length === 0 || scenesExtractProgress.active"
+ :loading="scenesExtractProgress.active"
+ >{{ $t('prop.startExtract') }}</el-button>
+ </template>
+ </el-dialog>
</div>
</template>
<script setup lang="ts">
-import { computed } from 'vue'
+import { ref, computed, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
+import { ElMessage, ElMessageBox } from 'element-plus'
import { Document, Plus, Search, Picture, Edit, Delete, PictureFilled } from '@element-plus/icons-vue'
import { TabHeader, ActionButton, EmptyState } from '@/components/common'
import { getImageUrl } from '@/utils/image'
import { useFilteredList } from '@/composables/useFilteredList'
import { useBatchSelection } from '@/composables/useBatchSelection'
+import { useDramaStore } from '@/stores/drama'
+import { dramaAPI } from '@/api/drama'
+import { taskAPI } from '@/api/task'
import type { Scene } from '@/types/drama'
const { t } = useI18n()
+const dramaStore = useDramaStore()
-const props = defineProps<{
- scenes: Scene[]
-}>()
+let pollingTimer: ReturnType<typeof setInterval> | null = null
-defineEmits<{
- extractScenes: []
- addScene: []
- editScene: [scene: Scene]
- generateSceneImage: [scene: Scene]
- deleteScene: [scene: Scene]
- batchDeleteScenes: [scenes: Scene[]]
- batchGenerateSceneImages: [scenes: Scene[]]
-}>()
+onUnmounted(() => {
+ if (pollingTimer) clearInterval(pollingTimer)
+})
-const scenesList = computed(() => props.scenes)
+const scenes = computed(() => dramaStore.scenes)
+const sortedEpisodes = computed(() =>
+ [...dramaStore.episodes].sort((a, b) => a.episode_number - b.episode_number)
+)
-const hasImage = (scene: Scene) => !!(scene.local_path || scene.image_url)
+const hasSceneImage = (scene: { local_path?: string; image_url?: string }) => !!(scene.local_path || scene.image_url)
const { searchQuery, filteredItems } = useFilteredList({
- items: scenesList,
+ items: scenes,
searchFields: ['title', 'location', 'description'] as (keyof Scene)[],
})
@@ -141,6 +239,261 @@ const {
selectedIds, isBatchMode, isAllSelected, isIndeterminate,
selectedItems, selectedCount, toggleItem, toggleAll, clearSelection,
} = useBatchSelection(filteredItems)
+
+// --- Dialog state ---
+const addSceneDialogVisible = ref(false)
+const editingScene = ref<Scene | null>(null)
+const newScene = ref({
+ location: '',
+ prompt: '',
+ image_url: '',
+ local_path: '',
+})
+
+const extractScenesDialogVisible = ref(false)
+const selectedScenesEpisodeIds = ref<(string | number)[]>([])
+const selectAllScenesEpisodes = ref(false)
+const isScenesIndeterminate = ref(false)
+const scenesExtractProgress = ref({
+ active: false,
+ percent: 0,
+ message: '',
+ status: '' as '' | 'success' | 'exception',
+})
+
+// --- Actions ---
+const reloadDrama = async () => {
+ await dramaStore.loadDrama(dramaStore.dramaId)
+}
+
+const startPolling = (callback: () => Promise<void>, maxAttempts = 20, interval = 3000) => {
+ if (pollingTimer) clearInterval(pollingTimer)
+ let attempts = 0
+ pollingTimer = setInterval(async () => {
+ attempts++
+ await callback()
+ if (attempts >= maxAttempts) {
+ if (pollingTimer) clearInterval(pollingTimer)
+ pollingTimer = null
+ }
+ }, interval)
+}
+
+const openAddSceneDialog = () => {
+ editingScene.value = null
+ newScene.value = { location: '', prompt: '', image_url: '', local_path: '' }
+ addSceneDialogVisible.value = true
+}
+
+const editScene = (scene: Scene) => {
+ editingScene.value = scene
+ newScene.value = {
+ location: scene.location || scene.name || '',
+ prompt: scene.prompt || scene.description || '',
+ image_url: scene.image_url || '',
+ local_path: scene.local_path || '',
+ }
+ addSceneDialogVisible.value = true
+}
+
+const handleSceneImageSuccess = (response: any) => {
+ if (response.data && response.data.url) {
+ newScene.value.image_url = response.data.url
+ newScene.value.local_path = response.data.local_path || ''
+ }
+}
+
+const beforeAvatarUpload = (file: any) => {
+ const isImage = file.type.startsWith('image/')
+ const isLt10M = file.size / 1024 / 1024 < 10
+ if (!isImage) ElMessage.error(t('message.imageOnlyUpload'))
+ if (!isLt10M) ElMessage.error(t('message.imageSizeLimit'))
+ return isImage && isLt10M
+}
+
+const saveScene = async () => {
+ if (!newScene.value.location.trim()) {
+ ElMessage.warning(t('message.enterSceneName'))
+ return
+ }
+
+ try {
+ if (editingScene.value) {
+ await dramaAPI.updateScene(editingScene.value.id, {
+ location: newScene.value.location,
+ description: newScene.value.prompt,
+ image_url: newScene.value.image_url,
+ local_path: newScene.value.local_path,
+ })
+ } else {
+ await dramaAPI.createScene({
+ drama_id: Number(dramaStore.dramaId),
+ location: newScene.value.location,
+ prompt: newScene.value.prompt,
+ description: newScene.value.prompt,
+ image_url: newScene.value.image_url,
+ local_path: newScene.value.local_path,
+ })
+ }
+
+ ElMessage.success(t(editingScene.value ? 'message.sceneUpdateSuccess' : 'message.sceneAddSuccess'))
+ addSceneDialogVisible.value = false
+ await reloadDrama()
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.operationFailed'))
+ }
+}
+
+const deleteScene = async (scene: Scene) => {
+ if (!scene.id) {
+ ElMessage.error(t('message.sceneIdNotExist'))
+ return
+ }
+
+ try {
+ await ElMessageBox.confirm(
+ t('message.sceneDeleteConfirm', { name: scene.name || scene.location }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ await dramaAPI.deleteScene(scene.id.toString())
+ ElMessage.success(t('message.sceneDeleted'))
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const generateSceneImage = async (scene: Scene) => {
+ try {
+ await dramaAPI.generateSceneImage({ scene_id: scene.id })
+ ElMessage.success(t('message.imageTaskSubmitted'))
+ startPolling(reloadDrama)
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.generateFailed'))
+ }
+}
+
+const batchDeleteScenes = async () => {
+ try {
+ await ElMessageBox.confirm(
+ t('common.batchDeleteConfirm', { count: selectedCount.value }),
+ t('message.deleteConfirmTitle'),
+ {
+ confirmButtonText: t('common.confirm'),
+ cancelButtonText: t('common.cancel'),
+ type: 'warning',
+ },
+ )
+
+ for (const scene of selectedItems.value) {
+ await dramaAPI.deleteScene(scene.id.toString())
+ }
+ ElMessage.success(t('message.batchDeleteSuccess'))
+ clearSelection()
+ await reloadDrama()
+ } catch (error: any) {
+ if (error !== 'cancel') {
+ ElMessage.error(error.message || t('message.deleteFailed'))
+ }
+ }
+}
+
+const batchGenerateSceneImages = async () => {
+ try {
+ for (const scene of selectedItems.value) {
+ await dramaAPI.generateSceneImage({ scene_id: scene.id })
+ }
+ ElMessage.success(t('message.imageTaskSubmitted'))
+ clearSelection()
+ startPolling(reloadDrama)
+ } catch (error: any) {
+ ElMessage.error(error.message || t('message.generateFailed'))
+ }
+}
+
+// --- Extract scenes ---
+const openExtractSceneDialog = () => {
+ extractScenesDialogVisible.value = true
+ selectedScenesEpisodeIds.value = []
+ selectAllScenesEpisodes.value = false
+ isScenesIndeterminate.value = false
+ scenesExtractProgress.value = { active: false, percent: 0, message: '', status: '' }
+}
+
+const handleSelectAllScenesEpisodes = (val: boolean) => {
+ selectedScenesEpisodeIds.value = val ? sortedEpisodes.value.map(ep => ep.id) : []
+ isScenesIndeterminate.value = false
+}
+
+const handleScenesEpisodeSelectionChange = (val: (string | number)[]) => {
+ const total = sortedEpisodes.value.length
+ selectAllScenesEpisodes.value = val.length === total
+ isScenesIndeterminate.value = val.length > 0 && val.length < total
+}
+
+const handleExtractScenes = async () => {
+ if (selectedScenesEpisodeIds.value.length === 0) return
+
+ try {
+ scenesExtractProgress.value = { active: true, percent: 0, message: t('character.extracting'), status: '' }
+
+ const res = await dramaAPI.batchExtractBackgrounds(
+ dramaStore.dramaId,
+ selectedScenesEpisodeIds.value.map(Number),
+ )
+
+ const taskId = res.task_id
+
+ const pollInterval = setInterval(async () => {
+ try {
+ const task = await taskAPI.getStatus(taskId)
+ if (task.progress !== undefined) {
+ scenesExtractProgress.value.percent = task.progress
+ }
+ if (task.message) {
+ scenesExtractProgress.value.message = task.message
+ }
+
+ if (task.status === 'completed') {
+ clearInterval(pollInterval)
+ const result = typeof task.result === 'string' ? JSON.parse(task.result) : task.result
+ scenesExtractProgress.value = {
+ active: false,
+ percent: 100,
+ message: t('scene.extractComplete', {
+ scenes: result?.scenes || 0,
+ dedup: result?.dedup_scenes || 0,
+ }),
+ status: 'success',
+ }
+ await reloadDrama()
+ } else if (task.status === 'failed') {
+ clearInterval(pollInterval)
+ scenesExtractProgress.value = {
+ active: false,
+ percent: 0,
+ message: task.error || t('common.failed'),
+ status: 'exception',
+ }
+ }
+ } catch {
+ clearInterval(pollInterval)
+ scenesExtractProgress.value = { active: false, percent: 0, message: t('common.failed'), status: 'exception' }
+ }
+ }, 3000)
+ } catch (error: any) {
+ scenesExtractProgress.value = { active: false, percent: 0, message: '', status: '' }
+ ElMessage.error(error.message || t('message.extractFailed'))
+ }
+}
</script>
<style scoped>