refactor: 提取项目准入状态构造函数
This commit is contained in:
1 parent
e174a35a94
commit
3d888ce28d
1 file changed
+6
-6
@@ -2,23 +2,23 @@ import { computed, type Ref } from 'vue'
|
||||
import type { ProjectAccess, ProjectSection } from './access'
|
||||
import type { ProjectStageReadiness } from './types'
|
||||
|
||||
function accessState(ready: boolean | undefined, reason: string | null | undefined, fallback: string) {
|
||||
return { enabled: Boolean(ready), reason: reason || fallback }
|
||||
}
|
||||
|
||||
/** 将服务端统一 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, '请先完成剧本创作'),
|
||||
...accessState(state?.script.ready, state?.script.reason, '请先完成剧本创作'),
|
||||
nextPath: 'create-drama',
|
||||
nextLabel: '前往剧本创作'
|
||||
},
|
||||
'visual-style': {
|
||||
...own(state?.breakdown.ready, state?.breakdown.reason, '请先完成剧本拆解'),
|
||||
...accessState(state?.breakdown.ready, state?.breakdown.reason, '请先完成剧本拆解'),
|
||||
nextPath: 'breakdown',
|
||||
nextLabel: '前往剧本拆解'
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user