From 4f510efc1be71cade8c1f2b5f4370feda7f3627c Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 3 Sep 2026 11:08:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E6=94=AF=E6=8C=81=E4=BB=A3?= =?UTF-8?q?=E5=AE=A2=E5=8D=8F=E5=8A=A9=E5=B9=B3=E5=8F=B0=E5=87=AD=E8=AF=81?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E8=AF=86=E5=88=AB=E3=80=81Token=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E6=84=9F=E7=9F=A5=E4=B8=8E=E5=8D=95=E6=8D=AE=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E5=A2=9E=E5=BC=BA=E5=B9=B6=E5=8F=91=E5=B8=83=20v0.3.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- openapi/openapi.yaml | 2 +- package.json | 2 +- src/cli/commands/auth.ts | 65 ++++++++++++++-- src/cli/commands/corps.ts | 39 ++++++++-- src/cli/commands/probe.ts | 18 ++++- src/cli/printer.ts | 37 +++++++++ src/core/auth/login.ts | 155 +++++++++++++++++++++++++++++++++++-- src/core/config/manager.ts | 2 + src/core/config/types.ts | 31 +++++++- src/domains/bill/tools.ts | 53 ++++++++++++- src/version.ts | 2 +- 12 files changed, 376 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index e94ef08..51704f6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hose-use (v0.3.0) +# hose-use (v0.3.1) 合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。 diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 9385e4b..1f571db 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: hose-use API & MCP Tools Specification - version: 0.3.0 + version: 0.3.1 description: >- Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows. servers: diff --git a/package.json b/package.json index 8311579..b958c7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.3.0", + "version": "0.3.1", "module": "src/server.ts", "type": "module", "bin": { diff --git a/src/cli/commands/auth.ts b/src/cli/commands/auth.ts index 5cc5c19..2efd710 100644 --- a/src/cli/commands/auth.ts +++ b/src/cli/commands/auth.ts @@ -3,6 +3,7 @@ import { fullSmsLogin, fullBrowserSyncLogin, sendSmsVerificationCode, + importCredentials, importF12Credentials, parseHeadersOrCurl, refreshAccountCorporations, @@ -14,7 +15,7 @@ import { } from "../../core/auth/account-store.js"; import { createEkbClient } from "../../core/auth/ekb.js"; import { stringOption, booleanOption } from "../parser.js"; -import { printJson, printKeyValue, printTable } from "../printer.js"; +import { printJson, printKeyValue, printTable, formatSourceLabel, formatExpiresAt } from "../printer.js"; import { prompt } from "../helpers.js"; import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; @@ -171,13 +172,41 @@ async function handleStatus(parsed: CliParsedArgs, runtime: CliRuntime): Promise return { stdout: printJson(statusObj), stderr: "", exitCode: 0 }; } - const summary = printKeyValue({ + const pairs: Record = { "当前活跃账号": activeAccount?.accountId || "未登录", "当前激活企业": currentCorp ? `${currentCorp.name} (${currentCorp.id})` : "未配置", "当前员工工号": currentCorp?.credentials.staffId || "-", - "凭证来源类型": currentCorp?.source || "-", + "员工真实姓名": currentCorp?.staffName || currentCorp?.session?.staffName || "-", + "凭证来源类型": formatSourceLabel(currentCorp?.source), "Token 有效性": sessionValid ? "✅ 有效 (已通过 Session 验证)" : "❌ 无效或未连接", - }); + "Token 过期时间": formatExpiresAt(currentCorp?.auth?.expiresAt || currentCorp?.session?.expTime), + }; + + if (currentCorp?.session) { + if (currentCorp.session.loginTime) { + pairs["会话创建时间"] = new Date(currentCorp.session.loginTime).toLocaleString("zh-CN", { hour12: false }); + } + if (currentCorp.session.platform) { + pairs["官方平台类型"] = currentCorp.session.platform; + } + if (currentCorp.session.isAssistPlatform) { + pairs["协助调试模式"] = "是 (Assist Platform)"; + if (currentCorp.session.operationUserName || currentCorp.session.operationUserId) { + pairs["协助操作人员"] = `${currentCorp.session.operationUserName || ""} (${currentCorp.session.operationUserId || ""})`.trim(); + } + if (currentCorp.session.assistId) { + pairs["协助会话 ID"] = currentCorp.session.assistId; + } + } + if (currentCorp.session.cellphone) { + pairs["绑定手机号码"] = currentCorp.session.cellphone; + } + if (currentCorp.session.isAdmin !== undefined) { + pairs["是否企业管理"] = currentCorp.session.isAdmin ? "是" : "否"; + } + } + + const summary = printKeyValue(pairs); return { stdout: `====== 当前登录与企业状态 ======\n${summary}\n`, @@ -209,7 +238,7 @@ async function handleImport(parsed: CliParsedArgs, runtime: CliRuntime): Promise let name = stringOption(parsed.options, ["name"]); if (!raw && !accessToken) { - raw = await prompt("请粘贴 F12 抓包文本 / cURL 命令行 (直接回车则手动逐项输入): "); + raw = await prompt("请粘贴抓包文本 / cURL 命令行 (直接回车则手动逐项输入): "); } if (raw) { @@ -227,7 +256,7 @@ async function handleImport(parsed: CliParsedArgs, runtime: CliRuntime): Promise return { stdout: "", stderr: "accessToken, corpId, staffId 均为必填!\n", exitCode: 1 }; } - const imported = await importF12Credentials({ + const imported = await importCredentials({ accessToken, corpId, staffId, @@ -238,8 +267,30 @@ async function handleImport(parsed: CliParsedArgs, runtime: CliRuntime): Promise return { stdout: printJson(imported), stderr: "", exitCode: 0 }; } + const summaryPairs: Record = { + "企业名称": imported.name, + "企业 ID": imported.id, + "员工工号": imported.credentials.staffId, + "员工姓名": imported.staffName || imported.session?.staffName || "-", + "凭证来源": formatSourceLabel(imported.source), + "过期时间": formatExpiresAt(imported.auth?.expiresAt || imported.session?.expTime), + "保存路径": `enterprises/${imported.id}.json`, + }; + + if (imported.session?.isAssistPlatform) { + summaryPairs["协助平台"] = "是 (Assist Platform 调试授权)"; + if (imported.session.operationUserName || imported.session.operationUserId) { + summaryPairs["协助操作人"] = `${imported.session.operationUserName || ""} (${imported.session.operationUserId || ""})`.trim(); + } + if (imported.session.assistId) { + summaryPairs["协助会话 ID"] = imported.session.assistId; + } + } + + const summaryText = printKeyValue(summaryPairs); + return { - stdout: `[SUCCESS] 成功导入并保存企业凭证!\n企业名称: ${imported.name}\n企业 ID: ${imported.id}\n员工工号: ${imported.credentials.staffId}\n保存路径: enterprises/${imported.id}.json\n`, + stdout: `[SUCCESS] 成功导入并保存企业凭证!\n${summaryText}\n`, stderr: "", exitCode: 0, }; diff --git a/src/cli/commands/corps.ts b/src/cli/commands/corps.ts index ce14ce8..f301ebb 100644 --- a/src/cli/commands/corps.ts +++ b/src/cli/commands/corps.ts @@ -1,4 +1,4 @@ -import { printJson, printKeyValue, printTable } from "../printer.js"; +import { printJson, printKeyValue, printTable, formatSourceLabel, formatExpiresAt } from "../printer.js"; import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; export async function handleCorpsCommand( @@ -48,11 +48,12 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise = { "企业 ID": current.id, "企业名称": current.name, "员工工号": current.credentials.staffId, - "来源类型": current.source || "manual", + "员工姓名": current.staffName || current.session?.staffName || "-", + "凭证来源": formatSourceLabel(current.source), + "Token 过期时间": formatExpiresAt(current.auth?.expiresAt || current.session?.expTime), "所属账号": current.accountId || "-", "主站地址": current.baseUrl || "https://app.ekuaibao.com", - }); + }; + + if (current.session) { + if (current.session.loginTime) { + pairs["会话创建时间"] = new Date(current.session.loginTime).toLocaleString("zh-CN", { hour12: false }); + } + if (current.session.platform) { + pairs["官方平台类型"] = current.session.platform; + } + if (current.session.isAssistPlatform) { + pairs["协助登录模式"] = "是 (Assist Platform)"; + if (current.session.operationUserName || current.session.operationUserId) { + pairs["协助操作人员"] = `${current.session.operationUserName || ""} (${current.session.operationUserId || ""})`.trim(); + } + if (current.session.assistId) { + pairs["协助会话 ID"] = current.session.assistId; + } + } + if (current.session.cellphone) { + pairs["绑定手机号码"] = current.session.cellphone; + } + if (current.session.isAdmin !== undefined) { + pairs["是否企业管理"] = current.session.isAdmin ? "是" : "否"; + } + } + + const output = printKeyValue(pairs); return { stdout: `====== 当前激活企业 ======\n${output}\n`, diff --git a/src/cli/commands/probe.ts b/src/cli/commands/probe.ts index a03e887..ac61942 100644 --- a/src/cli/commands/probe.ts +++ b/src/cli/commands/probe.ts @@ -1,6 +1,6 @@ import { createClientsForCorp } from "../helpers.js"; import * as api from "../../domains/platform/api.js"; -import { printJson, printKeyValue } from "../printer.js"; +import { printJson, printKeyValue, formatSourceLabel, formatExpiresAt } from "../printer.js"; import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; export async function handleProbeCommand( @@ -79,14 +79,26 @@ export async function handleProbeCommand( return { stdout: printJson(results), stderr: "", exitCode: 0 }; } - const summary = printKeyValue({ + const probePairs: Record = { "企业名称": currentCorp.name, "企业 ID": currentCorp.id, "员工工号": currentCorp.credentials.staffId, + "员工姓名": currentCorp.staffName || currentCorp.session?.staffName || "-", + "凭证来源": formatSourceLabel(currentCorp.source), + "Token 过期时间": formatExpiresAt(currentCorp.auth?.expiresAt || currentCorp.session?.expTime), "主站 Session 连通": (results.ekbSession as any).status === "ok" ? "🟢 正常" : "🔴 异常", "EASO 引擎鉴权换票": (results.easoToken as any).status === "ok" ? "🟢 握手成功" : "🔴 失败", "自建应用扫描": (results.platformAccess as any).status === "ok" ? `🟢 可访问 (${(results.platformAccess as any).totalPlatforms} 个自建应用)` : "🔴 失败", - }); + }; + + if (currentCorp.session?.isAssistPlatform) { + probePairs["协助操作人"] = `${currentCorp.session.operationUserName || ""} (${currentCorp.session.operationUserId || ""})`.trim(); + if (currentCorp.session.assistId) { + probePairs["协助会话 ID"] = currentCorp.session.assistId; + } + } + + const summary = printKeyValue(probePairs); return { stdout: `====== 诊断结果 (Enterprise Probe) ======\n${summary}\n`, diff --git a/src/cli/printer.ts b/src/cli/printer.ts index 8c4d08b..d60bb48 100644 --- a/src/cli/printer.ts +++ b/src/cli/printer.ts @@ -4,6 +4,43 @@ export function printJson(data: unknown): string { return JSON.stringify(data, null, 2); } +export function formatSourceLabel(source?: string): string { + switch (source) { + case "assist": + return "官方协助/代客平台 (Assist Platform)"; + case "account": + return "统一认证中心 (IDP 账密/短信)"; + case "browser": + return "浏览器会话同步 (WebBridge)"; + case "curl": + case "f12": + return "cURL 抓包导入 (cURL/F12)"; + case "manual": + return "手动配置"; + default: + return source || "未知来源"; + } +} + +export function formatExpiresAt(expiresAt?: number): string { + if (!expiresAt || expiresAt <= 0) return "长期有效 / 服务端未显式限制"; + const diffMs = expiresAt - Date.now(); + const dateStr = new Date(expiresAt).toLocaleString("zh-CN", { hour12: false }); + if (diffMs <= 0) { + return `${dateStr} (⚠️ 已过期)`; + } + const diffMins = Math.floor(diffMs / 60000); + if (diffMins < 60) { + return `${dateStr} (约剩余 ${diffMins} 分钟)`; + } + const diffHours = (diffMs / 3600000).toFixed(1); + if (Number(diffHours) < 24) { + return `${dateStr} (约剩余 ${diffHours} 小时)`; + } + const diffDays = Math.floor(diffMs / 86400000); + return `${dateStr} (约剩余 ${diffDays} 天)`; +} + export function printKeyValue(pairs: Record): string { const lines: string[] = []; const maxKeyLen = Math.max(...Object.keys(pairs).map((k) => k.length), 0); diff --git a/src/core/auth/login.ts b/src/core/auth/login.ts index ca6abbb..8174da3 100644 --- a/src/core/auth/login.ts +++ b/src/core/auth/login.ts @@ -263,13 +263,35 @@ export function parseHeadersOrCurl(rawInput: string): Partial { } } + // 3. 从 URL 中提取 query 参数(例如 ?corpId=xxx 或 &corpId=xxx) + if (!result.corpId) { + const urlCorpMatch = /(?:[?&]corpId=)([^&'"\s]+)/i.exec(rawInput); + if (urlCorpMatch) { + result.corpId = decodeURIComponent(urlCorpMatch[1]); + } + } + + // 4. 从 Cookie (-b / Cookie header) 中提取 ekb-access-token 或 corpId + if (!result.accessToken) { + const cookieTokenMatch = /ekb-access-token=([^;'"\s]+)/i.exec(rawInput); + if (cookieTokenMatch) { + result.accessToken = decodeURIComponent(cookieTokenMatch[1]); + } + } + if (!result.corpId) { + const cookieCorpMatch = /(?:^|;\s*)corpId=([^;'"\s]+)/i.exec(rawInput); + if (cookieCorpMatch) { + result.corpId = decodeURIComponent(cookieCorpMatch[1]); + } + } + return result; } /** - * 校验并导入单个 F12 抓包/手动凭证,保存到企业配置 + * 校验并导入单个抓包/手动凭证,自动探测官方 Session 平台类型并保存到企业配置 */ -export async function importF12Credentials( +export async function importCredentials( params: F12ImportParams ): Promise { const { accessToken, corpId, staffId } = params; @@ -279,8 +301,25 @@ export async function importF12Credentials( throw new AuthenticationError("导入凭证失败:accessToken、corpId、staffId 均为必填项"); } - // 验证凭证有效性并尝试自动获取企业名称 - let corpName = params.name; + // 1. 验证凭证有效性并提取官方服务端 Session 元数据 + let sessionData: { + id?: string; + userId?: string; + loginStaffId?: string; + corporationId?: string; + platform?: string; + isAssistPlatform?: boolean; + isShortTermToken?: boolean; + assistId?: string; + operationUserId?: string; + operationUserName?: string; + privilege?: string; + deviceType?: string; + loginAccountType?: string; + loginTime?: number; + expTime?: number; + } | undefined; + try { const res = await ky .get(`${baseUrl}/api/account/v2/session`, { @@ -290,20 +329,102 @@ export async function importF12Credentials( staffid: staffId, }, }) - .json<{ value?: { corporationId?: string; loginStaffId?: string; expTime?: number } }>(); + .json<{ + value?: { + id?: string; + userId?: string; + loginStaffId?: string; + corporationId?: string; + platform?: string; + isAssistPlatform?: boolean; + isShortTermToken?: boolean; + assistId?: string; + operationUserId?: string; + operationUserName?: string; + privilege?: string; + deviceType?: string; + loginAccountType?: string; + loginTime?: number; + expTime?: number; + }; + }>(); - if (!res.value?.corporationId) { + sessionData = res.value; + if (!sessionData || (!sessionData.corporationId && !sessionData.id && !sessionData.userId)) { throw new Error("服务端未返回有效 Session"); } } catch (err) { throw new AuthenticationError(`凭证校验失败,请检查 token 是否已过期: ${err instanceof Error ? err.message : String(err)}`); } + // 2. 尝试通过 $UNITY JWT 获取真实企业名称与员工详细信息 (如果未手动指定) + let corpName = params.name; + let staffName = sessionData?.privilege; + let cellphone: string | undefined; + let isAdmin: boolean | undefined; + let sourceChannel: string | undefined; + let jwtExpMs: number | undefined; + + try { + const jwtRes = await ky + .get(`${baseUrl}/api/engine/realm/$UNITY/actions/jwt`, { + searchParams: { corpId }, + headers: { + accesstoken: accessToken, + corpid: corpId, + staffid: staffId, + }, + }) + .json<{ id?: string; value?: string }>(); + const token = jwtRes.id || jwtRes.value; + if (token) { + const parts = token.split("."); + if (parts.length >= 2) { + const payload = JSON.parse(Buffer.from(parts[1], "base64").toString("utf-8")); + if (!corpName && payload.corporationName) { + corpName = payload.corporationName; + } + if (payload.staffName) { + staffName = payload.staffName; + } + if (payload.cellphone) { + cellphone = payload.cellphone; + } + if (payload.isAdmin !== undefined) { + isAdmin = payload.isAdmin === "true" || payload.isAdmin === true; + } + if (payload.exp) { + jwtExpMs = Number(payload.exp) * 1000; + } + } + } + } catch { + // 忽略尝试获取企业名失败 + } + + // 3. 智能判断语义化凭证来源 + let source: import("../config/types.js").CredentialSource = "curl"; + if (sessionData?.isAssistPlatform || sessionData?.platform === "ASSIST") { + source = "assist"; + } + + // 4. 计算 Token 过期时间戳 (ms) + let expiresAt: number | undefined; + if (sessionData?.expTime && sessionData.expTime > 0) { + expiresAt = sessionData.expTime; + } else if (jwtExpMs && jwtExpMs > 0) { + expiresAt = jwtExpMs; + } else if (sessionData?.isAssistPlatform && sessionData?.loginTime) { + // 协助平台短期调试 Token 通常 2 小时有效 + expiresAt = sessionData.loginTime + 2 * 3600 * 1000; + } + const corpConfig: CorpConfig = { id: corpId, name: corpName || `企业-${corpId}`, baseUrl, - source: "f12", + source, + staffName, credentials: { accessToken, corpId, @@ -311,6 +432,23 @@ export async function importF12Credentials( }, auth: { refreshTtl: 300, + expiresAt, + }, + session: { + platform: sessionData?.platform, + isAssistPlatform: sessionData?.isAssistPlatform, + isShortTermToken: sessionData?.isShortTermToken, + assistId: sessionData?.assistId, + operationUserId: sessionData?.operationUserId, + operationUserName: sessionData?.operationUserName, + staffName, + cellphone, + isAdmin, + deviceType: sessionData?.deviceType, + loginAccountType: sessionData?.loginAccountType, + loginTime: sessionData?.loginTime, + expTime: expiresAt || sessionData?.expTime, + sourceChannel, }, }; @@ -318,6 +456,9 @@ export async function importF12Credentials( return corpConfig; } +// 保持历史命名兼容 +export const importF12Credentials = importCredentials; + // ── 企业管理与主站 OAuth2 令牌换取 ───────────────────────────────────────────── /** diff --git a/src/core/config/manager.ts b/src/core/config/manager.ts index 0775166..6a1d7dd 100644 --- a/src/core/config/manager.ts +++ b/src/core/config/manager.ts @@ -9,6 +9,7 @@ export interface CorpSummary { staffId: string; baseUrl?: string; current: boolean; + expiresAt?: number; } export function resolveCorpConfig( @@ -145,6 +146,7 @@ export class CorpContext { staffId: corp.credentials.staffId, baseUrl: corp.baseUrl, current: corp.id === this.current?.id, + expiresAt: corp.auth?.expiresAt || corp.session?.expTime, })); } } diff --git a/src/core/config/types.ts b/src/core/config/types.ts index 7d19fc8..627e2c9 100644 --- a/src/core/config/types.ts +++ b/src/core/config/types.ts @@ -1,6 +1,13 @@ import { z } from "zod"; -export const CredentialSourceSchema = z.enum(["account", "manual", "browser", "f12"]); +export const CredentialSourceSchema = z.enum([ + "account", // 官方统一认证中心 (IDP) 账密/短信登录 + "assist", // 官方协助/代客平台 (Assist Platform) 调试授权会话 + "browser", // 浏览器会话 / Cookie 同步 + "manual", // 手动配置 + "curl", // cURL 抓包 / HTTP Headers 导入 + "f12", // 兼容旧版抓包标识 +]); export type CredentialSource = z.infer; export const CorpCredentialsSchema = z.object({ @@ -15,17 +22,37 @@ export const CorpAuthConfigSchema = z.object({ expiresAt: z.number().optional().describe("AccessToken 到期时间戳 (ms)"), }); +export const CorpSessionInfoSchema = z.object({ + platform: z.string().optional().describe("官方会话平台类型 (如 ASSIST, WEB, MOBILE, OPENAPI)"), + isAssistPlatform: z.boolean().optional().describe("是否为官方协助/代客平台登录"), + isShortTermToken: z.boolean().optional().describe("是否为短期临时 Token"), + assistId: z.string().optional().describe("协助会话/工单 ID"), + operationUserId: z.string().optional().describe("协助操作人 ID (如内部运维/实施账号)"), + operationUserName: z.string().optional().describe("协助操作人姓名"), + staffName: z.string().optional().describe("当前员工真实姓名"), + cellphone: z.string().optional().describe("绑定手机号"), + isAdmin: z.boolean().optional().describe("是否管理员"), + deviceType: z.string().optional().describe("设备类型"), + loginAccountType: z.string().optional().describe("登录账号类型"), + loginTime: z.number().optional().describe("登录时间戳 (ms)"), + expTime: z.number().optional().describe("过期时间戳 (ms)"), + sourceChannel: z.string().optional().describe("来源渠道 (如 APP, WEB)"), +}); +export type CorpSessionInfo = z.infer; + export const CorpConfigSchema = z.object({ id: z.string().describe("配置/身份唯一标识 (默认等于 corpId,同企业多身份时形如 corpId@accountId 或 corpId:staffId)"), name: z.string().describe("企业名称"), corpId: z.string().optional().describe("底层企业物理 ID (未填时默认等于 id)"), userId: z.string().optional().describe("所属用户 ID"), staffId: z.string().optional().describe("员工工号 (默认取 credentials.staffId)"), + staffName: z.string().optional().describe("员工真实姓名"), baseUrl: z.string().url().optional().default("https://app.ekuaibao.com"), - source: CredentialSourceSchema.optional().default("manual").describe("凭证来源: account/manual/browser/f12"), + source: CredentialSourceSchema.optional().default("manual").describe("凭证来源: account/assist/browser/manual/curl/f12"), accountId: z.string().optional().describe("所属主账号标识(如手机号)"), credentials: CorpCredentialsSchema, auth: CorpAuthConfigSchema.optional(), + session: CorpSessionInfoSchema.optional().describe("官方服务端 Session 与操作人元数据"), }); export type CorpCredentials = z.infer; diff --git a/src/domains/bill/tools.ts b/src/domains/bill/tools.ts index 6be365b..603e248 100644 --- a/src/domains/bill/tools.ts +++ b/src/domains/bill/tools.ts @@ -11,6 +11,53 @@ import { import { CorpContext } from "../../core/config/manager.js"; import { createEkbClient } from "../../core/auth/ekb.js"; +// ── 通用内置字段中文 Label 字典 ─────────────────────────────────────────────── + +const COMMON_FIELD_LABELS: Record = { + code: "单据编号", + name: "单据名称", + stage: "业务阶段", + state: "审批状态", + title: "单据标题", + amount: "单据金额", + expenseMoney: "报销金额", + payMoney: "支付金额", + apportionMoney: "分摊金额", + submitDate: "提交时间", + submitterId: "提交人ID", + ownerId: "归属人ID", + description: "事由说明", + detailType: "明细类型", + entityType: "实体类型", + settleStatus: "结算状态", + settleTime: "结算时间", + billingStatus: "开票状态", + voucherStatus: "凭证状态", + voucherCreateTime: "凭证生成时间", + writtenOffAmount: "已核销金额", + unwrittenOffAmount: "未核销金额", + linkType: "关联类型", + linkId: "关联审批流ID", + detailId: "明细ID", + detailNo: "明细序号", + feeTypeId: "费用类型ID", + attachments: "附件列表", + invoiceForm: "发票表单", + submitCount: "提交次数", + rejectionNum: "驳回次数", + reviewStatus: "审核状态", + preApprovedNodeName: "上一审批节点", + preNodeApprovedTime: "节点审批通过时间", + accountPropertyMoney: "核算属性金额", + accountPropertyDate: "核算属性日期", + flowSpecificationId: "流程规范ID", + feeDetailSpecificationId: "费用明细规范ID", + printState: "打印状态", + printCount: "打印次数", + onlyOwnerPrint: "仅提交人可打印", + ownerAndApproverPrintNodeFlag: "节点打印控制标识", +}; + // ── 字段元数据内存缓存 ───────────────────────────────────────────────────────── const schemaCache = new Map; entities: EntityMeta[] }>(); @@ -88,10 +135,8 @@ export function formatSingleBill( // 字典 Label 还原 const meta = dictionary.get(k); - let readableKey = meta ? meta.label : k.replace(/^E_[^_]+_/, ""); - if (readableKey.startsWith("E_")) { - readableKey = readableKey.replace(/^E_/, ""); - } + const bareKey = k.replace(/^E_[^_]+_/, "").replace(/^E_/, ""); + let readableKey = meta ? meta.label : (COMMON_FIELD_LABELS[k] || COMMON_FIELD_LABELS[bareKey] || bareKey); // 格式化字段值 let formattedVal = v; diff --git a/src/version.ts b/src/version.ts index 387b59e..767a57d 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.3.0"; +export const VERSION = "0.3.1";