From 77ac384d29c3c8e752a3e5c84c6de5441c17e140 Mon Sep 17 00:00:00 2001 From: mzl Date: Fri, 14 Aug 2026 17:47:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(stocking):=20=E4=BF=AE=E5=A4=8D=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=9B=9E=E5=A1=AB=E5=9B=A0=20attachment=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=AF=BC=E8=87=B4=E7=9A=84=E8=BD=A6=E8=BE=86=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E4=B8=8D=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端 show 返回的 attachment 为 JSON 字符串时,.map 抛 TypeError 中断整个 items 回填。增加 normalizeAttachment 统一兼容 数组/字符串/空值。 Co-Authored-By: Claude --- src/composables/useStockingForm.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/composables/useStockingForm.ts b/src/composables/useStockingForm.ts index c8cb749..886005b 100644 --- a/src/composables/useStockingForm.ts +++ b/src/composables/useStockingForm.ts @@ -974,6 +974,20 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) { } // 数据回显方法 + // 后端 attachment 可能返回数组或 JSON 字符串(未 decode),统一转数组 + const normalizeAttachment = (raw: any): any[] => { + if (Array.isArray(raw)) return raw + if (typeof raw === 'string' && raw.trim()) { + try { + const parsed = JSON.parse(raw) + return Array.isArray(parsed) ? parsed : [] + } catch { + return [] + } + } + return [] + } + const populateFromDetail = (res: any) => { if (!res) return isPopulating.value = true @@ -1021,7 +1035,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) { _echo_vin: Boolean(it.vin), mileage: it.mileage ?? 0, model_snapshot: it.model_snapshot || '', - attachment_files: (it.attachment || []).map((f: any) => ({ + attachment_files: normalizeAttachment(it.attachment).map((f: any) => ({ name: f.original_name || f.name || '附件', url: f.url || f.file_url || '', file_name: f.file_name || f.url || ''