diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index cc3339a..1e94e3b 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -19,6 +19,7 @@ import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts' import { preCheckFormCreate, handlePreCheckResult } from '../_precheck.ts' import { loadContextSafe } from '../_precheck.ts' import { runGuards, handleGuardResult } from '../_blindspot_guards.ts' +import { validateFormCreate } from './_validate.ts' import { loadAppContext } from '../app/context.ts' interface CreateOpts { @@ -116,6 +117,19 @@ export function buildFormCreateCommand(): Command { log.error('--ai-json 必须是 List 非空数组') process.exit(2) } + // 2026-06-26 v0.11d 兼容: AI prompt 规范字段名是 fieldName, 但 dacli 历史示例用 field + // web buildFormData (formUtils.ts:29) 读 child.fieldName, 缺则 __vModel__=undefined → form 字段丢 vmodel + // 这里兼容映射: field → fieldName (有 fieldName 优先用, 没有再 fallback field) + for (const m of aiModelList) { + if (Array.isArray(m?.fields)) { + for (const fld of m.fields) { + if (fld && !fld.fieldName && fld.field) { + fld.fieldName = fld.field + log.info(` 字段兼容映射: field → fieldName (${fld.field})`) + } + } + } + } // 强制 isMain (对齐 JNPF 后端 VisualAiServiceImpl.setIsMain(0, i==0)) aiModelList.forEach((m: any, i: number) => { m.isMain = (i === 0) }) // 自动填 enCode/fullName (用户未传时) @@ -627,6 +641,38 @@ export function buildFormCreateCommand(): Command { } log.info(`loadVisualDev.create ${opts.enCode} type=${type} webType=${webType} dbLinkId=${dbLinkId}`) + + // 2026-06-26 v0.11d+ step machine 校验 (镜像 web Form.vue handleNext + handleSubmit 前端校验) + // 失败时不发 API, 让 AI 看到具体 step + 错误字段 (不用去浏览器试错) + const validation = validateFormCreate({ + fullName: opts.fullName, + enCode: opts.enCode, + type, + webType, + tables, + formData, + columnData: columnDataObj, + }) + if (!validation.ok) { + log.error(`✗ step machine 校验未通过 (${validation.steps.filter(s => !s.ok).map(s => `step${s.step}(${s.stepName})`).join(', ')}):`) + for (const step of validation.steps) { + if (step.ok) { + log.ok(` step${step.step} ${step.stepName}: ✓ 通过`) + } else { + log.error(` step${step.step} ${step.stepName}: ✗ ${step.errors.length} 个错误`) + for (const err of step.errors) { + const fieldTag = err.field ? `[${err.field}] ` : '' + log.error(` - ${fieldTag}${err.message}`) + } + } + } + if (opts.json) { + printJson({ ok: false, validation: validation.steps }) + } + process.exit(1) + } + log.ok(`✓ step machine 校验通过 (3/3)`) + // v0.11+ Phase 2: 改用 webapi (loadVisualDev.create) await initWebapi(c) // P0.2: 加载 AppContext 供诊断用 (复用 P0.1 的 loadAppContext, 失败不阻断主流程)