Commit 1441cd31 by qinjianhui

fix: handle imageAry as plain

parent 3e0881e1
......@@ -62,17 +62,17 @@
<template #images>
<div class="flex-between">
<div class="images-position">
<div v-if="item.imageAry" class="images-container">
<div v-if="parseImageAry(item.imageAry).length" class="images-container">
<div
v-for="(img, index) in JSON.parse(item.imageAry as string)"
v-for="(img, index) in parseImageAry(item.imageAry)"
:key="index"
:title="img.title"
class="item-image"
>
<el-image
:src="img?.url"
:src="img.url"
height="50"
:preview-src-list="JSON.parse(item.imageAry as string).map((i: any) => i.url)"
:preview-src-list="parseImageAry(item.imageAry).map((i) => i.url)"
:initial-index="index"
/>
</div>
......@@ -480,6 +480,40 @@ const getPlatformImg = (code: string) => {
return ''
}
const parseImageAry = (
imageAry?: unknown,
): { url: string; title?: string }[] => {
if (typeof imageAry !== 'string' || !imageAry.trim()) return []
const trimmed = imageAry.trim()
if (trimmed.startsWith('http')) {
return trimmed
.split(',')
.map((url) => ({ url: url.trim() }))
.filter((item) => item.url)
}
try {
const parsed = JSON.parse(trimmed) as unknown
if (!Array.isArray(parsed)) return [{ url: trimmed }]
const result: { url: string; title?: string }[] = []
for (const item of parsed) {
if (typeof item === 'string' && item) {
result.push({ url: item })
} else if (item && typeof item === 'object' && 'url' in item) {
const url = (item as { url?: string }).url
if (url) {
result.push({
url,
title: (item as { title?: string }).title,
})
}
}
}
return result
} catch {
return [{ url: trimmed }]
}
}
const getOrderDelayText = (createTime?: string | null) => {
if (!createTime) return '--'
const createAt = dayjs(createTime)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment