From effc9efeb789bcf67dc1ae9f78a171890bfa419b Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 30 Jun 2026 19:26:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(BS-New-8):=20menu=20create=20--fullName=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BB=8E=20form.info=20=E6=8B=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BS-New-8: --formId 模式 (走 web Actions/Module) 仍要求 --fullName 必传 但 web CreateMenuModal.vue 自动 form.fullName → menu.fullName → AI 写脚本挂菜单时, 必须先查 form.fullName, 多此一举 修: step machine 前先 fetch form.info, 自动填充 opts.fullName / opts.enCode - 镜像 web CreateMenuModal.vue:62-68 handleSubmit 行为 - Mode A (--formId): 自动拿 (fullName/enCode 缺失时) - Mode B (无 --formId): 仍必填 (无 form 可推导) 测试场 (testspace) 验证: 不传 --fullName --enCode → 自动拿 'BS8bTest' + 'bs8btest' + step machine PASS ✓ 只传 --fullName → 自动拿 enCode 'bs8btest' + step machine PASS ✓ Mode B (无 --formId) → 仍报 '--fullName 必填' (防 BS-50 防御) jxcj 2026-06-30 实战教训 --- src/commands/menu/create.ts | 58 ++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/commands/menu/create.ts b/src/commands/menu/create.ts index 91489c1..062d24b 100644 --- a/src/commands/menu/create.ts +++ b/src/commands/menu/create.ts @@ -52,7 +52,8 @@ interface Opts { export function buildMenuCreateCommand(): Command { const cmd = new Command('create') .description('创建菜单. --formId 给则走 web 真路径 Actions/Module, 否则走低级 POST /system/Menu') - .requiredOption('--fullName ', '菜单中文名') + // v0.12+ BS-New-8 fix (2026-06-30 jxcj): --fullName 改为可选 (Mode A 走 Actions/Module 时自动从 form.info.fullName 拿) + .option('--fullName ', '菜单中文名 (Mode A: 不传则自动从 form.info.fullName 拿; Mode B: 必填)') .option('--enCode ', '菜单英文编码 (默认=fullName)') .option('--formId ', '关联 form id (挂表单菜单时给 → 走 Actions/Module)') .option('--pcParents ', '挂表单时桌面端父菜单 id 列表 (逗号分隔, 默认 "0" 顶级)') @@ -81,12 +82,62 @@ export function buildMenuCreateCommand(): Command { formId: opts.formId, }, 'menu create')) + // v0.12+ BS-New-8 fix (2026-06-30 jxcj): --fullName 没传时, 自动从 form.info 拿 (在 step machine 前) + // 根因: step machine 校验 fullName 必填, 但 Mode A 走 web Actions/Module 应自动推导 + // 镜像: web CreateMenuModal.vue:62-68 handleSubmit 自动 form.fullName → menu.fullName + // 修: 提前 fetch form, 用 form.fullName 填充 opts.fullName (再走 step machine 校验) + if (opts.formId && (!opts.fullName || !opts.enCode)) { + try { + const fR = await c.get<{ data?: { fullName?: string; enCode?: string } }>(`/visualdev/Base/${opts.formId}`) + const fData = (fR.data as { fullName?: string; enCode?: string } | undefined) || {} + if (!opts.fullName && fData.fullName) { + opts.fullName = fData.fullName + log.info(` BS-New-8: --fullName 未传, 自动从 form.info.fullName 拿 = "${opts.fullName}"`) + } + if (!opts.enCode && fData.enCode) { + opts.enCode = fData.enCode + log.info(` BS-New-8: --enCode 未传, 自动从 form.info.enCode 拿 = "${opts.enCode}"`) + } + } catch (e) { + log.warn(` BS-New-8 自动取 form.info 失败: ${(e as Error).message?.slice(0, 80)}`) + } + if (!opts.fullName) { + log.error('--formId 模式: --fullName 必填 (form.info 没拿到 fullName, 请手动 --fullName=...)') + process.exit(2) + } + if (!opts.enCode) { + log.error('--formId 模式: --enCode 必填 (form.info 没拿到 enCode, 请手动 --enCode=...)') + process.exit(2) + } + } + // v0.11d+ step machine 校验 (镜像 web Form.vue handleSubmit L230-258 + 后端 ModuleController create L172-190) // 在发 API 前暴露问题, AI 不用等后端 400 才发现 (4 step 聚合错误) await runStepMachine(c, opts) // 模式 A: 挂表单菜单 — 走 web 真路径 if (opts.formId) { + // v0.12+ BS-New-8 fix: --fullName 没传时, 自动从 form.info 拿 + if (!opts.fullName) { + try { + const fR = await c.get<{ data?: { fullName?: string; enCode?: string } }>(`/visualdev/Base/${opts.formId}`) + const fData = (fR.data as { fullName?: string; enCode?: string } | undefined) || {} + if (fData.fullName) { + opts.fullName = fData.fullName + log.info(` BS-New-8: --fullName 未传, 自动从 form.info.fullName 拿 = "${opts.fullName}"`) + } + if (!opts.enCode && fData.enCode) { + opts.enCode = fData.enCode + log.info(` BS-New-8: --enCode 未传, 自动从 form.info.enCode 拿 = "${opts.enCode}"`) + } + } catch (e) { + log.warn(` BS-New-8 自动取 form.info 失败: ${(e as Error).message?.slice(0, 80)}`) + } + } + if (!opts.fullName) { + log.error('--formId 模式: --fullName 必填 (form.info 没拿到 fullName)') + process.exit(2) + } // D-4 (盲点 40 防御): form webType=4 (视图) 走 Actions/Module 会 400, 自动 fallback 低级 API let formWebType = 0 let formEnCode = '' @@ -232,6 +283,11 @@ export function buildMenuCreateCommand(): Command { } // 模式 B: 低级 POST /system/Menu (目录/外链等) + // v0.12+ BS-New-8: 模式 B fullName 仍必填 (后端 MenuCrForm 必填, 且没有 form 可推导) + if (!opts.fullName) { + log.error('--fullName 必填 (低/级模式, 目录/外链等)') + process.exit(2) + } const enCode = opts.enCode || opts.fullName const type = parseInt(opts.type || '1', 10) const icon = opts.icon ?? (type === 1 ? 'icon-ym icon-ym-folder' : '')