From 877b5fc973e6ea3f11abe7ac9437d58b1821260b Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 13:10:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(form):=20v0.11f=20B-13=20ai-json=20relation?= =?UTF-8?q?Form=20=E8=87=AA=E5=8A=A8=E5=B1=95=E5=BC=80=20modelId/propsValu?= =?UTF-8?q?e/relationField?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **问题**: web FormGenerator.vue:272-276 校验 !modelId/propsValue/relationField → '关联功能/存储字段/回显字段不能为空' dacli --ai-json 路径未自动注入这 3 项必填, 导致主子表/关系表单无法走 ai-json 创建 **改动**: 1. _ai.ts AiFormModel.fields[] 加 fieldRelationConfig?: { modelId, propsValue, relationField, columnOptions[] } 2. create.ts:144 走 webBuildFormData 后, 递归遍历 formData.fields[] + 子表 children[], 注入 modelId/propsValue/relationField/columnOptions + web 默认值 (hasPage/pageSize/popupType/popupTitle/popupWidth) **主子表特殊**: 子表字段在 formData.fields[].__config__.children[] (jnpfKey=table), 注入逻辑需递归 **验证**: tds_space_v3 schema (id=840540897492860933) - f_policy_id (主表): modelId=tds_policy, propsValue=f_policy_id, relationField=f_policy_name, cols=5 ✓ - f_connector_id (子表): modelId=tds_connector, propsValue=f_connector_id, relationField=f_connector_name, cols=4 ✓ --- src/commands/form/_ai.ts | 14 +++++++++ src/commands/form/create.ts | 57 +++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/commands/form/_ai.ts b/src/commands/form/_ai.ts index 9ecc20b..ab988a7 100644 --- a/src/commands/form/_ai.ts +++ b/src/commands/form/_ai.ts @@ -32,6 +32,20 @@ export interface AiFormModel { fieldDbType?: string fieldComponent?: string fieldOptions?: Array<{ id?: string; fullName?: string; enCode?: string }> + /** + * v0.11f+ (2026-06-27 B-13 fix): relationForm 完整配置 + * 必填 3 项 (镜像 web FormGenerator.vue:272-276 校验): + * - modelId: 关联 form 的 enCode (例如 "tds_policy") + * - propsValue: 存储字段 = 当前字段 vmodel (例如 "f_policy_id") + * - relationField: 回显字段 = 目标 form 的显示字段 (例如 "f_policy_name") + * 可选 columnOptions: 弹窗列表列 (≤5, D-15 防御) + */ + fieldRelationConfig?: { + modelId?: string + propsValue?: string + relationField?: string + columnOptions?: Array<{ label?: string; value?: string; enCode?: string }> + } }> } diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index 7b7c4ef..c33f9fb 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -142,8 +142,61 @@ export function buildFormCreateCommand(): Command { // 走 buildFormData (同 --ai 路径) await initBuildFormData() const bfdResult = webBuildFormData(aiModelList) - ;(opts as any).__aiBuildFormData = bfdResult - log.info(`v0.11+ --ai-json 走 web buildFormData, formData.fields=${JSON.parse(bfdResult.formData).fields.length}`) + // v0.11f+ (2026-06-27 B-13 fix): 注入 relationForm 字段必填 3 项 + // web FormGenerator.vue:272-276 校验: !modelId → "关联功能不能为空" + // web buildFormData 不识别 AiFormModel.fields[].fieldRelationConfig, 需手动注入 + // 主子表场景: 子表字段在 formData.fields[].__config__.children[] 里 (jnpfKey=table) + const formDataObjInject = JSON.parse(bfdResult.formData) + const aiFieldsMap = new Map() // vmodel → ai field (含 fieldRelationConfig) + for (const m of aiModelList) { + if (Array.isArray(m?.fields)) { + for (const fld of m.fields) { + if (fld?.fieldName) aiFieldsMap.set(fld.fieldName, fld) + } + } + } + let relationInjected = 0 + const injectRelationForm = (fld: any) => { + const cfg = fld?.__config__ + if (cfg?.jnpfKey === 'relationForm') { + const vmodel = fld.__vModel__ + const aiFld = aiFieldsMap.get(vmodel) + const relCfg = aiFld?.fieldRelationConfig + if (!relCfg) { + log.warn(` ⚠ B-13: relationForm 字段 ${vmodel} 缺 fieldRelationConfig, 必填 modelId/propsValue/relationField (web 校验会拒)`) + } else { + // 注入 modelId / propsValue / relationField / columnOptions (镜像 web componentMap.ts:1386-1400) + if (relCfg.modelId) fld.modelId = relCfg.modelId + if (relCfg.propsValue) fld.propsValue = relCfg.propsValue + if (relCfg.relationField) fld.relationField = relCfg.relationField + if (Array.isArray(relCfg.columnOptions) && relCfg.columnOptions.length > 0) { + fld.columnOptions = relCfg.columnOptions.map((c: any) => ({ + label: c.label || c.value || c.enCode || '', + value: c.value || c.enCode || c.label || '', + enCode: c.enCode || c.value || '', + })) + } + // 默认补全 web 默认值 (用户没传时) + fld.hasPage = fld.hasPage ?? false + fld.pageSize = fld.pageSize ?? 20 + fld.popupType = fld.popupType ?? 'dialog' + fld.popupTitle = fld.popupTitle ?? '选择数据' + fld.popupWidth = fld.popupWidth ?? '800px' + relationInjected++ + } + } + // 递归: 主子表场景下子表字段在 jnpfKey=table 的 __config__.children[] 里 + if (Array.isArray(cfg?.children)) { + for (const child of cfg.children) injectRelationForm(child) + } + } + for (const fld of formDataObjInject.fields || []) injectRelationForm(fld) + if (relationInjected > 0) { + log.info(`v0.11f+ B-13 fix: 注入 ${relationInjected} 个 relationForm 字段 modelId/propsValue/relationField`) + } + // 序列化回 bfdResult + ;(opts as any).__aiBuildFormData = { ...bfdResult, formData: JSON.stringify(formDataObjInject) } + log.info(`v0.11+ --ai-json 走 web buildFormData, formData.fields=${formDataObjInject.fields.length}`) // v0.11+ cleanup: 不再强制 type=4, 保持 --type 用户传入 (默认 1 formDesign) // ai-json 含完整 tableName, 用户可走 type=1 + 物理表 (type=1 是 formDesign 列表) // 2026-06-26: webType 默认 '1' → '2' (生产场景 99% 都要列表页)