feat(short-drama-agent-front): 接入空间母版恢复与修订
This commit is contained in:
1 parent
c808a58a3f
commit
7e149a10c0
18 files changed
+2732
-12
No files matched your search
@@ -0,0 +1,366 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { NButton, NCheckbox, NCollapse, NCollapseItem, NTab, NTabs } from 'naive-ui'
|
||||
import AppDrawer from '../../../components/ui/AppDrawer.vue'
|
||||
import { AssetImage } from '../../../components/ui'
|
||||
import WorkspaceSectionHeading from '../../../components/ui/WorkspaceSectionHeading.vue'
|
||||
import { useActionMessage, showActionFeedback } from '../../../components/ui/useActionMessage'
|
||||
import { useQuery } from '../../../composables/useQuery'
|
||||
import { usePolling } from '../../../composables/usePolling'
|
||||
import { formatDate } from '../../../lib/format'
|
||||
import { getOperation } from '../../workflows/operations'
|
||||
import { spatialMasterApi } from '../api'
|
||||
import type { MasterGenerationReceipt } from '../types'
|
||||
import MasterGenerationForm from './MasterGenerationForm.vue'
|
||||
import MasterReviewForm from './MasterReviewForm.vue'
|
||||
import MasterRecoveryImpact from './MasterRecoveryImpact.vue'
|
||||
|
||||
/** 从原场景几何入口增量展开的正式母版管理,不另建生成或质量体系。 */
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 当前项目。 */ projectId: string
|
||||
/** 用户从已有场景选择的布局。 */ layoutId: string
|
||||
/** 上游活动操作仅限制写入,读取仍可使用。 */ disabled?: boolean
|
||||
}>(),
|
||||
{ disabled: false }
|
||||
)
|
||||
/** 全屏内容级滚动,正式操作由固定底栏提供。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 母版正式操作反馈沿用应用消息层。 */
|
||||
const message = useActionMessage()
|
||||
/** 正式资产变化后通知原图库只读刷新。 */
|
||||
const emit = defineEmits<{ changed: [] }>()
|
||||
/** 关闭时取消全部读取,切换项目/布局拒绝旧结果。 */
|
||||
const key = computed(() =>
|
||||
open.value && props.projectId && props.layoutId ? JSON.stringify([props.projectId, props.layoutId]) : ''
|
||||
)
|
||||
/** 当前真实布局、完整母版历史与正式已确认母版。 */
|
||||
const query = useQuery(key, async (value, signal) => {
|
||||
if (!value) return null
|
||||
const [projectId, layoutId] = JSON.parse(value) as [string, string]
|
||||
const [layouts, masters, confirmed] = await Promise.all([
|
||||
spatialMasterApi.layouts(projectId, signal),
|
||||
spatialMasterApi.masters(projectId, layoutId, signal),
|
||||
spatialMasterApi.confirmed(projectId, layoutId, signal)
|
||||
])
|
||||
const layout = layouts.find(item => item.id === layoutId)
|
||||
if (
|
||||
!layout ||
|
||||
(layout.projectId && layout.projectId !== projectId) ||
|
||||
masters.some(item => item.projectId !== projectId || item.spatialLayoutId !== layoutId) ||
|
||||
(confirmed &&
|
||||
(confirmed.projectId !== projectId ||
|
||||
confirmed.spatialLayoutId !== layoutId ||
|
||||
confirmed.spatialLayoutVersion !== layout.version ||
|
||||
confirmed.status !== 'confirmed'))
|
||||
)
|
||||
throw new Error('母版或布局与当前项目不匹配,请重新读取。')
|
||||
return { layout, masters, confirmed }
|
||||
})
|
||||
/** 后端为同步持久化母版任务,使用正式 GET 观察,不伪造 SSE 或百分比。 */
|
||||
const jobs = usePolling(
|
||||
key,
|
||||
async (value, signal) => {
|
||||
if (!value) return []
|
||||
const [projectId, layoutId] = JSON.parse(value) as [string, string]
|
||||
const rows = await spatialMasterApi.jobs(projectId, layoutId, signal)
|
||||
if (rows.some(item => item.projectId !== projectId || item.spatialLayoutId !== layoutId))
|
||||
throw new Error('任务记录与当前布局不匹配。')
|
||||
return rows
|
||||
},
|
||||
computed(() => (key.value ? 5000 : false))
|
||||
)
|
||||
/** 当前功能标签;未打开恢复影响时不发全布局检查。 */
|
||||
const tab = ref('masters')
|
||||
/** 用户主动查看审核时定位到对应表单,不让长图库挡住正文。 */
|
||||
const reviewSection = ref<HTMLElement | null>(null)
|
||||
/** 用户选择的正式母版;默认仅查看服务端当前记录。 */
|
||||
const selectedId = ref('')
|
||||
/** 选中图片只来自当前列表。 */
|
||||
const selected = computed(() => query.data.value?.masters.find(item => item.id === selectedId.value))
|
||||
/** 生成表单公开底栏操作。 */
|
||||
const generationRef = ref<InstanceType<typeof MasterGenerationForm> | null>(null)
|
||||
/** 审核表单公开底栏操作。 */
|
||||
const reviewRef = ref<InstanceType<typeof MasterReviewForm> | null>(null)
|
||||
/** 仅真正提交期间锁定关闭,普通查询不锁定。 */
|
||||
const busy = computed(() => !!generationRef.value?.submitting || !!reviewRef.value?.pending)
|
||||
/** 已有任务或未知费用阻止新付费/正式确认,不影响只读。 */
|
||||
const activeJob = computed(() => jobs.data.value?.some(item => !['completed', 'failed'].includes(item.status)))
|
||||
/** 复用项目全局活动锁,防止从另一入口并行写入。 */
|
||||
const blocked = computed(
|
||||
() =>
|
||||
props.disabled ||
|
||||
getOperation(props.projectId).pending ||
|
||||
!!activeJob.value ||
|
||||
!jobs.data.value ||
|
||||
!!jobs.error.value ||
|
||||
!!query.error.value
|
||||
)
|
||||
/** 最近任务公开状态。 */
|
||||
const jobLabels: Record<string, string> = {
|
||||
pending: '等待执行',
|
||||
running: '执行中',
|
||||
interrupted: '结果或费用待核查',
|
||||
completed: '已生成草稿',
|
||||
failed: '执行失败'
|
||||
}
|
||||
watch(
|
||||
key,
|
||||
() => {
|
||||
tab.value = 'masters'
|
||||
selectedId.value = ''
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
() => query.data.value,
|
||||
data => {
|
||||
if (data && !data.masters.some(item => item.id === selectedId.value))
|
||||
selectedId.value = data.confirmed?.id ?? data.masters[0]?.id ?? ''
|
||||
}
|
||||
)
|
||||
/** 任务在其他入口完成后,只读恢复母版列表,旧项目事件不会回填。 */
|
||||
watch(
|
||||
() => jobs.data.value,
|
||||
(rows, previous) => {
|
||||
if (!key.value || !rows || !previous) return
|
||||
if (
|
||||
rows.some(
|
||||
item =>
|
||||
['completed', 'failed', 'interrupted'].includes(item.status) &&
|
||||
previous.some(old => old.id === item.id && ['pending', 'running'].includes(old.status))
|
||||
)
|
||||
)
|
||||
void query.refresh()
|
||||
}
|
||||
)
|
||||
/**
|
||||
* 同步读取当前布局与任务;失败保持数据但暂停写入。
|
||||
* @returns 当前刷新完成
|
||||
*/
|
||||
async function refresh() {
|
||||
await Promise.all([query.refresh(), jobs.refresh(), reviewRef.value?.refresh()])
|
||||
}
|
||||
/**
|
||||
* 在同一只读范围选择母版并定位审核表单,不触发审核或确认。
|
||||
* @param masterId 用户选中的正式资产编号
|
||||
* @returns 正文定位完成
|
||||
*/
|
||||
async function selectMaster(masterId: string) {
|
||||
if (busy.value) return
|
||||
const target = key.value
|
||||
selectedId.value = masterId
|
||||
await nextTick()
|
||||
if (target === key.value) reviewSection.value?.scrollIntoView({ block: 'start' })
|
||||
}
|
||||
/**
|
||||
* 新草稿回执仅定位展示,不自动审核或确认。
|
||||
* @param receipt 已验证的正式生成回执
|
||||
*/
|
||||
function generated(receipt: MasterGenerationReceipt) {
|
||||
showActionFeedback(message, '已生成母版草稿,尚未完成质量审核与人工确认。', 'info')
|
||||
selectedId.value = receipt.masterId
|
||||
tab.value = 'masters'
|
||||
void query.refresh()
|
||||
void jobs.refresh()
|
||||
emit('changed')
|
||||
}
|
||||
/** 人工确认或机器审核后只读回查正式来源,不生成下游素材。 */
|
||||
function reviewed() {
|
||||
void query.refresh()
|
||||
void jobs.refresh()
|
||||
emit('changed')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是母版历史、独立质量、恢复影响和任务的全屏管理模块 -->
|
||||
<AppDrawer
|
||||
v-model:open="open"
|
||||
title="空间母版管理"
|
||||
description="历史原图、来源版本与人工/机器审核分别核对。所有生成和 AI 审核均须独立确认费用。"
|
||||
:busy="busy"
|
||||
>
|
||||
<div class="space-y-(--app-content-gap)">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 class="text-base font-semibold">{{ query.data.value?.layout.name || '当前空间布局' }}</h3>
|
||||
<p v-if="query.data.value" class="mt-2 wrap-anywhere text-xs text-muted">
|
||||
当前布局版本:{{ query.data.value.layout.version }}
|
||||
</p>
|
||||
</div>
|
||||
<NButton :loading="query.loading.value || jobs.loading.value" :disabled="busy" @click="refresh"
|
||||
>刷新母版与任务</NButton
|
||||
>
|
||||
</div>
|
||||
<p v-if="query.loading.value && !query.data.value" class="text-sm text-muted" role="status">
|
||||
正在读取布局与母版记录…
|
||||
</p>
|
||||
<p v-if="query.error.value" class="text-sm text-muted">{{ query.error.value }}</p>
|
||||
<p v-if="activeJob" class="text-sm text-muted" role="status">
|
||||
已有生成任务执行中或结果待核查,请在任务记录中核对;不会自动再次生图。
|
||||
</p>
|
||||
<NTabs v-model:value="tab" type="line" aria-label="空间母版功能"
|
||||
><NTab :disabled="busy" name="masters">母版与审核</NTab
|
||||
><NTab :disabled="busy" name="generate">恢复与修订</NTab
|
||||
><NTab :disabled="busy" name="impact">来源影响</NTab
|
||||
><NTab :disabled="busy" name="jobs">任务记录</NTab></NTabs
|
||||
>
|
||||
<template v-if="query.data.value">
|
||||
<!-- 以下是保留原图的全部母版历史,确认状态不冒充机器通过 -->
|
||||
<section v-if="tab === 'masters'" class="space-y-(--app-content-gap)">
|
||||
<WorkspaceSectionHeading
|
||||
title="母版历史"
|
||||
:description="
|
||||
query.data.value.confirmed
|
||||
? '当前版本已有正式确认母版;旧图和草稿继续保留。'
|
||||
: '暂无当前版本已确认母版。历史确认图不能自动作为当前母版。'
|
||||
"
|
||||
/>
|
||||
<p v-if="!query.data.value.masters.length" class="text-sm text-muted">
|
||||
暂无母版记录,可在恢复与修订中免费预检。
|
||||
</p>
|
||||
<div
|
||||
class="grid grid-cols-1 items-start gap-(--app-content-gap) sm:grid-cols-[repeat(auto-fill,minmax(220px,260px))]"
|
||||
>
|
||||
<article v-for="master in query.data.value.masters" :key="master.id" class="min-w-0 space-y-2">
|
||||
<AssetImage
|
||||
:src="master.imageUrl"
|
||||
:style="{ aspectRatio: '1/1' }"
|
||||
alt="空间母版原图"
|
||||
object-fit="contain"
|
||||
preview
|
||||
/>
|
||||
<p class="text-sm font-semibold">
|
||||
{{
|
||||
master.status === 'confirmed'
|
||||
? '已确认'
|
||||
: master.status === 'draft'
|
||||
? '草稿'
|
||||
: '状态待核对'
|
||||
}}{{ master.id === query.data.value.confirmed?.id ? ' · 当前全局母版' : '' }}
|
||||
</p>
|
||||
<p class="text-xs text-muted">
|
||||
{{
|
||||
master.spatialLayoutVersion === query.data.value.layout.version
|
||||
? '绑定当前布局'
|
||||
: '绑定历史布局'
|
||||
}}
|
||||
· {{ master.subjectFormId ? '形态专属机位' : '全局布局' }} ·
|
||||
{{ formatDate(master.createdAt) }}
|
||||
</p>
|
||||
<p v-if="master.confirmedBy" class="text-xs text-muted">
|
||||
人工确认:{{ master.confirmedBy }} ·
|
||||
{{ master.confirmedAt ? formatDate(master.confirmedAt) : '时间未记录' }}
|
||||
</p>
|
||||
<NButton
|
||||
class="workspace-action-button"
|
||||
:disabled="busy"
|
||||
@click="selectMaster(master.id)"
|
||||
>{{ selectedId === master.id ? '正在查看审核' : '查看审核与确认' }}</NButton
|
||||
>
|
||||
</article>
|
||||
</div>
|
||||
<section v-if="selected" ref="reviewSection">
|
||||
<MasterReviewForm
|
||||
ref="reviewRef"
|
||||
:key="selected.id"
|
||||
:project-id="projectId"
|
||||
:layout="query.data.value.layout"
|
||||
:master="selected"
|
||||
:disabled="blocked"
|
||||
@changed="reviewed"
|
||||
@stale="refresh"
|
||||
/>
|
||||
</section>
|
||||
</section>
|
||||
<!-- 以下是独立的免费输入预检与单次生成表单,结果只登记草稿 -->
|
||||
<MasterGenerationForm
|
||||
v-if="tab === 'generate'"
|
||||
ref="generationRef"
|
||||
:project-id="projectId"
|
||||
:layout="query.data.value.layout"
|
||||
:masters="query.data.value.masters"
|
||||
:disabled="blocked"
|
||||
@generated="generated"
|
||||
@stale="refresh"
|
||||
/>
|
||||
<MasterRecoveryImpact v-if="tab === 'impact'" :project-id="projectId" :layout-id="layoutId" />
|
||||
<!-- 以下是真实任务状态,无本次请求也可发现,不自动恢复或重复生图 -->
|
||||
<section v-if="tab === 'jobs'" class="space-y-4">
|
||||
<WorkspaceSectionHeading
|
||||
title="母版生成任务"
|
||||
description="完成仅代表草稿生成;中断可能已计费,应先核对原结果,不自动重试。"
|
||||
/>
|
||||
<p v-if="jobs.error.value" class="text-sm text-muted">{{ jobs.error.value }}</p>
|
||||
<p v-if="!jobs.data.value?.length" class="text-sm text-muted">暂无生成任务。</p>
|
||||
<article v-for="job in jobs.data.value" :key="job.id" class="space-y-2">
|
||||
<p class="text-sm font-semibold">
|
||||
{{ jobLabels[job.status] || '状态待核查' }} · {{ formatDate(job.updatedAt) }}
|
||||
</p>
|
||||
<p class="wrap-anywhere text-xs text-muted">
|
||||
任务编号:{{ job.id }} · {{ job.provider }} / {{ job.model }}
|
||||
</p>
|
||||
<p v-if="job.status === 'interrupted'" class="text-sm">原结果或费用待核查,请勿重新生图。</p>
|
||||
<NCollapse
|
||||
><NCollapseItem name="job" title="任务输入详情"
|
||||
><p class="wrap-anywhere text-xs">布局版本:{{ job.spatialLayoutVersion }}</p>
|
||||
<pre class="mt-2 whitespace-pre-wrap break-words text-xs">{{ job.prompt }}</pre>
|
||||
<pre class="mt-2 whitespace-pre-wrap break-words text-xs">{{
|
||||
JSON.stringify(job.generationOptions, null, 2)
|
||||
}}</pre>
|
||||
<p class="mt-2 text-xs">原任务参考摘要</p>
|
||||
<pre class="whitespace-pre-wrap break-words text-xs">{{
|
||||
job.referenceSnapshot ? JSON.stringify(job.referenceSnapshot, null, 2) : '未记录'
|
||||
}}</pre>
|
||||
</NCollapseItem></NCollapse
|
||||
>
|
||||
</article>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
<!-- 以下是固定底栏中的独立费用确认、人工确认与关闭入口 -->
|
||||
<template #footer>
|
||||
<div class="flex w-full flex-wrap items-center justify-end gap-3">
|
||||
<NCheckbox
|
||||
v-if="tab === 'generate' && generationRef"
|
||||
v-model:checked="generationRef.acknowledged"
|
||||
:disabled="busy || blocked"
|
||||
class="mr-auto"
|
||||
>已核对本次费用,确认仅生成一张草稿</NCheckbox
|
||||
>
|
||||
<NCheckbox
|
||||
v-if="tab === 'masters' && selected?.status === 'draft' && reviewRef"
|
||||
v-model:checked="reviewRef.visionAcknowledged"
|
||||
:disabled="busy || blocked"
|
||||
class="mr-auto"
|
||||
>单独确认本次 AI 视觉审核可能收费</NCheckbox
|
||||
>
|
||||
<NButton :disabled="busy" @click="open = false">关闭</NButton>
|
||||
<NButton
|
||||
v-if="tab === 'generate' && generationRef"
|
||||
type="primary"
|
||||
:loading="generationRef.submitting"
|
||||
:disabled="!generationRef.canSubmit"
|
||||
@click="generationRef.submit()"
|
||||
>确认费用并生成一张草稿</NButton
|
||||
>
|
||||
<NButton
|
||||
v-if="tab === 'masters' && selected?.status === 'draft' && reviewRef"
|
||||
:loading="reviewRef.pending === 'vision'"
|
||||
:disabled="!reviewRef.canValidate"
|
||||
@click="reviewRef.validate()"
|
||||
>AI 视觉审核</NButton
|
||||
>
|
||||
<NButton
|
||||
v-if="tab === 'masters' && selected?.status === 'draft' && reviewRef"
|
||||
type="primary"
|
||||
:loading="reviewRef.pending === 'confirm'"
|
||||
:disabled="!reviewRef.canConfirm"
|
||||
@click="reviewRef.confirm()"
|
||||
>正式人工确认母版</NButton
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</AppDrawer>
|
||||
</template>
|
||||
Reference in new issue
Block a user