Files
xiaoxia-saas/apps/web/src/pages/generate/hooks/useStepNavigation.ts
T
xiaoxia ad8aebd1b0
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 27s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m47s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m15s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 36s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m19s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 23s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 57s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m10s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m13s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 2m23s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 5m17s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 21s
AI Code Review / AI Code Review (pull_request) Successful in 6m49s
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
refactor(generate): 拆分 GeneratePage 主文件,抽离表单状态/步骤导航/步骤内容/底部按钮
- 抽 useGenerateFormState: 集中管理 7 步向导所有共享状态、API 加载、URL 参数解析
- 抽 useStepNavigation: 步骤切换与各步骤前置校验
- 抽 GenerateStepContent 组件: 当前步骤内容渲染 switch
- 抽 GenerateStepActions 组件: 底部操作按钮
- 主文件 485→238 行 (-51%),仅保留布局与事件编排
2026-07-27 00:29:07 +08:00

64 lines
1.6 KiB
TypeScript

/**
* GeneratePage 步骤导航
* 管理步骤切换与各步骤的前置校验
*/
import { message } from "antd"
import type { TitleSettings } from "../types"
export interface UseStepNavigationOptions {
currentStep: number
setCurrentStep: (step: number | ((prev: number) => number)) => void
selectedTemplate: string
materialMode: "manual" | "auto"
selectedMaterials: string[]
smartSelectedIds: string[]
titleSettings: TitleSettings
}
export interface UseStepNavigationReturn {
goNext: () => void
goPrev: () => void
}
export const useStepNavigation = (options: UseStepNavigationOptions): UseStepNavigationReturn => {
const {
currentStep,
setCurrentStep,
selectedTemplate,
materialMode,
selectedMaterials,
smartSelectedIds,
titleSettings,
} = options
const goNext = () => {
if (currentStep === 1 && !selectedTemplate) {
message.warning("请先选择一个模板")
return
}
if (currentStep === 2 && materialMode === "manual" && selectedMaterials.length === 0) {
message.warning("请至少选择一个素材")
return
}
if (currentStep === 2 && materialMode === "auto" && smartSelectedIds.length === 0) {
message.warning("请先进行智能匹配并选择素材")
return
}
if (currentStep === 4 && !titleSettings.title.trim()) {
message.warning("请选择或输入标题")
return
}
if (currentStep < 7) {
setCurrentStep((s) => s + 1)
}
}
const goPrev = () => {
if (currentStep > 1) {
setCurrentStep((s) => s - 1)
}
}
return { goNext, goPrev }
}