refactor: 项目准入直接消费统一阶段状态

This commit is contained in:
GouJ committed 2026-09-26 21:15:21 +08:00
1 parent 2a2a81772d
commit 184cb4b1dd
1 file changed
+57 -67
+57 -67
View File
@@ -1,71 +1,61 @@
import { computed, type Ref } from 'vue'
import { breakdownSnapshot } from '../workflows/selectors'
import type { ProjectSection, ProjectAccess } from './access'
import type { ProjectDetail } from './types'
import type { Checkpoint } from '../workflows/types'
import type { ProjectAccess, ProjectSection } from './access'
import type { ProjectStageReadiness } from './types'
/**
* 主流程准入只使用已经持久化且当前项目可读取的数据。
* 更细的身份、图片和分镜 readiness 由对应页面与 Production Plan 继续校验,
* 避免前端复制服务端业务规则。
*/
export function useProjectStageAccess(
projectId: Ref<string>,
project: Ref<ProjectDetail | null>,
checkpoints: Ref<Checkpoint[]>
) {
const scriptReady = computed(() => project.value?.id === projectId.value && project.value.status === 'completed')
const breakdownReady = computed(() => {
if (!scriptReady.value) return false
const snapshot = breakdownSnapshot(checkpoints.value)
const result = snapshot?.breakdownResult ?? snapshot
return Boolean(
result?.subjectCandidates?.length &&
result?.subjectForms?.length &&
result?.storyboardEpisodeShots?.length &&
result?.storyboardShotValidation?.valid
)
})
const sections = computed<Record<ProjectSection, ProjectAccess['sections'][ProjectSection]>>(() => ({
'create-drama': { enabled: true, reason: '' },
breakdown: {
enabled: scriptReady.value,
reason: '请先完成剧本创作',
nextPath: 'create-drama',
nextLabel: '前往剧本创作'
},
'visual-style': {
enabled: breakdownReady.value,
reason: '请先完成剧本拆解,准备好人物、场景、道具和镜头',
nextPath: 'breakdown',
nextLabel: '前往剧本拆解'
},
'subject-identity': {
enabled: breakdownReady.value,
reason: '请先完成剧本拆解,准备好需要制作的主体',
nextPath: 'breakdown',
nextLabel: '前往剧本拆解'
},
'subject-images': {
enabled: breakdownReady.value,
reason: '请先完成剧本拆解和主体准备',
nextPath: 'subject-identity',
nextLabel: '前往主体身份'
},
storyboard: {
enabled: breakdownReady.value,
reason: '请先完成剧本拆解,生成正式镜头后再进行分镜设计',
nextPath: 'breakdown',
nextLabel: '前往剧本拆解'
},
production: {
enabled: breakdownReady.value,
reason: '请先完成剧本拆解。进入镜头生产后还会检查主体素材和分镜设计是否齐全',
nextPath: 'breakdown',
nextLabel: '前往剧本拆解'
/** 将服务端统一 readiness 转为侧栏、URL 门禁和下一步引导,前端不复制制作规则。 */
export function useProjectStageAccess(projectId: Ref<string>, readiness: Ref<ProjectStageReadiness | null>) {
const sections = computed<Record<ProjectSection, ProjectAccess['sections'][ProjectSection]>>(() => {
const state = readiness.value
const own = (ready: boolean | undefined, reason: string | null | undefined, fallback: string) => ({
enabled: Boolean(ready),
reason: reason || fallback
})
return {
'create-drama': { enabled: true, reason: '' },
breakdown: {
...own(state?.script.ready, state?.script.reason, '请先完成剧本创作'),
nextPath: 'create-drama',
nextLabel: '前往剧本创作'
},
'visual-style': {
...own(state?.breakdown.ready, state?.breakdown.reason, '请先完成剧本拆解'),
nextPath: 'breakdown',
nextLabel: '前往剧本拆解'
},
'subject-identity': {
enabled: Boolean(state?.breakdown.ready && state?.visualStyle.ready),
reason: state?.breakdown.reason || state?.visualStyle.reason || '请先准备视觉风格',
nextPath: state?.breakdown.ready ? 'visual-style' : 'breakdown',
nextLabel: state?.breakdown.ready ? '前往视觉风格' : '前往剧本拆解'
},
'subject-images': {
enabled: Boolean(state?.breakdown.ready && state?.visualStyle.ready && state?.identity.ready),
reason:
state?.breakdown.reason ||
state?.visualStyle.reason ||
state?.identity.reason ||
'请先完成主体身份准备',
nextPath: state?.visualStyle.ready ? 'subject-identity' : state?.breakdown.ready ? 'visual-style' : 'breakdown',
nextLabel: state?.visualStyle.ready ? '前往主体身份' : state?.breakdown.ready ? '前往视觉风格' : '前往剧本拆解'
},
storyboard: {
enabled: Boolean(state?.breakdown.ready && state?.subjectAssets.ready),
reason: state?.breakdown.reason || state?.subjectAssets.reason || '请先准备主体素材',
nextPath: state?.breakdown.ready ? 'subject-images' : 'breakdown',
nextLabel: state?.breakdown.ready ? '前往形态图片' : '前往剧本拆解'
},
production: {
enabled: Boolean(state?.breakdown.ready && state?.subjectAssets.ready && state?.storyboard.ready),
reason:
state?.breakdown.reason ||
state?.subjectAssets.reason ||
state?.storyboard.reason ||
'请先完成镜头制作准备',
nextPath: state?.subjectAssets.ready ? 'storyboard' : state?.breakdown.ready ? 'subject-images' : 'breakdown',
nextLabel: state?.subjectAssets.ready ? '前往分镜设计' : state?.breakdown.ready ? '前往形态图片' : '前往剧本拆解'
}
}
}))
return { scriptReady, breakdownReady, sections }
})
const scriptReady = computed(() => readiness.value?.script.ready === true)
return { projectId, scriptReady, sections }
}