hookehuyr

filter invalid booth gallery images

......@@ -29,14 +29,34 @@ const activityId = ref('')
const isApiSuccess = code => Number(code) === 1
const mapBoothImages = boothImages =>
const normalizeBoothImageUrls = boothImages =>
boothImages
.filter(item => typeof item === 'string' && item.trim() !== '')
.filter(item => typeof item === 'string')
.map(item => item.trim())
.filter(url => url !== '')
const isValidImageUrl = async url => {
try {
await Taro.getImageInfo({ src: url })
return true
} catch (error) {
console.warn('[BoothMapGallery] 过滤非图片展位资源:', url, error)
return false
}
}
const mapBoothImages = async boothImages => {
const normalizedUrls = normalizeBoothImageUrls(boothImages)
const validityList = await Promise.all(normalizedUrls.map(url => isValidImageUrl(url)))
return normalizedUrls
.filter((_, index) => validityList[index])
.map((url, index) => ({
id: `booth-${index}`,
url,
mode: 'widthFix',
}))
}
const fetchBoothImages = async () => {
if (!activityId.value) {
......@@ -62,7 +82,7 @@ const fetchBoothImages = async () => {
return
}
imageList.value = mapBoothImages(result?.data?.booth_images || [])
imageList.value = await mapBoothImages(result?.data?.booth_images || [])
} catch (error) {
console.error('[BoothMapGallery] 获取展位图失败:', error)
imageList.value = []
......