diff --git a/src/commands/test/render.ts b/src/commands/test/render.ts index b34a977..07317d3 100644 --- a/src/commands/test/render.ts +++ b/src/commands/test/render.ts @@ -118,6 +118,7 @@ interface RenderOpts { dictBindValidCheck?: boolean // 字典绑定 dictionaryType 在 dict 表存在 (默认 ON) labelCompleteCheck?: boolean // formItem label 非空 + 唯一 (默认 ON) requiredControlTypeCheck?: boolean // 必填字段不能在 switch/button/table 容器 (默认 ON) + columnListSubtableCheck?: boolean // columnList 引用子表字段是否有效 (v0.21+ Round 3) } export function buildTestRenderCommand(): Command { @@ -139,6 +140,7 @@ export function buildTestRenderCommand(): Command { .option('--no-dict-bind-valid-check', '关闭字典绑定有效性校验 (dictionaryType 在 dict 表存在, 默认 ON)') .option('--no-label-complete-check', '关闭 formItem label 完整性校验 (非空 + 唯一, 默认 ON)') .option('--no-required-control-type-check', '关闭必填字段控件类型校验 (必填不能在 switch/button 容器, 默认 ON)') + .option('--no-column-list-subtable-check', '关闭 columnList 子表字段引用校验 (tableFieldXXX-F_* 引用错配, 默认 ON)') .action(async (opts: RenderOpts) => { const c = await JnpfClient.fromToken() const results: RenderCheckResult[] = [] @@ -153,6 +155,7 @@ export function buildTestRenderCommand(): Command { opts.dictBindValidCheck = opts.dictBindValidCheck !== false opts.labelCompleteCheck = opts.labelCompleteCheck !== false opts.requiredControlTypeCheck = opts.requiredControlTypeCheck !== false + opts.columnListSubtableCheck = opts.columnListSubtableCheck !== false try { if (opts.module === 'dict') { @@ -386,6 +389,7 @@ async function renderForm( const formFields = extractFormRenderFields(formData) const columnFields = extractColumnListFields(columnData) + const columnList = columnData?.columnList || [] // Step I 复用 (外层作用域) // 3. 调 API 拿实际数据 (modelId=formId) // 注: webapi shim 已 unwrap, 返回的是 {pagination, list} (无 code 包裹) @@ -885,6 +889,63 @@ async function renderForm( lg.error(`✗ 必填控件类型: FAIL (${invalidRequired.length} 个非法必填: ${invalidRequired.slice(0, 3).map(r => r.jnpfKey).join(', ')})`) } } + + // === Step I: columnList 子表字段静态校验 (v0.21+ 加深, Round 3 工单) === + // 镜像 web 端 ColumnDesign.vue 渲染逻辑: columnList.prop 形如 `tableField107-F_Month` + // → tableField107 是子表 ID, F_Month 是子表字段 → 应去子表 API 查, 不去外层 + // 漂移: baseline columnList 引用子表字段 (e.g. tableField107-F_Month) 但 formData.tables[0] 没该子表 + // 或 子表没该字段 → 浏览器列表白屏 + if (opts.columnListSubtableCheck !== false && columnList.length > 0) { + const tables = typeof formDetail.tables === 'string' + ? JSON.parse(formDetail.tables || '[]') + : (formDetail.tables || []) + // 收集所有子表字段名 (扁平, 不管子表 ID 映射 — tableField107 是前端虚拟 ID, 跟 tableName 没直接对应) + const subTableFields = new Set() + const subTableCount = tables.length > 1 ? tables.length - 1 : 0 // 第 1 张是主表, 其余是子表 + for (let i = 1; i < tables.length; i++) { + for (const f of (tables[i]?.fields || [])) { + const fname = f.field || f.columnName + if (fname) subTableFields.add(fname) + } + } + + const subtableIssues: string[] = [] + const subTableProps: string[] = [] + const SUBTABLE_PROP = /^tableField\d+-(.+)$/ // 匹配 tableField107-F_Month + for (const col of columnList) { + const prop = col.prop || col.field + if (!prop) continue + if (!SUBTABLE_PROP.test(prop)) continue + subTableProps.push(prop) + const m = prop.match(SUBTABLE_PROP)! + const subField = m[1] + // 三态判定: + // 1. 外层 API 有此字段 → 列引用错 (应该直接用字段名, 不该用 tableFieldXXX- 前缀) + // 2. 子表有此字段 → PASS + // 3. 都没有 → FAIL (字段不存在, 浏览器白屏) + if (apiFieldSet.has(subField)) { + subtableIssues.push(`列 ${prop} 引用子表路径, 但外层 API 也有字段 "${subField}" — 应直接用 prop="${subField}" 而非子表路径`) + } else if (!subTableFields.has(subField)) { + subtableIssues.push(`列 ${prop} 引用子表字段 "${subField}" 但 formData.tables[1+] 无此字段 (浏览器列表白屏)`) + } + } + const status: 'PASS' | 'FAIL' = subtableIssues.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'form', + page: 'columnList 子表字段引用', + sourceFile: `columnData.columnList[].prop + formData.tables[1+].fields (formId=${formId}, subtables=${subTableCount})`, + renderFields: subTableProps, + apiFields: Array.from(subTableFields).sort().slice(0, 20), + missing: subtableIssues, + extra: [], + status, + }) + if (subtableIssues.length === 0) { + lg.info(`✓ columnList 子表字段: PASS (${subTableProps.length} 子表列引用全部有效)`) + } else { + lg.error(`✗ columnList 子表字段: FAIL (${subtableIssues.length} 个错配: ${subtableIssues.slice(0, 3).join(' | ')})`) + } + } } // ============================================================================