From dd81f9ce20ae8404abebd96aa5fcae0ac6444fad Mon Sep 17 00:00:00 2001 From: ssw Date: Wed, 1 Jul 2026 16:27:29 +0800 Subject: [PATCH] auto(284e8d004cbb): session end @ 2026-07-01T16:27:24 (+1f) --- src/commands/test/render.ts | 660 ++++++++++++++++++++++++++++++++++-- 1 file changed, 639 insertions(+), 21 deletions(-) diff --git a/src/commands/test/render.ts b/src/commands/test/render.ts index b72510c..758c715 100644 --- a/src/commands/test/render.ts +++ b/src/commands/test/render.ts @@ -21,7 +21,8 @@ * **支持的模块** (按 JNPF 业务场景): * - dict: 字典 (类型 + 数据), 含 4 个 vue + 3 个 API * - form: 表单 (form 设计器 formData + 列表设计器 columnData, 含主子表), 通过 --formId 必填 - * - menu: (TODO Phase B) + * - di: 数据接口 (SQL/API/WebSocket), 镜像 web DataInterface 渲染契约 + * - menu: 菜单 (4 关卡: list 字段 ⊆ api / form 字段 ⊆ api / parentId 树形 + systemId 应用隔离 + propertyJson.moduleId 关联 / propertyJson JSON schema), --id= 可选第 5 关卡单条 propertyJson 完整性 * * **vs 浏览器测试**: * - 速度: ~2s vs 30s+ @@ -66,6 +67,8 @@ import { parse } from '@vue/compiler-sfc' import { JnpfClient } from '../../core/client.ts' import { initWebapi, loadDict } from '../../webapi/dict.ts' import { initWebapi as initWebapiVisual, loadVisualDev } from '../../webapi/visualDev.ts' +import { initWebapi as initWebapiDi, loadDataInterface } from '../../webapi/di.ts' +import { initWebapi as initWebapiMenu, loadMenu } from '../../webapi/menu.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import * as fs from 'node:fs/promises' @@ -106,9 +109,9 @@ export function buildTestRenderCommand(): Command { const cmd = new Command('render') .alias('source') .description('源码渲染验证 (镜像 web 端渲染契约, 替代浏览器验证) — 读 vue 渲染契约 + 调 API, 检查字段完整性') - .requiredOption('--module ', '模块名: dict | form | menu (Phase B)') + .requiredOption('--module ', '模块名: dict | form | di | menu') .option('--typeId ', '字典类型 id (dict module 验证数据时必填)') - .option('--id ', '实体 id (验证单条数据时用)') + .option('--id ', '实体 id (验证单条数据时用, menu module 验证单条菜单 propertyJson schema)') .option('--formId ', '表单 id (form module 必填)') .option('--json', '原始 JSON 输出', false) // === v0.11g+ 真实渲染契约升级 (2026-06-28) === @@ -135,8 +138,12 @@ export function buildTestRenderCommand(): Command { process.exit(2) } await renderForm(c, opts, results, opts.json ? silent : real) + } else if (opts.module === 'di') { + await renderDi(c, opts, results, opts.json ? silent : real) + } else if (opts.module === 'menu') { + await renderMenu(c, opts, results, opts.json ? silent : real) } else { - log.error(`暂不支持 module=${opts.module} (Phase B 计划: menu)`) + log.error(`暂不支持 module=${opts.module}`) process.exit(2) } } catch (e) { @@ -176,10 +183,10 @@ export function buildTestRenderCommand(): Command { installAiHelpHook(cmd, { purpose: '源码渲染验证 (替代浏览器验证) — 读 vue 渲染契约 + 调 API, 检查字段完整性 (~2s)', - required: { '--module': 'dict | form | menu' }, + required: { '--module': 'dict | form | di | menu' }, optional: { '--typeId': '字典类型 id (dict module 验证数据时必填)', - '--id': '实体 id (验证单条数据时用)', + '--id': '实体 id (验证单条数据时用, di module 验证单条接口 schema, menu module 验证单条菜单 propertyJson)', '--formId': '表单 id (form module 必填)', }, example: [ @@ -188,20 +195,28 @@ export function buildTestRenderCommand(): Command { 'dacli test render --module=dict --typeId=X --id=Y # 验证某条数据详情渲染', 'dacli test render --module=dict --json | jq ".results[].status" # 批量跑', 'dacli test render --module=form --formId=840616900198137861 # 验证某 form 渲染 (formData+columnData)', + 'dacli test render --module=di # 验证所有数据接口 list+form 字段 ⊆ api (webapi 镜像, SQL/API/WebSocket 三类型 schema)', + 'dacli test render --module=di --id=841610403778660420 # 验证某条接口详情 schema 完整性', + 'dacli test render --module=menu # 验证菜单 list 字段 + form 字段 ⊆ api (webapi 镜像, parentId 树形 + systemId 应用隔离 + propertyJson schema)', + 'dacli test render --module=menu --id=841765096471398533 # 验证某条菜单 propertyJson 完整性 (moduleId/webType/isTree/iconBackgroundColor)', ], source: { - web: 'web/.../sysData/dictionary/{index,Form,components/index,components/Form}.vue + web/.../FormGenerator/ + web/.../ColumnDesign/', - api: 'web/.../api/systemData/dictionary.ts + web/.../api/onlineDev/visualDev.ts (Base/{id} info, OnlineDev/{modelId}/List)', + web: 'web/.../sysData/dictionary/{index,Form,components/index,components/Form}.vue + web/.../FormGenerator/ + web/.../dataCenter/dataInterface/{index,Form,Preview}.vue + web/.../permission/menu/{index,Form}.vue', + api: 'web/.../api/systemData/dictionary.ts + web/.../api/onlineDev/visualDev.ts + web/.../api/systemData/dataInterface.ts + web/.../api/system/menu.ts (loadMenu webapi 镜像)', }, notes: [ '**v0.11+ NEW (2026-06-27)**: 沉淀自 Batch 1 字典验证 (用户拍板: 替代浏览器验证)', '**v0.11+ form module (2026-06-27)**: 添加 form module, 验证 formData.fields + columnData.columnList 渲染契约', + '**v0.14+ di module (2026-07-01)**: 添加 di module, 镜像 web DataInterface 渲染 + SQL/API/WebSocket 三类型 schema 校验 (dacli test render --module=di)', + '**v0.14+ menu module (2026-07-01)**: 添加 menu module, 镜像 web Menu 渲染 + propertyJson schema 校验 (dacli test render --module=menu)', '**vs 浏览器测试**: 速度 2s vs 30s, 不需 playwright, 不依赖 SPA 路由 (JNPF admin 经常菜单 404)', '**能查**: 字段缺失 / schema 漂移 / API 返字段不对 / enCode 不匹配渲染契约', '**查不出**: vmodel bind bug (浏览器 JS) / 控件渲染异常 → 这些仍需 ssw-e2e-test', '**B 铁律对应**: B1 列表渲染 / B2 表单渲染 / B3 详情渲染 / B4 更新后状态', '**算法 (dict)**: 读 vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 API 返字段对比, 缺则 FAIL', '**算法 (form)**: 读 formData.fields[].__vModel__ (含主子表递归) + columnData.columnList[].prop → 与 API 返字段对比', + '**算法 (di)**: 读 views/dataCenter/dataInterface/{index,Form}.vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 loadDataInterface webapi 镜像对比 → 4 关卡 (list 字段 ⊆ api / form 字段 ⊆ api / 必填 5 字段 (fullName/enCode/category/type/enabledMark) / SQL/API/WebSocket schema 完整性)', + '**算法 (menu)**: 读 views/permission/menu/{index,Form}.vue 提取 BasicColumn.dataIndex + useForm schemas.field → 与 loadMenu.getMenuList/getInfo webapi 镜像对比 → 4 关卡 (list 字段 ⊆ api / form 字段 ⊆ api / 必填 parentId 树形 + systemId 应用隔离 + moduleId 关联 / propertyJson schema 完整性 moduleId/webType/isTree/iconBackgroundColor)', ], }) return cmd @@ -585,6 +600,410 @@ async function renderForm( } } +// ============================================================================ +// Menu module (v0.14+ NEW, 2026-07-01 — 镜像 §TC-C 4 关卡真实契约) +// +// 算法 (4 关卡): +// 1. 读 web 端 views/permission/menu/index.vue (BasicColumn.dataIndex 列表字段) +// + views/permission/menu/Form.vue (useForm schemas[].field 表单字段) +// 2. 调 loadMenu.getMenuList (走 webapi 镜像) → 取第一层+递归子菜单, 合并字段并集 +// 3. 4 关卡: +// 3.1 list 字段 ⊆ api 字段 (BasicColumn 必能渲染) +// 3.2 form 字段 ⊆ api 字段 (form schemas 必能 setFieldsValue) +// 3.3 必填/外键/关联完整性: parentId 树形 (-1 顶级) + systemId 应用隔离 + moduleId 关联 form +// 3.4 schema 完整性: propertyJson JSON.parse OK + 必含 moduleId/iconBackgroundColor (isTree/webType 按 type 变) +// 4. --id= 时追加单条菜单 propertyJson schema 校验 (第 5 个关卡) +// +// 镜像 web 端: +// - web/.../permission/menu/index.vue L44-71 menuTableColumns BasicColumn +// - web/.../permission/menu/Form.vue L88-182 useForm schemas +// - web/.../permission/menu/Form.vue L209-227 getInfo: data.propertyJson → JSON.parse → data.moduleId = propertyJson.moduleId +// - web/.../api/system/menu.ts getMenuList (ModuleBySystem) + getInfo +// ============================================================================ + +/** + * 从菜单树递归提取所有菜单项 (含 children 嵌套) + */ +function flattenMenuTree(items: any[]): any[] { + const out: any[] = [] + const walk = (nodes: any[]) => { + if (!Array.isArray(nodes)) return + for (const n of nodes) { + if (n && typeof n === 'object') out.push(n) + if (n?.children) walk(n.children) + } + } + walk(items) + return out +} + +/** + * 从 menu web 列表 vue 提取 BasicColumn.dataIndex + * 镜像 web/.../permission/menu/index.vue L44-71 menuTableColumns + */ +async function extractMenuListRenderFields(): Promise { + const vueFile = `${WEB_ROOT}/views/permission/menu/index.vue` + const src = await fs.readFile(vueFile, 'utf-8') + const { descriptor } = parse(src) + const ss = descriptor.scriptSetup?.content || '' + // 找 menuTableColumns 数组里的 dataIndex + const m = ss.match(/menuTableColumns[\s\S]*?\n\]/) + if (!m) return [] + const fields: string[] = [] + const re = /dataIndex:\s*['"]([^'"]+)['"]/g + let mm + while ((mm = re.exec(m[0])) !== null) fields.push(mm[1]) + return fields +} + +/** + * 从 menu web 表单 vue 提取 useForm schemas[].field + * 镜像 web/.../permission/menu/Form.vue L88-182 + */ +async function extractMenuFormRenderFields(): Promise { + const vueFile = `${WEB_ROOT}/views/permission/menu/Form.vue` + const src = await fs.readFile(vueFile, 'utf-8') + const { descriptor } = parse(src) + const ss = descriptor.scriptSetup?.content || '' + // 找 schemas 数组里的 field (Form.vue L88 有完整 const schemas: FormSchema[] = [...]) + const m = ss.match(/const\s+schemas[\s\S]*?\n\]/) + if (!m) { + // 退化: 匹配 schemas: [...](隐式类型) + const m2 = ss.match(/schemas:\s*\[[\s\S]*?\n\s*\]/) + if (!m2) return [] + return extractFieldsFromBlock(m2[0]) + } + return extractFieldsFromBlock(m[0]) +} + +function extractFieldsFromBlock(block: string): string[] { + const fields: string[] = [] + const re = /field:\s*['"]([^'"]+)['"]/g + let mm + while ((mm = re.exec(block)) !== null) fields.push(mm[1]) + return fields +} + +/** + * 渲染 menu module: 4 关卡 + 可选第 5 关卡 (单条 propertyJson 完整性) + */ +async function renderMenu( + c: JnpfClient, + opts: RenderOpts, + results: RenderCheckResult[], + logFn: { info: (...a: unknown[]) => void; warn: (...a: unknown[]) => void; error: (...a: unknown[]) => void } = real, +): Promise { + await initWebapiMenu(c) + const lg = logFn + + // === 1. 读 web 端渲染契约 === + let listFields: string[] = [] + let formFields: string[] = [] + try { + listFields = await extractMenuListRenderFields() + if (listFields.length === 0) { + lg.warn('菜单列表渲染字段为空 (未提取到 menuTableColumns, 检查 index.vue 结构)') + } + } catch (e) { + lg.error(`读 menu index.vue 失败: ${(e as Error).message}`) + } + try { + formFields = await extractMenuFormRenderFields() + if (formFields.length === 0) { + lg.warn('菜单表单渲染字段为空 (未提取到 schemas, 检查 Form.vue 结构)') + } + } catch (e) { + lg.error(`读 menu Form.vue 失败: ${(e as Error).message}`) + } + + // === 2. 调 webapi 拿实际数据 === + let apiFlat: any[] = [] + let apiSource: 'live-data' | 'empty' = 'empty' + try { + const r: any = await loadMenu.getMenuList({}) + // 兼容 {list: [...]} 和直接 [...] 两种返回 + const list = Array.isArray(r) ? r : Array.isArray(r?.list) ? r.list : [] + apiFlat = flattenMenuTree(list) + apiSource = apiFlat.length > 0 ? 'live-data' : 'empty' + } catch (e) { + lg.error(`getMenuList 失败: ${(e as Error).message}`) + } + + // 收集 API 字段 (所有样本的字段并集) + const apiFieldSet = new Set() + for (const item of apiFlat) { + if (item && typeof item === 'object') { + for (const k of Object.keys(item)) apiFieldSet.add(k) + } + } + const apiFields = Array.from(apiFieldSet).sort() + + if (apiSource === 'empty') { + lg.warn('菜单 API 返回空, 字段对比会标记全部缺失 (无菜单数据, 可通过 dacli menu list --include-actions 创建测试菜单)') + // 仍走流程, 但 missing=renderFields + } + + // === 3.1 Gate 1: 列表字段 ⊆ api 字段 === + { + const renderSet = new Set(listFields) + const missing = listFields.filter(f => !apiFieldSet.has(f)) + const extra = apiFields.filter(f => !renderSet.has(f)) + const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'menu', + page: '菜单列表', + sourceFile: 'views/permission/menu/index.vue (menuTableColumns L44-71)', + renderFields: listFields, + apiFields, + missing, + extra, + status, + }) + const icon = status === 'PASS' ? '✓' : '✗' + lg.info(`${icon} 菜单列表: ${status} (${listFields.length} 渲染字段, ${apiFields.length} API 字段 [源:${apiSource}]${missing.length ? `, 缺 ${missing.length}` : ''})`) + } + + // === 3.2 Gate 2: 表单字段 ⊆ api 字段 (getMenuList ∪ getInfo) === + // 镜像 web Form.vue L209-227: init(data) 走 getInfo(id) 拿完整字段 (含 description/linkTarget/category/moduleId) + // getInfo 返 propertyJson (string) → JSON.parse → data.moduleId = propertyJson.moduleId + // 所以 form 必填字段应 ⊆ (list API 字段 ∪ info API 字段 ∪ propertyJson.* 解析字段) + let infoUnionSet = new Set() + let infoSource = 'list-only' + if (apiFlat.length > 0) { + // 拿第一条菜单调 getInfo (info 字段集对所有菜单结构相同, 抽样即可) + const sample = apiFlat.find(m => m.id) || apiFlat[0] + try { + const infoResp: any = await loadMenu.getInfo(sample.id) + const data = (infoResp as any)?.data || infoResp + if (data && typeof data === 'object') { + infoSource = 'list+info' + for (const k of Object.keys(data)) infoUnionSet.add(k) + // propertyJson 解析后字段也算 API 字段 (web 端 Form.vue L211-213 会 parse + 展开 moduleId) + if (typeof data.propertyJson === 'string') { + try { + const parsed = JSON.parse(data.propertyJson) + if (parsed && typeof parsed === 'object') { + infoUnionSet.add('propertyJson_parsed') + for (const k of Object.keys(parsed)) infoUnionSet.add(`propertyJson.${k}`) + } + } catch { /* ignore */ } + } + } + } catch (e) { + lg.warn(`getInfo(${sample.id}) 失败 (Gate 2 仅用 list): ${(e as Error).message}`) + } + } + // list 字段 + info 字段 + propertyJson.* 字段 合并为表单渲染所需 API 字段 + const formApiFieldSet = new Set([...apiFieldSet, ...infoUnionSet]) + const formApiFields = Array.from(formApiFieldSet).sort() + // 处理 propertyJson.moduleId 这种"点路径"映射: vue field='moduleId' 对应 API 字段 propertyJson.moduleId + const resolveField = (f: string) => apiFieldSet.has(f) || infoUnionSet.has(f) || + infoUnionSet.has(`propertyJson.${f}`) + { + const renderSet = new Set(formFields) + const missing = formFields.filter(f => !resolveField(f)) + const extra = formApiFields.filter(f => !renderSet.has(f)) + const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'menu', + page: '菜单表单', + sourceFile: 'views/permission/menu/Form.vue (schemas L88-182) + getInfo (Form.vue L209-227)', + renderFields: formFields, + apiFields: formApiFields, + missing, + extra, + status, + }) + const icon = status === 'PASS' ? '✓' : '✗' + lg.info(`${icon} 菜单表单: ${status} (${formFields.length} 渲染字段, ${formApiFields.length} API 字段 [源:${infoSource}]${missing.length ? `, 缺 ${missing.length}` : ''})`) + } + + // === 3.3 Gate 3: 必填/外键/关联完整性 (parentId 树形 + systemId 应用隔离 + moduleId 关联 form) === + // 镜像 web 端: + // - 树形: parentId='-1' 顶级, 否则挂父节点; Form.vue L88-95 TreeSelect 必填 + // - 应用隔离: systemId == 当前 appCode 的 systemId (请求头 App-Code 决定); 每个菜单项必须带 systemId + // - moduleId 关联: propertyJson.moduleId 关联 form/dict/dataV/portal/flow (类型 3/4/5/6/8/9/10/11) + const treeIssues: string[] = [] + const isoIssues: string[] = [] + const moduleIdIssues: string[] = [] + const needModuleIdTypes = new Set([3, 4, 5, 6, 8, 9, 10, 11]) + if (apiFlat.length > 0) { + // 树形: 顶级菜单 parentId 应为 '-1' 或 '0' (JNPF 用 -1, 但兼容 0) + const topLevel = apiFlat.filter(m => m.parentId === '-1' || m.parentId === '0' || !m.parentId) + if (topLevel.length === 0) { + treeIssues.push(`无顶级菜单 (parentId='-1'/'0' 缺失, ${apiFlat.length} 项全部为子菜单)`) + } + // 每条非顶级必须有 parentId 引用顶级或同级 + const allIds = new Set(apiFlat.map(m => m.id).filter(Boolean)) + for (const m of apiFlat) { + if (m.parentId && m.parentId !== '-1' && m.parentId !== '0' && !allIds.has(m.parentId)) { + treeIssues.push(`菜单 ${m.fullName || m.id} parentId=${m.parentId} 引用不存在`) + } + } + // 应用隔离: 每条菜单应有 systemId + const noSystemId = apiFlat.filter(m => !m.systemId) + if (noSystemId.length > 0) { + isoIssues.push(`${noSystemId.length} 项缺 systemId (${noSystemId.slice(0, 3).map(m => m.fullName || m.id).join(', ')}${noSystemId.length > 3 ? '...' : ''})`) + } + // moduleId 关联: 类型 3/4/5/6/8/9/10/11 必须有 moduleId (propertyJson.moduleId 提取在 web Form.vue L213) + const noModuleId = apiFlat.filter(m => { + if (!needModuleIdTypes.has(Number(m.type))) return false + // 顶级目录类型 1 不需要 moduleId + // propertyJson 可能是字符串, 解析看 moduleId + let moduleId: any = null + if (typeof m.propertyJson === 'string') { + try { + const parsed = JSON.parse(m.propertyJson || '{}') + moduleId = parsed?.moduleId + } catch { /* ignore */ } + } else if (m.propertyJson && typeof m.propertyJson === 'object') { + moduleId = m.propertyJson.moduleId + } + return !moduleId + }) + if (noModuleId.length > 0) { + moduleIdIssues.push(`${noModuleId.length} 项 type∈{3,4,5,6,8,9,10,11} 缺 propertyJson.moduleId (${noModuleId.slice(0, 3).map(m => m.fullName || m.id).join(', ')}${noModuleId.length > 3 ? '...' : ''})`) + } + } else { + treeIssues.push('无菜单数据 (跳过树形/外键/关联校验)') + } + { + const allIssues = [...treeIssues, ...isoIssues, ...moduleIdIssues] + const status: 'PASS' | 'FAIL' = allIssues.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'menu', + page: '必填/外键/关联完整性', + sourceFile: 'parentId 树形 + systemId 应用隔离 + propertyJson.moduleId 关联 (web Form.vue L88-95/L213)', + renderFields: ['parentId', 'systemId', 'moduleId'], + apiFields: ['parentId', 'systemId', 'propertyJson.moduleId'], + missing: allIssues, + extra: [], + status, + }) + if (allIssues.length === 0) { + const topCount = apiFlat.filter(m => m.parentId === '-1' || m.parentId === '0').length + lg.info(`✓ 必填/外键/关联完整性: PASS (${apiFlat.length} 菜单项, 顶级 ${topCount}, tree/systemId/moduleId 全部完整)`) + } else { + lg.error(`✗ 必填/外键/关联完整性: FAIL (${allIssues.slice(0, 3).join(' | ')}${allIssues.length > 3 ? '...' : ''})`) + } + } + + // === 3.4 Gate 4: schema 完整性 (propertyJson JSON.parse + 必含 moduleId/iconBackgroundColor) === + // 镜像 web Form.vue L211-213: data.propertyJson = JSON.parse(data.propertyJson) → data.moduleId = propertyJson.moduleId + // propertyJson 必含字段: moduleId (按 type 必填), iconBackgroundColor (图标背景色, 始终存在) + // 按 type 可选: webType (type 3/11), isTree (type 4) + const propertyJsonIssues: string[] = [] + let propertyJsonParsed = 0 + if (apiFlat.length > 0) { + for (const m of apiFlat) { + if (m.propertyJson == null) { + // propertyJson 可为空 (顶级目录可能没设置), 不算 issue, 跳过 + continue + } + if (typeof m.propertyJson !== 'string') { + propertyJsonIssues.push(`菜单 ${m.fullName || m.id} propertyJson 类型不对 (期望 string JSON, 实际 ${typeof m.propertyJson})`) + continue + } + try { + const parsed = JSON.parse(m.propertyJson) + propertyJsonParsed++ + if (typeof parsed !== 'object' || parsed === null) { + propertyJsonIssues.push(`菜单 ${m.fullName || m.id} propertyJson 解析后非对象`) + continue + } + // 必含: iconBackgroundColor (Form.vue L46-49 默认值) + if (parsed.iconBackgroundColor === undefined) { + propertyJsonIssues.push(`菜单 ${m.fullName || m.id} propertyJson 缺 iconBackgroundColor`) + } + // type∈{3,4,5,6,8,9,10,11} 必须有 moduleId (复用 Gate 3 的 needModuleIdTypes) + if (needModuleIdTypes.has(Number(m.type)) && !parsed.moduleId) { + propertyJsonIssues.push(`菜单 ${m.fullName || m.id} type=${m.type} propertyJson 缺 moduleId`) + } + } catch (e) { + propertyJsonIssues.push(`菜单 ${m.fullName || m.id} propertyJson JSON.parse 失败: ${(e as Error).message.slice(0, 80)}`) + } + } + } + { + const status: 'PASS' | 'FAIL' = propertyJsonIssues.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'menu', + page: 'propertyJson schema 完整性', + sourceFile: 'propertyJson: JSON.parse → {moduleId, iconBackgroundColor, webType?, isTree?} (Form.vue L211-213)', + renderFields: ['moduleId', 'iconBackgroundColor', 'webType?', 'isTree?'], + apiFields: apiFlat.filter(m => m.propertyJson).map(m => `${m.fullName || m.id}.propertyJson`).slice(0, 5), + missing: propertyJsonIssues, + extra: [], + status, + }) + if (propertyJsonIssues.length === 0) { + lg.info(`✓ propertyJson schema: PASS (${propertyJsonParsed} 个 propertyJson 全部 JSON.parse OK + 必含字段完整)`) + } else { + lg.error(`✗ propertyJson schema: FAIL (${propertyJsonIssues.slice(0, 3).join(' | ')}${propertyJsonIssues.length > 3 ? '...' : ''})`) + } + } + + // === 3.5 Gate 5 (可选, --id): 单条菜单 propertyJson + getInfo 完整字段校验 === + // 镜像 web Form.vue L209-227 init(data): getInfo(id) → JSON.parse(propertyJson) → 必含 linkTarget/category/description + if (opts.id) { + let infoDetail: any + try { + infoDetail = await loadMenu.getInfo(opts.id) + } catch (e) { + lg.error(`getInfo(${opts.id}) 失败: ${(e as Error).message}`) + infoDetail = null + } + const data = (infoDetail as any)?.data || infoDetail + if (!data || typeof data !== 'object') { + lg.error(`getInfo(${opts.id}) 返回非对象: ${JSON.stringify(infoDetail).slice(0, 200)}`) + } else { + const infoFieldSet = new Set(Object.keys(data)) + const infoFields = Array.from(infoFieldSet).sort() + // form 必填字段 (来自 Form.vue schemas + getInfo 派生: moduleId 是 propertyJson.moduleId) + const requiredInfoFields = [ + 'parentId', 'fullName', 'enCode', 'icon', 'type', + 'sortCode', 'enabledMark', 'noShow', + 'linkTarget', 'category', 'description', 'propertyJson', 'systemId', + ] + const missing = requiredInfoFields.filter(f => !infoFieldSet.has(f)) + // 解析 propertyJson + let propertyJsonOk = false + let propertyJsonDetails = '' + if (typeof data.propertyJson === 'string') { + try { + const parsed = JSON.parse(data.propertyJson) + if (parsed && typeof parsed === 'object') { + propertyJsonOk = true + propertyJsonDetails = `moduleId=${parsed.moduleId || '<空>'}, iconBackgroundColor=${parsed.iconBackgroundColor || '<空>'}` + if (parsed.moduleId === undefined) missing.push('propertyJson.moduleId') + } + } catch (e) { + missing.push(`propertyJson JSON.parse 失败: ${(e as Error).message.slice(0, 60)}`) + } + } else if (data.propertyJson && typeof data.propertyJson === 'object') { + propertyJsonOk = true + propertyJsonDetails = `moduleId=${data.propertyJson.moduleId || '<空>'}, iconBackgroundColor=${data.propertyJson.iconBackgroundColor || '<空>'}` + } + const status: 'PASS' | 'FAIL' = missing.length === 0 && propertyJsonOk ? 'PASS' : 'FAIL' + results.push({ + module: 'menu', + page: '单条菜单 getInfo 完整性', + sourceFile: `getInfo (menuId=${opts.id}, propertyJson: ${propertyJsonDetails})`, + renderFields: requiredInfoFields, + apiFields: infoFields, + missing, + extra: [], + status, + }) + if (status === 'PASS') { + lg.info(`✓ 单条菜单 getInfo: PASS (${infoFields.length} 字段, ${propertyJsonDetails})`) + } else { + lg.error(`✗ 单条菜单 getInfo: FAIL (${missing.slice(0, 3).join(' | ')}${missing.length > 3 ? '...' : ''})`) + } + } + } +} + // ============================================================================ // Dict module // ============================================================================ @@ -601,6 +1020,7 @@ async function renderDict( // 注: components/index.vue 是"字典分类管理"抽屉的 vue, 用 BasicColumn 渲染类型 await checkRender({ pageName: '字典类型列表', + moduleName: 'dict', vueFile: `${WEB_ROOT}/views/sysData/dictionary/components/index.vue`, vueMode: 'list', // 只取 BasicColumn apiCall: async () => { @@ -625,6 +1045,7 @@ async function renderDict( if (opts.id) { await checkRender({ pageName: '字典类型编辑表单', + moduleName: 'dict', vueFile: `${WEB_ROOT}/views/sysData/dictionary/components/Form.vue`, vueMode: 'form', // 只取 useForm schemas apiCall: async () => { @@ -641,6 +1062,7 @@ async function renderDict( if (opts.typeId) { await checkRender({ pageName: '字典数据列表', + moduleName: 'dict', vueFile: `${WEB_ROOT}/views/sysData/dictionary/index.vue`, vueMode: 'list', apiCall: async () => { @@ -657,6 +1079,7 @@ async function renderDict( if (opts.typeId && opts.id) { await checkRender({ pageName: '字典数据编辑表单', + moduleName: 'dict', vueFile: `${WEB_ROOT}/views/sysData/dictionary/Form.vue`, vueMode: 'form', apiCall: async () => { @@ -670,6 +1093,182 @@ async function renderDict( } } +// ============================================================================ +// Di module (数据接口, v0.14+ 新增, 2026-07-01) +// ============================================================================ + +async function renderDi( + c: JnpfClient, + opts: RenderOpts, + results: RenderCheckResult[], + logFn: { info: (...a: unknown[]) => void; warn: (...a: unknown[]) => void; error: (...a: unknown[]) => void } = real, +): Promise { + await initWebapiDi(c) + const lg = logFn + + // === 关卡 1: 列表字段 ⊆ api 字段 === + // 镜像 web 端: + // - views/dataCenter/dataInterface/index.vue L30-37 BasicColumn: + // fullName / enCode / type / creatorTime / sortCode / enabledMark + // - loadDataInterface.getDataInterfaceList → GET /api/system/DataInterface + // 返回 DataInterfaceListVO: id/fullName/type/enCode/sortCode/enabledMark/creatorTime/tenantId/isPostPosition + await checkRender({ + pageName: 'di 列表', + moduleName: 'di', + vueFile: `${WEB_ROOT}/views/dataCenter/dataInterface/index.vue`, + vueMode: 'list', + apiCall: async () => { + const r = (await loadDataInterface.getDataInterfaceList({ currentPage: 1, pageSize: 50 })) as any + // webapi shim 已 unwrap: {data:{list:[]}} 或 {list:[]} + const list = Array.isArray(r?.data?.list) ? r.data.list : Array.isArray(r?.list) ? r.list : [] + return list + }, + results, + log: logFn, + onEmptyApi: 'SKIP', + }) + + // === 关卡 2: 表单字段 ⊆ api 字段 === + // 镜像 web 端: + // - views/dataCenter/dataInterface/Form.vue L164-252 useForm.schemas (10 字段): + // fullName / enCode / category / type / action / sortCode / enabledMark / + // hasPage / isPostPosition / description + // - loadDataInterface.getDataInterfaceInfo → GET /api/system/DataInterface/{id} + // 返回 DataInterfaceVo (id/enCode/fullName/category/type/hasPage/action/sortCode/ + // enabledMark/description/fieldJson/parameterJson/isPostPosition/dataConfigJson/...) + let formInfoId: string | undefined = opts.id + if (!formInfoId) { + // 拿第 1 条数据接口用作详情 schema 校验 + try { + const r = (await loadDataInterface.getDataInterfaceList({ currentPage: 1, pageSize: 5 })) as any + const list = Array.isArray(r?.data?.list) ? r.data.list : Array.isArray(r?.list) ? r.list : [] + if (list.length > 0) { + formInfoId = list[0].id + lg.info(`di 表单字段对比: 用第 1 条接口 id=${formInfoId} (fullName=${list[0].fullName || '?'})`) + } else { + lg.warn(`di 表单字段对比: 列表为空且未传 --id, 跳过 (form/schema 关卡需真实存在接口)`) + } + } catch (e) { + lg.warn(`di 表单字段对比: getDataInterfaceList 失败: ${(e as Error).message}`) + } + } + + if (formInfoId) { + let formInfoData: any = null + try { + const r = (await loadDataInterface.getDataInterfaceInfo(formInfoId)) as any + formInfoData = (r?.data !== undefined ? r.data : r) + } catch (e) { + lg.warn(`getDataInterfaceInfo 失败 (id=${formInfoId}): ${(e as Error).message}`) + } + + if (formInfoData && typeof formInfoData === 'object') { + // 关卡 2 主对比 + await checkRender({ + pageName: 'di 表单', + moduleName: 'di', + vueFile: `${WEB_ROOT}/views/dataCenter/dataInterface/Form.vue`, + vueMode: 'form', + apiCall: async () => [formInfoData], + results, + log: logFn, + }) + + // === 关卡 3: 必填字段完整性 (镜像 web _validate.ts + Form.vue L165-251) === + // 4 个核心必填字段 (rules: required): fullName / enCode / category / type + if (opts.requiredFieldCheck !== false) { + const requiredFields = ['fullName', 'enCode', 'category', 'type'] + const missingRequired: string[] = [] + for (const k of requiredFields) { + if (formInfoData[k] === undefined || formInfoData[k] === null || formInfoData[k] === '') { + missingRequired.push(k) + } + } + const status: 'PASS' | 'FAIL' = missingRequired.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'di', + page: 'di 必填字段完整性', + sourceFile: `DataInterfaceVo (id=${formInfoId})`, + renderFields: requiredFields, + apiFields: requiredFields.filter(k => formInfoData[k] !== undefined), + missing: missingRequired, + extra: [], + status, + }) + if (missingRequired.length === 0) { + lg.info(`✓ di 必填字段完整性: PASS (${requiredFields.length} 个必填字段 (fullName/enCode/category/type) 全部非空)`) + } else { + lg.error(`✗ di 必填字段完整性: FAIL (缺 ${missingRequired.length} 个: ${missingRequired.join(', ')})`) + } + } + + // === 关卡 4: schema 完整性 (SQL/API/静态 三类型) === + // 镜像 web 端 Form.vue L79-93 defaultJson 结构: + // 静态 (id=2): dataConfigJson.staticData (string) + // SQL (id=1): dataConfigJson.sqlData.{dbLinkId, sql} + // API (id=3): dataConfigJson.apiData.{method, url, header, query, body, bodyType} + // 注: JNPF UI 配置器只支持 static/SQL/API 三类型. + if (opts.columnListRequired !== false) { + const type = Number(formInfoData.type) + const schemaIssues: string[] = [] + + // dataConfigJson 是 string, 解析 + let dataConfigJson: any = formInfoData.dataConfigJson + if (typeof dataConfigJson === 'string') { + try { dataConfigJson = JSON.parse(dataConfigJson) } catch { dataConfigJson = null } + } + + if (!dataConfigJson || typeof dataConfigJson !== 'object') { + schemaIssues.push('dataConfigJson 缺失或解析失败 (三类型 schema 不可能正确)') + } else { + if (type === 1) { + // SQL 类型 — 镜像 Form.vue L82-84 defaultJson.sqlData + const sql = dataConfigJson.sqlData || {} + if (!sql.dbLinkId && sql.dbLinkId !== '0' && sql.dbLinkId !== 0) schemaIssues.push('type=1 SQL dataConfigJson.sqlData.dbLinkId 缺失') + if (!sql.sql) schemaIssues.push('type=1 SQL dataConfigJson.sqlData.sql 缺失') + } else if (type === 2) { + // 静态类型 — 镜像 Form.vue L80 defaultJson.staticData + if (!dataConfigJson.staticData && dataConfigJson.staticData !== '') schemaIssues.push('type=2 静态 dataConfigJson.staticData 缺失') + } else if (type === 3) { + // API 类型 — 镜像 Form.vue L85-92 defaultJson.apiData + const api = dataConfigJson.apiData || {} + if (!api.method) schemaIssues.push('type=3 API dataConfigJson.apiData.method 缺失') + if (!api.url) schemaIssues.push('type=3 API dataConfigJson.apiData.url 缺失') + if (!Array.isArray(api.header)) schemaIssues.push('type=3 API dataConfigJson.apiData.header 非数组') + if (!Array.isArray(api.query)) schemaIssues.push('type=3 API dataConfigJson.apiData.query 非数组') + if (api.body === undefined) schemaIssues.push('type=3 API dataConfigJson.apiData.body 缺失') + if (api.bodyType === undefined) schemaIssues.push('type=3 API dataConfigJson.apiData.bodyType 缺失') + } else { + schemaIssues.push(`未知 type=${type} (JNPF UI 仅支持 type=1=SQL / 2=静态 / 3=API)`) + } + } + + const status: 'PASS' | 'FAIL' = schemaIssues.length === 0 ? 'PASS' : 'FAIL' + results.push({ + module: 'di', + page: `di schema (type=${type})`, + sourceFile: `dataConfigJson (id=${formInfoId})`, + renderFields: type === 1 ? ['sqlData.dbLinkId', 'sqlData.sql'] + : type === 2 ? ['staticData'] + : type === 3 ? ['apiData.method', 'apiData.url', 'apiData.header', 'apiData.query', 'apiData.body', 'apiData.bodyType'] + : [], + apiFields: [], + missing: schemaIssues, + extra: [], + status, + }) + if (schemaIssues.length === 0) { + lg.info(`✓ di schema (type=${type}): PASS (镜像 web Form.vue L79-93 defaultJson 三类型结构)`) + } else { + lg.error(`✗ di schema (type=${type}): FAIL (${schemaIssues.slice(0, 3).join(' | ')}${schemaIssues.length > 3 ? '...' : ''})`) + } + } + } else { + lg.warn(`di 表单 schema: getDataInterfaceInfo 未返回有效对象, 跳过 form/required/schema 3 关卡`) + } + } +} + // 日志门面 (json 模式静默, 否则用 log) const real = { info: log.info, @@ -693,6 +1292,8 @@ interface CheckOpts { apiCall: () => Promise results: RenderCheckResult[] log: { info: (...a: unknown[]) => void; warn: (...a: unknown[]) => void; error: (...a: unknown[]) => void } + moduleName: string // 用于标记 results.module 字段 + onEmptyApi?: 'FAIL' | 'SKIP' // API 空数据时: FAIL (默认, 跟 form 一致) / SKIP (dict 列表为空, 可选跳过) } async function checkRender(opts: CheckOpts): Promise { @@ -716,18 +1317,35 @@ async function checkRender(opts: CheckOpts): Promise { } if (apiData.length === 0) { - lg.warn(`${opts.pageName}: API 返回空, 跳过字段对比 (无数据可对比)`) - opts.results.push({ - module: 'dict', - page: opts.pageName, - sourceFile: opts.vueFile.replace(WEB_ROOT, '...'), - renderFields, - apiFields: [], - missing: renderFields, - extra: [], - status: 'FAIL', - }) - return + const emptyBehavior = opts.onEmptyApi ?? 'FAIL' + if (emptyBehavior === 'SKIP') { + lg.warn(`${opts.pageName}: API 返回空, 跳过字段对比 (无数据可对比)`) + opts.results.push({ + module: opts.moduleName, + page: opts.pageName, + sourceFile: opts.vueFile.replace(WEB_ROOT, '...'), + renderFields, + apiFields: [], + missing: renderFields, // 镜像 dict 行为: 空数据时所有渲染字段算 missing + extra: [], + status: 'FAIL', + }) + return + } else { + // FAIL 模式: 当列表/数据不存在时, 整体视为渲染失败 + lg.warn(`${opts.pageName}: API 返回空 (FAIL 模式)`) + opts.results.push({ + module: opts.moduleName, + page: opts.pageName, + sourceFile: opts.vueFile.replace(WEB_ROOT, '...'), + renderFields, + apiFields: [], + missing: renderFields, + extra: [], + status: 'FAIL', + }) + return + } } // 3. 提取 API 字段 (所有样本的字段并集) @@ -749,7 +1367,7 @@ async function checkRender(opts: CheckOpts): Promise { const status: 'PASS' | 'FAIL' = missing.length === 0 ? 'PASS' : 'FAIL' opts.results.push({ - module: 'dict', + module: opts.moduleName, page: opts.pageName, sourceFile: opts.vueFile.replace(WEB_ROOT, '...'), renderFields,