From 49e3176e6bf1d3569b1dcd71e0648ff225442b48 Mon Sep 17 00:00:00 2001 From: clz Date: Mon, 19 Jan 2026 01:27:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86=E7=BC=96=E8=BE=91=E8=B4=A6?= =?UTF-8?q?=E5=8D=95=E6=8E=A5=E5=8F=A3=E4=BB=8E=20PATCH=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20POST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改后端路由:POST /api/bills/:id - 修改前端 API 调用方法为 POST - 移除临时添加的 CORS 中间件 - 解决生产环境 405 Method Not Allowed 问题 --- server/handler/update_bill.go | 2 +- server/router/router.go | 2 +- web/src/lib/api.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/handler/update_bill.go b/server/handler/update_bill.go index e78499b..689e647 100644 --- a/server/handler/update_bill.go +++ b/server/handler/update_bill.go @@ -47,7 +47,7 @@ func parseBillTime(s string) (time.Time, error) { return time.Time{}, fmt.Errorf("unsupported time format") } -// UpdateBill PATCH /api/bills/:id 更新清洗后的账单记录 +// UpdateBill POST /api/bills/:id 更新清洗后的账单记录 func UpdateBill(c *gin.Context) { id := strings.TrimSpace(c.Param("id")) if id == "" { diff --git a/server/router/router.go b/server/router/router.go index 8b206e6..7cf4a1f 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -60,7 +60,7 @@ func setupAPIRoutes(r *gin.Engine) { authed.GET("/bills", handler.ListBills) // 编辑账单 - authed.PATCH("/bills/:id", handler.UpdateBill) + authed.POST("/bills/:id", handler.UpdateBill) // 手动创建账单 authed.POST("/bills/manual", handler.CreateManualBills) diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts index fea183f..dd7112a 100644 --- a/web/src/lib/api.ts +++ b/web/src/lib/api.ts @@ -258,7 +258,7 @@ export interface UpdateBillResponse { export async function updateBill(id: string, patch: UpdateBillRequest): Promise { const response = await apiFetch(`${API_BASE}/api/bills/${encodeURIComponent(id)}`, { - method: 'PATCH', + method: 'POST', headers: { 'Content-Type': 'application/json', },