P0 修复:
- relationForm typo: ' popupTable' / searchForms 杜撰字段移除 (create.ts:299 → {})
- columnDataObj 补 29 字段: ruleList/funcs/tabConfig/viewKey/defaultColumnList 等
- useOverflow → showOverflow 命名对齐 web ColumnDesign
- printId → printIds 类型对齐 (数组 vs 单值)
P1 修复:
- buildColumnListEntry 补 31 字段: tag/tagIcon/visibility/layout/span/renderKey/fullNameI18nCode 等
- buildSearchListEntry value: '' → [] (数组, datePicker 期望)
- searchMultiple: 0 → false (bool 类型对齐)
L2 guard BS-51 降级: v0.11 schema 修复后, 简化 path 不再盲点
审计文档: doc/audit-form-create-deviations.md (659 行)
验证脚本: doc/verify-form-create-fix.mjs (99 PASS / 0 FAIL)
Co-Authored-By: Claude <[email protected]>
125 lines
6.3 KiB
JavaScript
125 lines
6.3 KiB
JavaScript
// /home/ubuntu/ccWorkDir/docs/dacli/verify-form-create-fix.mjs
|
|
// 验证 v0.11 修复后的 schema 与 web 一致(只读)
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
const SRC = '/home/ubuntu/ccWorkDir/dacli/src/commands/form/create.ts'
|
|
const src = readFileSync(SRC, 'utf8')
|
|
|
|
// 改进:跟踪 brace 深度 + 引号状态,正确提取顶层 key
|
|
function extractTopLevelKeys(startMarker, srcText) {
|
|
const startIdx = srcText.indexOf(startMarker)
|
|
if (startIdx === -1) return { keys: [], start: -1, end: -1 }
|
|
const objStart = srcText.indexOf('{', startIdx)
|
|
if (objStart === -1) return { keys: [], start: -1, end: -1 }
|
|
|
|
let depth = 0, inString = false, stringChar = '', inComment = false, inLineComment = false
|
|
let objEnd = -1
|
|
for (let i = objStart; i < srcText.length; i++) {
|
|
const ch = srcText[i], next = srcText[i + 1]
|
|
if (inLineComment) { if (ch === '\n') inLineComment = false; continue }
|
|
if (inComment) { if (ch === '*' && next === '/') { inComment = false; i++ }; continue }
|
|
if (inString) {
|
|
if (ch === '\\') { i++; continue }
|
|
if (ch === stringChar) inString = false
|
|
continue
|
|
}
|
|
if (ch === '/' && next === '/') { inLineComment = true; i++; continue }
|
|
if (ch === '/' && next === '*') { inComment = true; i++; continue }
|
|
if (ch === '"' || ch === "'" || ch === '`') { inString = true; stringChar = ch; continue }
|
|
if (ch === '{') depth++
|
|
else if (ch === '}') { depth--; if (depth === 0) { objEnd = i; break } }
|
|
}
|
|
if (objEnd === -1) return { keys: [], start: -1, end: -1 }
|
|
|
|
const body = srcText.slice(objStart, objEnd + 1)
|
|
const keys = []
|
|
// 处理同一行多个 key (如 `columnOptions: [], defaultColumnList: [],`)
|
|
// 用后行断言避免匹配 value 中的对象 key (如 funcs.afterOnload)
|
|
const re = /(?:^|[\s,{(])([a-zA-Z_$][\w$]*)\s*:/gm
|
|
let m
|
|
while ((m = re.exec(body)) !== null) keys.push(m[1])
|
|
return { keys, start: objStart, end: objEnd }
|
|
}
|
|
|
|
const cd = extractTopLevelKeys('const columnDataObj: any = {', src)
|
|
const fd = extractTopLevelKeys('const formData = {', src)
|
|
|
|
console.log(`columnDataObj 字段数: ${cd.keys.length}`)
|
|
console.log(`formData 字段数: ${fd.keys.length}\n`)
|
|
|
|
// === 必填 web defaultColumnData 字段 ===
|
|
const REQUIRED_CD = [
|
|
'ruleList', 'resizable', 'showOverflow', 'childTableStyle', 'showSummary',
|
|
'columnOptions', 'defaultColumnList', 'viewKey', 'hasPage', 'groupField',
|
|
'parentField', 'printIds', 'useColumnPermission', 'useFormPermission',
|
|
'useBtnPermission', 'useDataPermission', 'btnsList', 'columnBtnsList',
|
|
'funcs', 'tabConfig', 'relationForm', 'type', 'pageSize', 'columnList',
|
|
'searchList', 'treeTitle', 'treeDataSource', 'treePropsValue',
|
|
'treePropsLabel', 'cardListConfig', 'complexHeaderList', 'tableConfig',
|
|
'uploaderTemplateJson'
|
|
]
|
|
const REQUIRED_FD = [
|
|
'formRef', 'formModel', 'size', 'labelPosition', 'labelWidth', 'labelSuffix',
|
|
'formRules', 'popupType', 'generalWidth', 'fullScreenWidth', 'drawerWidth',
|
|
'gutter', 'disabled', 'span', 'colon', 'hasCancelBtn', 'hasConfirmBtn',
|
|
'confirmButtonText', 'cancelButtonText', 'hasConfirmAndAddBtn', 'hasPrintBtn',
|
|
'printButtonText', 'customBtns', 'appCustomBtns', 'primaryKeyPolicy',
|
|
'concurrencyLock', 'logicalDelete', 'dataLog', 'useBusinessKey',
|
|
'businessKeyList', 'businessKeyTip', 'printId', 'formStyle', 'classNames',
|
|
'className', 'classJson', 'detailExtraList', 'fields', 'tableName'
|
|
]
|
|
|
|
let pass = 0, fail = 0
|
|
|
|
console.log('=== columnDataObj 字段核对 (web defaultColumnData 1:1 对齐) ===')
|
|
for (const k of REQUIRED_CD) {
|
|
if (cd.keys.includes(k)) { console.log(`✓ ${k.padEnd(28)}`); pass++ }
|
|
else { console.log(`✗ ${k.padEnd(28)} — 缺失!`); fail++ }
|
|
}
|
|
|
|
console.log('\n=== formData 字段核对 (web formData schema) ===')
|
|
for (const k of REQUIRED_FD) {
|
|
if (fd.keys.includes(k)) { console.log(`✓ ${k.padEnd(28)}`); pass++ }
|
|
else { console.log(`✗ ${k.padEnd(28)} — 缺失!`); fail++ }
|
|
}
|
|
|
|
console.log('\n=== relationForm typo / 杜撰字段 ===')
|
|
if (src.includes("' popupTable'")) { console.log('✗ FAIL: 仍含 \' popupTable\' typo'); fail++ }
|
|
else { console.log('✓ PASS: 无 \' popupTable\' typo'); pass++ }
|
|
if (src.includes('searchForms')) { console.log('✗ FAIL: 仍含 searchForms 杜撰字段'); fail++ }
|
|
else { console.log('✓ PASS: 无 searchForms'); pass++ }
|
|
|
|
console.log('\n=== printId vs printIds 类型修复 ===')
|
|
// formData.printId 单值是允许的 (form 有自己的 printId 字段, 与 columnData.printIds 不同)
|
|
if (fd.keys.includes('printId')) { console.log('✓ PASS: formData.printId 单值 (web formData 也有)'); pass++ }
|
|
else { console.log('✗ FAIL: formData.printId 缺失'); fail++ }
|
|
if (cd.keys.includes('printIds')) { console.log('✓ PASS: columnData.printIds 数组'); pass++ }
|
|
else { console.log('✗ FAIL: columnData.printIds 缺失'); fail++ }
|
|
|
|
console.log('\n=== useOverflow → showOverflow 命名修复 ===')
|
|
if (cd.keys.includes('showOverflow')) { console.log('✓ PASS: showOverflow 存在'); pass++ }
|
|
else { console.log('✗ FAIL: 缺 showOverflow'); fail++ }
|
|
|
|
console.log('\n=== buildColumnListEntry 关键字段 ===')
|
|
const ENTRY_KEY = ['fullNameI18nCode', 'clearable', 'disabled', 'style', 'on', 'placeholder', 'renderKey', 'tag', 'tagIcon', 'visibility']
|
|
const fn1Start = src.indexOf('const buildColumnListEntry =')
|
|
const fn1End = src.indexOf('const buildSearchListEntry =', fn1Start)
|
|
const fn1Body = src.slice(fn1Start, fn1End)
|
|
for (const k of ENTRY_KEY) {
|
|
// 既支持 `${k}:` (literal) 也支持 `${k},` (对象简写) 也支持 `${k}\n` (跨行)
|
|
if (fn1Body.includes(`${k}:`) || fn1Body.includes(`${k},`) || fn1Body.includes(`${k}\n`)) { console.log(`✓ PASS: buildColumnListEntry.${k}`); pass++ }
|
|
else { console.log(`✗ FAIL: buildColumnListEntry 缺 ${k}`); fail++ }
|
|
}
|
|
|
|
console.log('\n=== buildSearchListEntry 关键字段 ===')
|
|
const fn2Start = src.indexOf('const buildSearchListEntry =')
|
|
const fn2End = src.indexOf('const tables', fn2Start)
|
|
const fn2Body = src.slice(fn2Start, fn2End)
|
|
const ENTRY2_KEY = ['fullNameI18nCode', 'clearable', 'disabled', 'style', 'placeholder', 'on', 'value', 'searchMultiple', 'sourceType', 'searchType', 'isKeyword', 'noShow']
|
|
for (const k of ENTRY2_KEY) {
|
|
if (fn2Body.includes(`${k}:`)) { console.log(`✓ PASS: buildSearchListEntry.${k}`); pass++ }
|
|
else { console.log(`✗ FAIL: buildSearchListEntry 缺 ${k}`); fail++ }
|
|
}
|
|
|
|
console.log(`\n=== 总计: ${pass} PASS / ${fail} FAIL ===`)
|
|
process.exit(fail > 0 ? 1 : 0) |