From 0ee6df60e6dba2ed3ca71a94d1caf033cfc44ec1 Mon Sep 17 00:00:00 2001 From: hwj Date: Wed, 11 Mar 2026 17:07:28 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E8=AE=BE=E5=A4=87=E5=8F=B0?= =?UTF-8?q?=E8=B4=A6-=E6=96=B0=E5=A2=9E/=E7=BC=96=E8=BE=91-=E8=B5=84?= =?UTF-8?q?=E6=96=99=E5=A4=9A=E9=80=89=E4=BC=A0=E5=8F=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mes/deviceledger/DeviceLedgerForm.vue | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/views/mes/deviceledger/DeviceLedgerForm.vue b/src/views/mes/deviceledger/DeviceLedgerForm.vue index 17e3bf17..b354508a 100644 --- a/src/views/mes/deviceledger/DeviceLedgerForm.vue +++ b/src/views/mes/deviceledger/DeviceLedgerForm.vue @@ -282,6 +282,61 @@ const normalizeYmd = (value: any): string | undefined => { return formatDate(new Date(value), 'YYYY-MM-DD') } +const normalizeFileUrlAsJsonArrayString = (value: any): string | undefined => { + if (value === null || value === undefined || value === '') return undefined + if (typeof value === 'string') { + const trimmed = value.trim() + if (!trimmed) return undefined + try { + const parsed = JSON.parse(trimmed) + if (Array.isArray(parsed)) { + const normalized = parsed + .map((item) => { + if (!item) return undefined + if (typeof item === 'string') { + const url = item.trim() + if (!url) return undefined + const idx = url.lastIndexOf('/') + const name = idx !== -1 ? url.substring(idx + 1) : url + return { fileName: name, fileUrl: url } + } + if (typeof item === 'object' && (item as any).fileUrl) { + const url = String((item as any).fileUrl) + const name = (item as any).fileName ? String((item as any).fileName) : undefined + const idx = url.lastIndexOf('/') + return { fileName: name || (idx !== -1 ? url.substring(idx + 1) : url), fileUrl: url } + } + return undefined + }) + .filter((v) => Boolean(v)) + return normalized.length ? JSON.stringify(normalized) : undefined + } + if (parsed && typeof parsed === 'object') { + const url = (parsed as any).fileUrl ? String((parsed as any).fileUrl) : undefined + if (!url) return undefined + const name = (parsed as any).fileName ? String((parsed as any).fileName) : undefined + const idx = url.lastIndexOf('/') + return JSON.stringify([{ fileName: name || (idx !== -1 ? url.substring(idx + 1) : url), fileUrl: url }]) + } + } catch {} + + const urls = trimmed + .split(',') + .map((s) => s.trim()) + .filter((s) => !!s) + if (!urls.length) return undefined + const infos = urls.map((url) => { + const idx = url.lastIndexOf('/') + const name = idx !== -1 ? url.substring(idx + 1) : url + return { fileName: name, fileUrl: url } + }) + return JSON.stringify(infos) + } + if (Array.isArray(value)) return JSON.stringify(value) + if (typeof value === 'object' && (value as any).fileUrl) return JSON.stringify([value]) + return JSON.stringify([{ fileName: '', fileUrl: String(value) }]) +} + const initFormData = () => ({ id: undefined, deviceCode: undefined, @@ -452,7 +507,8 @@ const submitForm = async () => { factoryEntryDate: normalizeYmd(formData.value.factoryEntryDate), deviceManager: formData.value.deviceManagerIds?.length ? formData.value.deviceManagerIds.join(',') : undefined, componentId: formData.value.componentIds?.length ? formData.value.componentIds.join(',') : undefined, - beijianId: formData.value.beijianIds?.length ? formData.value.beijianIds.join(',') : undefined + beijianId: formData.value.beijianIds?.length ? formData.value.beijianIds.join(',') : undefined, + fileUrl: normalizeFileUrlAsJsonArrayString((formData.value as any).fileUrl) } as unknown as DeviceLedgerVO delete (data as any).deviceManagerIds delete (data as any).componentIds