From ab875344e646ce0d91e58e16af6c8f92d47f3c1f Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 2 Jul 2026 11:46:18 +0800 Subject: [PATCH] =?UTF-8?q?P0-3=20=E4=BF=AE=E5=A4=8D:=20portal=20setDefaul?= =?UTF-8?q?t=20=E8=B5=B0=20menu=20list=20=E6=89=BE=20moduleId=20(BS-110,?= =?UTF-8?q?=202026-07-02)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FINDING-P3: portal setDefault 旧版用 loadPortal.getInfo(portalId) 查 PortalEntity.moduleId 但 PortalEntity 是 portal 表实体 (fullName/enCode/category), 没有 moduleId 字段 → portalId 路径 100% 走'BS-110 无法解析 menuId'错误 后端真值 PortalDataController.setDefault: moduleService.getInfo(id) → portalService.getById(module.getModuleId()) 即 setDefault 收的是 menuId, portalId→menuId 需要查 module(moduleId=portalId) 修复: - 用 webapi/menu.getList() 走 MenuBySystem 拿所有菜单, 客户端 filter moduleId=portalId - initMenuWebapi 初始化 menu 模块 - 错误提示: 0 菜单时 portal 必须先 release (release 会自动建菜单, moduleId=portalId) 审计: dacli/docs/cmd-review/v0.14-rollout-audit-2026-07-02.md §3.1 P0/P3 --- src/commands/portal/setDefault.ts | 43 ++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/commands/portal/setDefault.ts b/src/commands/portal/setDefault.ts index 238621e..5578617 100644 --- a/src/commands/portal/setDefault.ts +++ b/src/commands/portal/setDefault.ts @@ -8,12 +8,13 @@ * - 错误信息: "The portal has been deleted" (VS415) * * 修复: - * - 接受 --portalId 或 --menuId 二选一 (推荐 --portalId, 命令内部 portal.id → menu.id) - * - 内部走 webapi/portal.setDefaultPortal, 实际传 menu id + * - 接受 --portalId 或 --menuId 二选一 (推荐 --menuId 直接传, 避免 portalId→menuId 链路) + * - 若传 --portalId: 走 menu list 过滤 moduleId=portalId, 找对应菜单 id * * 镜像源: * - 后端 PortalDataController.setDefault (走 module → portal 链路) * - webapi/portal.ts: setDefaultPortal (Proxy 暴露) + * - webapi/menu.ts: getMenuList (用 moduleId 过滤) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -23,6 +24,10 @@ import { initWebapi as initPortalWebapi, loadPortal, } from '../../webapi/portal.ts' +import { + initWebapi as initMenuWebapi, + loadMenu, +} from '../../webapi/menu.ts' interface SetDefaultOpts { portalId?: string @@ -30,18 +35,31 @@ interface SetDefaultOpts { json?: boolean } -/** 通过 portalId 查 menuId (镜像 web 端实现, 但简化) */ -async function resolveMenuIdFromPortal(portalId: string, client: JnpfClient): Promise { +/** v0.15+ (BS-110 fix, 2026-07-02): 通过 portalId 查 menuId (走 webapi menu list) + * 旧版 v0.14+ 用 loadPortal.getInfo 查 PortalEntity.moduleId 错误 (PortalEntity 无此字段) + * 新版走 loadMenu.getList 过滤 moduleId=portalId, 跟 jnpf 后端 ModuleService.list 行为一致 + * 镜像源: webapi/menu.ts: getMenuList (镜像 web/api/system/menu.ts:9 ModuleBySystem) + */ +async function resolveMenuIdFromPortal(portalId: string, _client: JnpfClient): Promise { try { - // 走 webapi portal info, 看是否有 menu id 字段 - const r = (await loadPortal.getInfo(portalId)) as { data?: any } | any - const data = r?.data || r - if (data?.moduleId) return String(data.moduleId) - if (data?.menuId) return String(data.menuId) - log.warn(`portal id=${portalId} info 中未找到 menuId/moduleId, 请显式传 --menuId`) + // 走 webapi menu list 找 moduleId=portalId 的菜单 + // 注: web ModuleBySystem 不支持 moduleId 过滤, 但 list 接口支持 (走 kw + 后端 sql filter) + // 兜底: 先 list 全部再客户端 filter + const r = (await loadMenu.getList()) as { data?: unknown } | unknown + const list = (r as { data?: { list?: unknown[] } })?.data?.list + || (Array.isArray(r) ? r as unknown[] : []) + const matched = (list as Array<{ id?: string; moduleId?: string }>).find( + (m) => String(m.moduleId || '') === String(portalId), + ) + if (matched?.id) { + log.dim(` resolveMenuIdFromPortal: portalId=${portalId} → menuId=${matched.id}`) + return String(matched.id) + } + log.warn(`portal id=${portalId} 在 menu list 中无 moduleId 匹配项, 请显式传 --menuId`) + log.warn(` 提示: 0 菜单时 portal 必须先 release (release 会自动建菜单, moduleId=portalId)`) return null } catch (e) { - log.warn(`portal info 异常: ${(e as Error).message?.slice(0, 100)}`) + log.warn(`menu list 异常: ${(e as Error).message?.slice(0, 100)}`) return null } } @@ -57,12 +75,13 @@ export function buildPortalSetDefaultCommand(): Command { .action(async (opts: SetDefaultOpts) => { if (!opts.portalId && !opts.menuId) { log.error('必传 --portalId 或 --menuId (二选一)') - log.error('提示: 推荐 --portalId, 命令内部自动 portal.id → menu.id 转换') + log.error('提示: 推荐 --menuId 直接传, 避免 portalId → menuId 链路 (走 menu list 过滤 moduleId)') process.exit(1) } const c = await JnpfClient.fromToken() await initPortalWebapi(c) + await initMenuWebapi(c) // v0.15+: portalId 路径走 menu list 找 moduleId // === BS-110: setDefaultPortal 实际收 menu id, portal.id → menu.id === let menuId: string | null = null