Showing
1 changed file
with
23 additions
and
3 deletions
| ... | @@ -29,14 +29,34 @@ const activityId = ref('') | ... | @@ -29,14 +29,34 @@ const activityId = ref('') |
| 29 | 29 | ||
| 30 | const isApiSuccess = code => Number(code) === 1 | 30 | const isApiSuccess = code => Number(code) === 1 |
| 31 | 31 | ||
| 32 | -const mapBoothImages = boothImages => | 32 | +const normalizeBoothImageUrls = boothImages => |
| 33 | boothImages | 33 | boothImages |
| 34 | - .filter(item => typeof item === 'string' && item.trim() !== '') | 34 | + .filter(item => typeof item === 'string') |
| 35 | + .map(item => item.trim()) | ||
| 36 | + .filter(url => url !== '') | ||
| 37 | + | ||
| 38 | +const isValidImageUrl = async url => { | ||
| 39 | + try { | ||
| 40 | + await Taro.getImageInfo({ src: url }) | ||
| 41 | + return true | ||
| 42 | + } catch (error) { | ||
| 43 | + console.warn('[BoothMapGallery] 过滤非图片展位资源:', url, error) | ||
| 44 | + return false | ||
| 45 | + } | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +const mapBoothImages = async boothImages => { | ||
| 49 | + const normalizedUrls = normalizeBoothImageUrls(boothImages) | ||
| 50 | + const validityList = await Promise.all(normalizedUrls.map(url => isValidImageUrl(url))) | ||
| 51 | + | ||
| 52 | + return normalizedUrls | ||
| 53 | + .filter((_, index) => validityList[index]) | ||
| 35 | .map((url, index) => ({ | 54 | .map((url, index) => ({ |
| 36 | id: `booth-${index}`, | 55 | id: `booth-${index}`, |
| 37 | url, | 56 | url, |
| 38 | mode: 'widthFix', | 57 | mode: 'widthFix', |
| 39 | })) | 58 | })) |
| 59 | +} | ||
| 40 | 60 | ||
| 41 | const fetchBoothImages = async () => { | 61 | const fetchBoothImages = async () => { |
| 42 | if (!activityId.value) { | 62 | if (!activityId.value) { |
| ... | @@ -62,7 +82,7 @@ const fetchBoothImages = async () => { | ... | @@ -62,7 +82,7 @@ const fetchBoothImages = async () => { |
| 62 | return | 82 | return |
| 63 | } | 83 | } |
| 64 | 84 | ||
| 65 | - imageList.value = mapBoothImages(result?.data?.booth_images || []) | 85 | + imageList.value = await mapBoothImages(result?.data?.booth_images || []) |
| 66 | } catch (error) { | 86 | } catch (error) { |
| 67 | console.error('[BoothMapGallery] 获取展位图失败:', error) | 87 | console.error('[BoothMapGallery] 获取展位图失败:', error) |
| 68 | imageList.value = [] | 88 | imageList.value = [] | ... | ... |
-
Please register or login to post a comment