hookehuyr

fix: 为车辆列表添加默认封面图片处理

在多个页面中为车辆数据添加默认封面图片处理,当front_photo为空时使用DEFAULT_COVER_IMG
同时优化了首页的代码格式和分享功能缩进
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-10 22:49:42 4 + * @LastEditTime: 2025-07-11 10:11:35
5 * @FilePath: /jgdl/src/pages/authCar/index.vue 5 * @FilePath: /jgdl/src/pages/authCar/index.vue
6 * @Description: 认证车源 6 * @Description: 认证车源
7 --> 7 -->
...@@ -95,7 +95,7 @@ import { useFavorite } from '@/composables/useFavorite' ...@@ -95,7 +95,7 @@ import { useFavorite } from '@/composables/useFavorite'
95 import './index.less' 95 import './index.less'
96 // 接口导入 96 // 接口导入
97 import { getVehicleListAPI } from '@/api/car'; 97 import { getVehicleListAPI } from '@/api/car';
98 - 98 +import { DEFAULT_COVER_IMG } from '@/utils/config'
99 // Banner图片数据 99 // Banner图片数据
100 const bannerImages = ref([ 100 const bannerImages = ref([
101 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=800&h=400&fit=crop', 101 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=800&h=400&fit=crop',
...@@ -174,6 +174,7 @@ const loadAuthCarData = async (isLoadMore = false) => { ...@@ -174,6 +174,7 @@ const loadAuthCarData = async (isLoadMore = false) => {
174 // 处理图片数据 174 // 处理图片数据
175 const processedData = vehicleList.map(item => ({ 175 const processedData = vehicleList.map(item => ({
176 ...item, 176 ...item,
177 + front_photo: item.front_photo || DEFAULT_COVER_IMG,
177 })) 178 }))
178 179
179 if (isLoadMore) { 180 if (isLoadMore) {
......
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-10 21:30:57 4 + * @LastEditTime: 2025-07-11 10:09:02
5 * @FilePath: /jgdl/src/pages/index/index.vue 5 * @FilePath: /jgdl/src/pages/index/index.vue
6 * @Description: 捡个电驴首页 6 * @Description: 捡个电驴首页
7 --> 7 -->
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
16 </nut-col> 16 </nut-col>
17 <nut-col span="18"> 17 <nut-col span="18">
18 <!-- Search Bar --> 18 <!-- Search Bar -->
19 - <nut-searchbar v-model="searchValue" placeholder="搜索更多商品" :disabled="true" @click-input="onSearchHandle" shape="round" background="transparent" input-background="#ffffff"> 19 + <nut-searchbar v-model="searchValue" placeholder="搜索更多商品" :disabled="true" @click-input="onSearchHandle"
20 + shape="round" background="transparent" input-background="#ffffff">
20 <template #leftin> 21 <template #leftin>
21 <Search2 /> 22 <Search2 />
22 </template> 23 </template>
...@@ -40,19 +41,22 @@ ...@@ -40,19 +41,22 @@
40 <view class="px-4 mt-2"> 41 <view class="px-4 mt-2">
41 <view class="flex justify-around py-4"> 42 <view class="flex justify-around py-4">
42 <view class="flex flex-col items-center" @tap="onNewCarClick"> 43 <view class="flex flex-col items-center" @tap="onNewCarClick">
43 - <view class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center" style="background: linear-gradient( 135deg, rgba(255,161,53,0.15) 0%, rgba(235,83,5,0.25) 100%); box-shadow: 0px 2px 8px 0px rgba(235,83,5,0.15);"> 44 + <view class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center"
45 + style="background: linear-gradient( 135deg, rgba(255,161,53,0.15) 0%, rgba(235,83,5,0.25) 100%); box-shadow: 0px 2px 8px 0px rgba(235,83,5,0.15);">
44 <Clock size="20" color="#f97316" /> 46 <Clock size="20" color="#f97316" />
45 </view> 47 </view>
46 <text class="text-xs mt-1 text-gray-700">最新上架</text> 48 <text class="text-xs mt-1 text-gray-700">最新上架</text>
47 </view> 49 </view>
48 <view class="flex flex-col items-center" @tap="onGoodCarClick"> 50 <view class="flex flex-col items-center" @tap="onGoodCarClick">
49 - <view class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center" style="background: linear-gradient( 135deg, rgba(255,161,53,0.15) 0%, rgba(235,83,5,0.25) 100%); box-shadow: 0px 2px 8px 0px rgba(235,83,5,0.15);"> 51 + <view class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center"
52 + style="background: linear-gradient( 135deg, rgba(255,161,53,0.15) 0%, rgba(235,83,5,0.25) 100%); box-shadow: 0px 2px 8px 0px rgba(235,83,5,0.15);">
50 <Star size="20" color="#f97316" /> 53 <Star size="20" color="#f97316" />
51 </view> 54 </view>
52 <text class="text-xs mt-1 text-gray-700">特价好车</text> 55 <text class="text-xs mt-1 text-gray-700">特价好车</text>
53 </view> 56 </view>
54 <view class="flex flex-col items-center" @tap="onCertifiedClick"> 57 <view class="flex flex-col items-center" @tap="onCertifiedClick">
55 - <view class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center" style="background: linear-gradient( 135deg, rgba(255,161,53,0.15) 0%, rgba(235,83,5,0.25) 100%); box-shadow: 0px 2px 8px 0px rgba(235,83,5,0.15);"> 58 + <view class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center"
59 + style="background: linear-gradient( 135deg, rgba(255,161,53,0.15) 0%, rgba(235,83,5,0.25) 100%); box-shadow: 0px 2px 8px 0px rgba(235,83,5,0.15);">
56 <Shop size="20" color="#f97316" /> 60 <Shop size="20" color="#f97316" />
57 </view> 61 </view>
58 <text class="text-xs mt-1 text-gray-700">认证车源</text> 62 <text class="text-xs mt-1 text-gray-700">认证车源</text>
...@@ -73,14 +77,16 @@ ...@@ -73,14 +77,16 @@
73 <view v-for="scooter in featuredScooters" :key="scooter.id" 77 <view v-for="scooter in featuredScooters" :key="scooter.id"
74 class="bg-white rounded-lg shadow-sm overflow-hidden" @tap="() => onProductClick(scooter)"> 78 class="bg-white rounded-lg shadow-sm overflow-hidden" @tap="() => onProductClick(scooter)">
75 <view class="relative p-2"> 79 <view class="relative p-2">
76 - <image :src="scooter.front_photo" mode="aspectFill" 80 + <image :src="scooter.front_photo" mode="aspectFill" class="w-full h-36 object-cover rounded-lg" />
77 - class="w-full h-36 object-cover rounded-lg" /> 81 + <view
78 - <view class="absolute top-4 right-3 w-7 h-7 rounded-full bg-white bg-opacity-80 flex items-center justify-center" @tap.stop="() => toggleFavorite(scooter)"> 82 + class="absolute top-4 right-3 w-7 h-7 rounded-full bg-white bg-opacity-80 flex items-center justify-center"
83 + @tap.stop="() => toggleFavorite(scooter)">
79 <Heart1 v-if="!scooter.is_favorite" size="22" :color="'#9ca3af'" /> 84 <Heart1 v-if="!scooter.is_favorite" size="22" :color="'#9ca3af'" />
80 <HeartFill v-else size="22" :color="'#ef4444'" /> 85 <HeartFill v-else size="22" :color="'#ef4444'" />
81 </view> 86 </view>
82 <view v-if="scooter.verification_status === 5" 87 <view v-if="scooter.verification_status === 5"
83 - class="absolute bottom-4 right-4 text-white text-xs px-1.5 py-0.5 rounded flex items-center" style="background-color: #EB5305;"> 88 + class="absolute bottom-4 right-4 text-white text-xs px-1.5 py-0.5 rounded flex items-center"
89 + style="background-color: #EB5305;">
84 <Check size="12" color="#ffffff" class="mr-0.5" /> 90 <Check size="12" color="#ffffff" class="mr-0.5" />
85 <text class="text-white">认证</text> 91 <text class="text-white">认证</text>
86 </view> 92 </view>
...@@ -123,7 +129,8 @@ ...@@ -123,7 +129,8 @@
123 <image :src="scooter.front_photo" :alt="scooter.name" mode="aspectFill" 129 <image :src="scooter.front_photo" :alt="scooter.name" mode="aspectFill"
124 class="w-full flex-1 object-cover rounded-lg" /> 130 class="w-full flex-1 object-cover rounded-lg" />
125 <view v-if="scooter.verification_status === 5" 131 <view v-if="scooter.verification_status === 5"
126 - class="absolute bottom-3 right-3 text-white text-xs px-1 rounded flex items-center" style="background-color: #EB5305;"> 132 + class="absolute bottom-3 right-3 text-white text-xs px-1 rounded flex items-center"
133 + style="background-color: #EB5305;">
127 <Check size="12" color="#ffffff" class="mr-0.5" /> 134 <Check size="12" color="#ffffff" class="mr-0.5" />
128 <text class="text-white">认证</text> 135 <text class="text-white">认证</text>
129 </view> 136 </view>
...@@ -170,7 +177,7 @@ import "./index.less"; ...@@ -170,7 +177,7 @@ import "./index.less";
170 // 导入接口 177 // 导入接口
171 import { getRecommendVehicleAPI, getVehicleListAPI } from '@/api/car'; 178 import { getRecommendVehicleAPI, getVehicleListAPI } from '@/api/car';
172 import { useFavorite } from '@/composables/useFavorite' 179 import { useFavorite } from '@/composables/useFavorite'
173 - 180 +import { DEFAULT_COVER_IMG } from '@/utils/config'
174 // 响应式数据 181 // 响应式数据
175 const searchValue = ref('') 182 const searchValue = ref('')
176 // favoriteIds 已移除,现在使用基于对象属性的收藏模式 183 // favoriteIds 已移除,现在使用基于对象属性的收藏模式
...@@ -289,11 +296,30 @@ onMounted(async () => { ...@@ -289,11 +296,30 @@ onMounted(async () => {
289 const res2 = await getRecommendVehicleAPI({ section: 3 }) 296 const res2 = await getRecommendVehicleAPI({ section: 3 })
290 if (res2.code) { 297 if (res2.code) {
291 featuredScooters.value = res2.data 298 featuredScooters.value = res2.data
299 + // 处理图片数据
300 + const processedData = res2.data.map(item => ({
301 + ...item,
302 + front_photo: item.front_photo || DEFAULT_COVER_IMG,
303 + // 确保价格为数字类型
304 + price: Number(item.price) || 0,
305 + market_price: Number(item.market_price) || 0
306 + }))
307 +
308 + featuredScooters.value = processedData
292 } 309 }
293 // 获取最新上架 310 // 获取最新上架
294 const res3 = await getVehicleListAPI({ page: 0, limit: 5 }) 311 const res3 = await getVehicleListAPI({ page: 0, limit: 5 })
295 if (res3.code) { 312 if (res3.code) {
296 latestScooters.value = res3.data.list 313 latestScooters.value = res3.data.list
314 + // 处理图片数据
315 + const processedData = res3.data.list.map(item => ({
316 + ...item,
317 + front_photo: item.front_photo || DEFAULT_COVER_IMG,
318 + // 确保价格为数字类型
319 + price: Number(item.price) || 0,
320 + market_price: Number(item.market_price) || 0,
321 + }))
322 + latestScooters.value = processedData
297 } 323 }
298 }) 324 })
299 325
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-10 22:47:45 4 + * @LastEditTime: 2025-07-11 10:10:56
5 * @FilePath: /jgdl/src/pages/newCarList/index.vue 5 * @FilePath: /jgdl/src/pages/newCarList/index.vue
6 * @Description: 最新上架页面 6 * @Description: 最新上架页面
7 --> 7 -->
...@@ -121,7 +121,7 @@ import './index.less' ...@@ -121,7 +121,7 @@ import './index.less'
121 // 接口导入 121 // 接口导入
122 import { getVehicleBrandsAPI, getSchoolsAPI } from '@/api/other'; 122 import { getVehicleBrandsAPI, getSchoolsAPI } from '@/api/other';
123 import { getVehicleListAPI } from '@/api/car'; 123 import { getVehicleListAPI } from '@/api/car';
124 - 124 +import { DEFAULT_COVER_IMG } from '@/utils/config'
125 // 响应式数据 125 // 响应式数据
126 const searchValue = ref('') 126 const searchValue = ref('')
127 /** 127 /**
...@@ -268,6 +268,7 @@ const loadVehicleData = async (isLoadMore = false) => { ...@@ -268,6 +268,7 @@ const loadVehicleData = async (isLoadMore = false) => {
268 // 处理图片数据 268 // 处理图片数据
269 const processedData = vehicleList.map(item => ({ 269 const processedData = vehicleList.map(item => ({
270 ...item, 270 ...item,
271 + front_photo: item.front_photo || DEFAULT_COVER_IMG,
271 // 添加新车标签(7天内发布的车辆) 272 // 添加新车标签(7天内发布的车辆)
272 isNew: new Date() - new Date(item.created_time) < 7 * 24 * 60 * 60 * 1000 273 isNew: new Date() - new Date(item.created_time) < 7 * 24 * 60 * 60 * 1000
273 })) 274 }))
......