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 || ''