diff --git a/src/commands/form/info.ts b/src/commands/form/info.ts index c597d8f..92595dc 100644 --- a/src/commands/form/info.ts +++ b/src/commands/form/info.ts @@ -29,20 +29,35 @@ async function resolveFormId(input: string): Promise<{ id: string; resolvedFrom: if (/^[\d-]+$/.test(input) && input.length >= 10) { return { id: input, resolvedFrom: 'literal' } } - // 否则按 enCode 查 + // 否则按 enCode 查 — 注意: web 端 getVisualDevList 用 keyword 做 exact-match, + // 若 enCode 大小写不一致 (e.g. 输入 "tdd8customermanage" 但实际 enCode="tdd8CustomerManage") + // → 返回 0 条. fallback: keyword 0 条时拉全量 + 客户端模糊匹配 const c = await JnpfClient.fromToken() await initWebapi(c) - const resp = (await loadVisualDev.getVisualDevList({ - keyword: input, - currentPage: 1, - pageSize: 200, - })) as { list?: Array<{ id?: string; enCode?: string; fullName?: string }> } - const list = resp.list || [] - // 精确匹配 enCode (优先); 否则 fullName 包含; 最后模糊 enCode + let list: Array<{ id?: string; enCode?: string; fullName?: string }> = [] + try { + const resp = (await loadVisualDev.getVisualDevList({ + keyword: input, + currentPage: 1, + pageSize: 200, + })) as { list?: Array<{ id?: string; enCode?: string; fullName?: string }> } + list = resp.list || [] + } catch { /* fallback below */ } + // keyword 查询 0 条时, 拉全量客户端模糊匹配 (单 app 表单数一般 < 500, pageSize=500 安全) + if (list.length === 0) { + const resp = (await loadVisualDev.getVisualDevList({ + currentPage: 1, + pageSize: 500, + })) as { list?: Array<{ id?: string; enCode?: string; fullName?: string }> } + list = resp.list || [] + } + // 精确匹配 enCode (优先); 否则 fullName 包含; 最后模糊 enCode (toLowerCase 兼容 PascalCase) + const inputLower = input.toLowerCase() const exact = list.find((f) => f.enCode === input) const byName = list.find((f) => f.fullName === input) - const fuzzy = list.find((f) => (f.enCode || '').toLowerCase().includes(input.toLowerCase())) - const hit = exact || byName || fuzzy + const fuzzyEnCode = list.find((f) => (f.enCode || '').toLowerCase() === inputLower) + const fuzzyPartial = list.find((f) => (f.enCode || '').toLowerCase().includes(inputLower)) + const hit = exact || byName || fuzzyEnCode || fuzzyPartial if (!hit || !hit.id) { throw new Error(`enCode 未匹配到 form: "${input}" (list 返回 ${list.length} 条, 请用 dacli form list 查正确 enCode)`) }