index.vue
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template>
<view class="booth-map-gallery-page">
<view v-if="loading" class="booth-map-gallery-status">加载中...</view>
<view v-else-if="imageList.length === 0" class="booth-map-gallery-status"> 暂无展位图 </view>
<view v-else class="booth-map-gallery-grid">
<view
v-for="(item, index) in imageList"
:key="item.id"
class="booth-map-gallery-item"
@click="previewImage(index)"
>
<image class="booth-map-gallery-image" :src="item.url" :mode="item.mode || 'widthFix'" />
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import Taro, { useLoad } from '@tarojs/taro'
import './index.less'
import { detailAPI } from '@/api/map_activity'
const imageList = ref([])
const loading = ref(false)
const activityId = ref('')
const isApiSuccess = code => Number(code) === 1
const mapBoothImages = boothImages =>
boothImages
.filter(item => typeof item === 'string' && item.trim() !== '')
.map((url, index) => ({
id: `booth-${index}`,
url,
mode: 'widthFix',
}))
const fetchBoothImages = async () => {
if (!activityId.value) {
imageList.value = []
Taro.showToast({
title: '缺少活动信息',
icon: 'none',
})
return
}
loading.value = true
try {
const result = await detailAPI({ id: activityId.value })
if (!isApiSuccess(result?.code)) {
Taro.showToast({
title: result?.msg || '获取展位图失败',
icon: 'none',
})
imageList.value = []
return
}
imageList.value = mapBoothImages(result?.data?.booth_images || [])
} catch (error) {
console.error('[BoothMapGallery] 获取展位图失败:', error)
imageList.value = []
Taro.showToast({
title: '获取展位图失败',
icon: 'none',
})
} finally {
loading.value = false
}
}
useLoad(options => {
activityId.value = options.activityId || options.activity_id || options.id || ''
fetchBoothImages()
})
const previewImage = index => {
if (imageList.value.length === 0) {
return
}
Taro.previewImage({
current: imageList.value[index].url,
urls: imageList.value.map(item => item.url),
})
}
</script>
<script>
export default {
name: 'BoothMapGallery',
}
</script>