diff --git a/src/commands/portal/release.ts b/src/commands/portal/release.ts index 0dfd9ca..cb68d56 100644 --- a/src/commands/portal/release.ts +++ b/src/commands/portal/release.ts @@ -58,19 +58,50 @@ export function buildPortalReleaseCommand(): Command { // === step 0.5 BS-109: 自动检测 pcModuleParentId/appModuleParentId === // v0.15+ 修复 (2026-07-02): 用 ctx.topLevelMenus (id+fullName 对象数组) 替代 ctx.menus:string[] // + ctx.currentSystemId 替代不存在的 currentSystemId 字段 (P0-1 已补) + // v0.15+ (P2-9, 2026-07-02): 性能优化 — 替代 loadAppContext() (拉 5 个 list ~3-5s 延迟) + // 改用单 API: loadMenu.getMenuList() (拉菜单) + loadSystem.getSystemList() (拉 currentSystemId) + // 节省 4 个无用 list 调用 (forms/dm/workflows/currentUser) let pcSystemId = opts.pcSystemId let pcModuleParentId = opts.pcModuleParentId let appSystemId = opts.appSystemId let appModuleParentId = opts.appModuleParentId try { - const ctx = await loadAppContext() - if (!pcSystemId && ctx.currentSystemId) pcSystemId = ctx.currentSystemId - if (!appSystemId && ctx.currentSystemId) appSystemId = ctx.currentSystemId + // 先从 ~/.dacli-token/category-cache.json 读 currentSystemId (跟 P0-1 一致) + // category-cache 通常都有, 1 次 fs.readFile 即可, 免去调 system list API + if (!pcSystemId || !appSystemId) { + try { + const { homedir } = await import('node:os') + const { join, resolve } = await import('node:path') + const { existsSync, readFileSync } = await import('node:fs') + const dir = process.env.DACLI_TOKEN_DIR ? resolve(process.env.DACLI_TOKEN_DIR) : join(homedir(), '.dacli-token') + const cachePath = join(dir, 'category-cache.json') + if (existsSync(cachePath)) { + const cache = JSON.parse(readFileSync(cachePath, 'utf-8')) as Record + if (cache[c.appCode]?.id) { + if (!pcSystemId) pcSystemId = cache[c.appCode].id + if (!appSystemId) appSystemId = cache[c.appCode].id + } + } + } catch { + // 读失败, 后续兜底 + } + } + + // 直接调 menu list (替代 loadAppContext 拉 5 个 list) + // topLevelMenus 派生自 menu list 的 parentId=0/-1 过滤 (跟 P0-1 tryFetchMenus 行为一致) + const menuWebapi = await import('../../webapi/menu.ts') + await menuWebapi.initWebapi(c) + const menuResp = (await menuWebapi.loadMenu.getMenuList()) as { data?: { list?: Array<{ id?: string; fullName?: string; parentId?: string | number; enCode?: string; category?: string }> } } | unknown + const allMenus = (menuResp as { data?: { list?: unknown[] } })?.data?.list + || (Array.isArray(menuResp) ? menuResp as unknown[] : []) + const topLevelMenus = (allMenus as Array<{ id?: string; fullName?: string; parentId?: string | number; enCode?: string; category?: string }>) + .filter((m) => m && (m.parentId === '0' || m.parentId === '-1' || m.parentId === 0 || m.parentId === -1)) + .map((m) => ({ id: String(m.id || ''), fullName: m.fullName, parentId: String(m.parentId ?? ''), enCode: m.enCode, category: m.category })) + .filter((m) => m.id) // 自动检测顶级菜单 (BS-109, 跟 BS-106 menu create 模式一致) // FINDING-P4 (2026-07-02 audit): PC/App 端菜单树分离, 应分别取 // category: 'Web' / 'App' (web 端 ReleaseModal.vue:104/108 行为) - const topLevelMenus = ctx.topLevelMenus || [] const pcTop = topLevelMenus.find((m) => m.category === 'Web' || m.category === undefined || m.category === '') const appTop = topLevelMenus.find((m) => m.category === 'App') if (topLevelMenus.length > 0) { @@ -94,7 +125,7 @@ export function buildPortalReleaseCommand(): Command { log.warn(` 或显式传 --pcModuleParentId= --pcSystemId=`) } } catch (e) { - log.warn(`BS-109: AppContext 加载失败 (${(e as Error).message?.slice(0, 100)}), 跳过自动检测`) + log.warn(`BS-109: menu/system 加载失败 (${(e as Error).message?.slice(0, 100)}), 跳过自动检测`) } // === step 1 构造 pc/app/platformRelease (镜像 web ReleaseModal.vue:80) ===