From fb5a8ce4a2d0fd1ca95490d5ffcc1874ea2f6f12 Mon Sep 17 00:00:00 2001 From: "weicw1996@qq.com" Date: Wed, 30 Sep 2026 10:13:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(attachment):=20=E5=AE=98=E7=BD=91=E7=94=B5?= =?UTF-8?q?=E5=AD=90=E5=8F=91=E7=A5=A8=E4=B8=8B=E8=BD=BD=E6=8A=A5=E3=80=8C?= =?UTF-8?q?=E5=8F=91=E7=A5=A8ID=E4=B8=8D=E8=83=BD=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 取票中转 route 的转发 query 是手写白名单,只带 kind/orderNo/projectNo/index,漏了 invoiceId。官网点发票下载时后端因此只收到 kind=invoice、没有发票 id,命中 HjcAttachmentController 的入参校验,原样回 code=1「发票ID不能为空」。补上解构与转发,并在注释里写清三种资源标识都要转发(tender 按订单号、bulletin 按项目编号、invoice 按发票 id)。 --- server/api/tender/attachment-ticket.get.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/api/tender/attachment-ticket.get.ts b/server/api/tender/attachment-ticket.get.ts index 2089aeb..e3717a2 100644 --- a/server/api/tender/attachment-ticket.get.ts +++ b/server/api/tender/attachment-ticket.get.ts @@ -7,10 +7,15 @@ import { getTenantFromContext } from '../../utils/tenant' * 取附件下载票据(一次性、短时)。 * GET /api/tender/attachment-ticket?kind=tender&orderNo=xxx&index=0 * GET /api/tender/attachment-ticket?kind=bulletin&projectNo=xxx&index=0 + * GET /api/tender/attachment-ticket?kind=invoice&invoiceId=xxx&index=0 + * + * **三种资源标识都要转发**:`kind=invoice`(电子发票)的标识是 `invoiceId`, + * 漏了它后端只会看到「kind=invoice 但没有发票 id」,直接回 + * `{"code":1,"message":"发票ID不能为空"}`——本路由曾漏过这一个字段。 * * 为什么要它:一站式的静态文件服务加了鉴权,附件不再直连,改由后端反代 * (工作区根目录 `docs/adr/0007-attachment-download-via-platform-proxy.md`)。 - * 下发给前端的附件地址是**本平台的资源地址**(只有 kind/订单号或项目编号/序号, + * 下发给前端的附件地址是**本平台的资源地址**(只有 kind/订单号或项目编号或发票 id/序号, * 没有路径、也没有票据);**点击下载时**才来这里换一张票据,再用票据去 * `{modulesApiBase}/api/hjc/attachment?ticket=…` 取文件。 * @@ -24,7 +29,7 @@ import { getTenantFromContext } from '../../utils/tenant' export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) - const { kind, orderNo, projectNo, index } = getQuery(event) + const { kind, orderNo, projectNo, invoiceId, index } = getQuery(event) const cookieToken = getCookie(event, 'hjc_token') const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null) @@ -41,7 +46,9 @@ export default defineEventHandler(async (event) => { kind, index, ...(orderNo ? { orderNo } : {}), - ...(projectNo ? { projectNo } : {}) + ...(projectNo ? { projectNo } : {}), + // 电子发票按发票 id 取件;漏掉这一行,发票下载必报「发票ID不能为空」 + ...(invoiceId ? { invoiceId } : {}) } }) } catch (error: any) {