hookehuyr

feat(首页): 添加轮播图点击跳转功能并优化数据结构

修改轮播图数据结构以包含id字段
添加点击事件跳转到详情页功能
1 <!-- 1 <!--
2 * @Date: 2025-06-28 10:33:00 2 * @Date: 2025-06-28 10:33:00
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-17 09:58:32 4 + * @LastEditTime: 2025-07-18 17:11:10
5 * @FilePath: /jgdl/src/pages/index/index.vue 5 * @FilePath: /jgdl/src/pages/index/index.vue
6 * @Description: 捡个电驴首页 6 * @Description: 捡个电驴首页
7 --> 7 -->
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
31 <view class="px-4 pt-4" style="background: linear-gradient( 180deg, #fb923c 0%, rgba(255,203,53,0) 61%);"> 31 <view class="px-4 pt-4" style="background: linear-gradient( 180deg, #fb923c 0%, rgba(255,203,53,0) 61%);">
32 <nut-swiper :init-page="0" :pagination-visible="true" pagination-color="#ffffff" auto-play="3000" 32 <nut-swiper :init-page="0" :pagination-visible="true" pagination-color="#ffffff" auto-play="3000"
33 class="rounded-lg overflow-hidden" height="160"> 33 class="rounded-lg overflow-hidden" height="160">
34 - <nut-swiper-item v-for="(image, index) in bannerImages" :key="index"> 34 + <nut-swiper-item v-for="(image, index) in bannerImages" :key="index" @click="onBannerClick(image)">
35 - <image :src="image" mode="aspectFill" class="w-full h-40 object-cover" /> 35 + <image :src="image.front_photo" mode="aspectFill" class="w-full h-40 object-cover" />
36 </nut-swiper-item> 36 </nut-swiper-item>
37 </nut-swiper> 37 </nut-swiper>
38 </view> 38 </view>
...@@ -180,9 +180,15 @@ onMounted(async () => { ...@@ -180,9 +180,15 @@ onMounted(async () => {
180 // 获取首页轮播 180 // 获取首页轮播
181 const res1 = await getRecommendVehicleAPI({ section: 1 }) 181 const res1 = await getRecommendVehicleAPI({ section: 1 })
182 if (res1.code) { 182 if (res1.code) {
183 - bannerImages.value = res1.data.list.map(item => item.front_photo); 183 + bannerImages.value = res1.data.list.map(item => ({
184 + id: item.id,
185 + front_photo: item.front_photo
186 + }));
184 if (!bannerImages.value.length) { 187 if (!bannerImages.value.length) {
185 - bannerImages.value = [DEFAULT_COVER_IMG] 188 + bannerImages.value = [{
189 + id: 0,
190 + front_photo: DEFAULT_COVER_IMG
191 + }]
186 } 192 }
187 } 193 }
188 }) 194 })
...@@ -210,4 +216,11 @@ useShareAppMessage(() => { ...@@ -210,4 +216,11 @@ useShareAppMessage(() => {
210 // 返回shareObj 216 // 返回shareObj
211 return shareObj; 217 return shareObj;
212 }) 218 })
219 +
220 +// 点击banner图片跳转到详情页
221 +const onBannerClick = ({id}) => {
222 + Taro.navigateTo({
223 + url: `/pages/productDetail/index?id=${id}`
224 + })
225 +}
213 </script> 226 </script>
......