feat: 剧本恢复操作持久展示后台状态
This commit is contained in:
1 parent
0017965fec
commit
204cf25aaa
1 file changed
+28
-7
@@ -2,7 +2,7 @@
|
||||
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
|
||||
import ActionMenu from '../../components/ui/ActionMenu.vue'
|
||||
import { NScrollbar, NCollapse, NCollapseItem, NProgress, NTab, NTabs, NTag } from 'naive-ui'
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ArrowRight, Check, Circle } from '@lucide/vue'
|
||||
import { EmptyState } from '../../components/ui'
|
||||
import { useProjectContext } from '../projects/context'
|
||||
@@ -13,6 +13,8 @@ import HistoryPanel from '../workflows/HistoryPanel.vue'
|
||||
import ConfirmAction from '../workflows/ConfirmAction.vue'
|
||||
import { downloadText } from '../../lib/format'
|
||||
import EpisodeReader from './EpisodeReader.vue'
|
||||
import { useWorkflowExecution } from '../workflows/execution'
|
||||
import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.vue'
|
||||
|
||||
/** 剧本创作工作区,正式数据库内容为准,checkpoint 只补充计划与恢复信息。 */
|
||||
const { project, checkpoints, refresh, error } = useProjectContext()
|
||||
@@ -22,7 +24,15 @@ const dramaRecords = computed(() => workflowCheckpoints(checkpoints.value, 'crea
|
||||
const state = computed(() => dramaRecords.value.at(-1)?.state)
|
||||
const episodes = computed(() => project.value?.episodes ?? [])
|
||||
const total = computed(() => state.value?.episodeCount)
|
||||
const operation = computed(() => getOperation(project.value!.id))
|
||||
const projectId = computed(() => project.value?.id ?? '')
|
||||
const operation = computed(() => getOperation(projectId.value))
|
||||
const backgroundExecution = useWorkflowExecution(projectId, 'create-drama')
|
||||
watch(
|
||||
() => backgroundExecution.query.data.value?.status,
|
||||
(status, previous) => {
|
||||
if ((status === 'completed' || status === 'failed') && status !== previous) void refresh()
|
||||
}
|
||||
)
|
||||
const complete = computed(() => project.value?.status === 'completed')
|
||||
const hasCheckpoint = computed(() => dramaRecords.value.length > 0)
|
||||
const canGenerate = computed(
|
||||
@@ -52,9 +62,11 @@ const stages = computed(() => [
|
||||
async function resume(action: 'resume-generation' | 'resume-rewrite') {
|
||||
if (!project.value || operation.value.pending || error.value) return
|
||||
const id = project.value.id
|
||||
await runOperation(id, action === 'resume-generation' ? '恢复剧集生成' : '恢复剧本改写', () =>
|
||||
projectsApi.resume(id, action)
|
||||
)
|
||||
await runOperation(id, action === 'resume-generation' ? '恢复剧集生成' : '恢复剧本改写', async () => {
|
||||
const started = await projectsApi.resume(id, action)
|
||||
await backgroundExecution.track(started.executionId)
|
||||
return started
|
||||
})
|
||||
await refresh()
|
||||
}
|
||||
|
||||
@@ -85,6 +97,15 @@ function exportScript() {
|
||||
</div>
|
||||
</div></div
|
||||
></template>
|
||||
<WorkflowExecutionPanel
|
||||
v-if="backgroundExecution.executionId.value"
|
||||
title="剧本创作后台任务"
|
||||
:execution="backgroundExecution.query.data.value"
|
||||
:loading="backgroundExecution.query.loading.value"
|
||||
:error="backgroundExecution.query.error.value"
|
||||
@refresh="backgroundExecution.query.refresh"
|
||||
@dismiss="backgroundExecution.dismiss"
|
||||
/>
|
||||
<div v-if="!complete" class="mt-5 flex flex-wrap items-center justify-between gap-4">
|
||||
<p class="text-sm text-muted">
|
||||
已写入 {{ episodes.length }}<span v-if="total"> / {{ total }}</span> 集<span v-if="!total">
|
||||
@@ -98,13 +119,13 @@ function exportScript() {
|
||||
label="恢复生成"
|
||||
description="用于剧集尚未写完的情况。后端会检查角色、世界观与 checkpoint,并继续处理剧集。"
|
||||
acknowledgement
|
||||
:disabled="!canGenerate || operation.pending || !!error"
|
||||
:disabled="!canGenerate || operation.pending || backgroundExecution.active.value || !!error"
|
||||
@confirm="resume('resume-generation')"
|
||||
/><ConfirmAction
|
||||
label="恢复改写"
|
||||
description="用于剧集已齐全但审核未通过的情况。将读取 checkpoint 的改写上下文并重新审核。"
|
||||
acknowledgement
|
||||
:disabled="!canRewrite || operation.pending || !!error"
|
||||
:disabled="!canRewrite || operation.pending || backgroundExecution.active.value || !!error"
|
||||
@confirm="resume('resume-rewrite')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user