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