hookehuyr

feat(车辆列表): 从API动态获取品牌、年份和学校数据

移除硬编码的车辆品牌、年份和学校选项,改为从API动态获取
首页和最新上架页面的车辆数据改为从API获取
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 18:30:25 4 + * @LastEditTime: 2025-07-10 20:17:31
5 * @FilePath: /jgdl/src/pages/index/index.vue 5 * @FilePath: /jgdl/src/pages/index/index.vue
6 * @Description: 捡个电驴首页 6 * @Description: 捡个电驴首页
7 --> 7 -->
...@@ -184,89 +184,10 @@ const onSearchHandle = () => { ...@@ -184,89 +184,10 @@ const onSearchHandle = () => {
184 const bannerImages = ref([]) 184 const bannerImages = ref([])
185 185
186 // 精品推荐数据 186 // 精品推荐数据
187 -const featuredScooters = ref([ 187 +const featuredScooters = ref([])
188 - {
189 - id: '1',
190 - name: '小龟电动车',
191 - year: '2023',
192 - school: '上海理工大学',
193 - price: 3880,
194 - imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
195 - isVerified: true
196 - },
197 - {
198 - id: '2',
199 - name: '立马电动车',
200 - year: '2022',
201 - school: '上海复旦大学',
202 - price: 2999,
203 - imageUrl: 'https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
204 - isVerified: true
205 - },
206 - {
207 - id: '3',
208 - name: '雅迪电动车',
209 - year: '2023',
210 - school: '上海理工大学',
211 - price: 4299,
212 - imageUrl: 'https://images.unsplash.com/photo-1591637333184-19aa84b3e01f?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
213 - },
214 - {
215 - id: '4',
216 - name: '爱玛电动车',
217 - year: '2022',
218 - school: '上海复旦大学',
219 - price: 3599,
220 - imageUrl: 'https://images.unsplash.com/photo-1558980664-3a031cf67ea8?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
221 - isVerified: true
222 - }
223 -])
224 188
225 // 最新上架数据 189 // 最新上架数据
226 -const latestScooters = ref([ 190 +const latestScooters = ref([])
227 - {
228 - id: '5',
229 - name: '雅迪 豪华版',
230 - year: '2023',
231 - school: '上海理工大学',
232 - price: 3200,
233 - imageUrl: 'https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
234 - isVerified: true,
235 - batteryHealth: 98,
236 - mileage: 1200
237 - },
238 - {
239 - id: '6',
240 - name: '台铃 战速',
241 - year: '2022',
242 - school: '上海理工大学',
243 - price: 3800,
244 - imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
245 - batteryHealth: 92,
246 - mileage: 2500
247 - },
248 - {
249 - id: '7',
250 - name: '小鸟电车',
251 - year: '2023',
252 - school: '上海复旦大学',
253 - price: 3100,
254 - imageUrl: 'https://images.unsplash.com/photo-1558980664-3a031cf67ea8?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
255 - batteryHealth: 92,
256 - mileage: 2000
257 - },
258 - {
259 - id: '8',
260 - name: '新日电动车',
261 - year: '2024',
262 - school: '上海同济大学',
263 - price: 6700,
264 - imageUrl: 'https://images.unsplash.com/photo-1595941069915-4ebc5197c14a?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
265 - isVerified: true,
266 - batteryHealth: 96,
267 - mileage: 500
268 - }
269 -])
270 191
271 /** 192 /**
272 * 切换收藏状态 193 * 切换收藏状态
...@@ -335,7 +256,6 @@ useDidShow(() => { ...@@ -335,7 +256,6 @@ useDidShow(() => {
335 }) 256 })
336 257
337 useReady(async () => { 258 useReady(async () => {
338 - console.warn('index onReady')
339 // 版本更新检查 259 // 版本更新检查
340 if (!wx.canIUse("getUpdateManager")) { 260 if (!wx.canIUse("getUpdateManager")) {
341 wx.showModal({ 261 wx.showModal({
...@@ -388,7 +308,7 @@ onMounted(async () => { ...@@ -388,7 +308,7 @@ onMounted(async () => {
388 featuredScooters.value = res2.data 308 featuredScooters.value = res2.data
389 } 309 }
390 // 获取最新上架 310 // 获取最新上架
391 - const res3 = await getVehicleListAPI({ page: 0, page_size: 5 }) 311 + const res3 = await getVehicleListAPI({ page: 0, limit: 5 })
392 if (res3.code) { 312 if (res3.code) {
393 latestScooters.value = res3.data.list 313 latestScooters.value = res3.data.list
394 } 314 }
......
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 09:54:21 4 + * @LastEditTime: 2025-07-10 21:19:50
5 * @FilePath: /jgdl/src/pages/newCarList/index.vue 5 * @FilePath: /jgdl/src/pages/newCarList/index.vue
6 * @Description: 最新上架页面 6 * @Description: 最新上架页面
7 --> 7 -->
...@@ -117,6 +117,9 @@ import { ref, computed, onMounted } from 'vue' ...@@ -117,6 +117,9 @@ import { ref, computed, onMounted } from 'vue'
117 import { Search2, Heart1, HeartFill } from '@nutui/icons-vue-taro' 117 import { Search2, Heart1, HeartFill } from '@nutui/icons-vue-taro'
118 import TabBar from '@/components/TabBar.vue' 118 import TabBar from '@/components/TabBar.vue'
119 import './index.less' 119 import './index.less'
120 +// 导入接口
121 +import { getVehicleListAPI } from '@/api/car';
122 +import { getVehicleBrandsAPI, getSchoolsAPI } from '@/api/other';
120 123
121 // 响应式数据 124 // 响应式数据
122 const searchValue = ref('') 125 const searchValue = ref('')
...@@ -126,37 +129,16 @@ const onBlurSearch = () => { ...@@ -126,37 +129,16 @@ const onBlurSearch = () => {
126 const favoriteIds = ref(['2', '4', '6']) 129 const favoriteIds = ref(['2', '4', '6'])
127 130
128 // Filter states - 使用NutUI Menu组件 131 // Filter states - 使用NutUI Menu组件
129 -const selectedBrand = ref('all') 132 +const selectedBrand = ref('')
130 -const selectedYear = ref('all') 133 +const selectedYear = ref('')
131 -const selectedSchool = ref('all') 134 +const selectedSchool = ref('')
132 135
133 // Menu选项数据 136 // Menu选项数据
134 -const brandOptions = ref([ 137 +const brandOptions = ref([])
135 - { text: '全部品牌', value: 'all' },
136 - { text: '雅迪', value: '雅迪' },
137 - { text: '台铃', value: '台铃' },
138 - { text: '小鸟', value: '小鸟' },
139 - { text: '新日', value: '新日' },
140 - { text: '爱玛', value: '爱玛' },
141 - { text: '小牛', value: '小牛' }
142 -])
143 138
144 -const yearOptions = ref([ 139 +const yearOptions = ref([])
145 - { text: '出厂年份', value: 'all' },
146 - { text: '2024年', value: '2024年' },
147 - { text: '2023年', value: '2023年' },
148 - { text: '2022年', value: '2022年' },
149 - { text: '2021年', value: '2021年' },
150 - { text: '2020年', value: '2020年' }
151 -])
152 140
153 -const schoolOptions = ref([ 141 +const schoolOptions = ref([])
154 - { text: '所在学校', value: 'all' },
155 - { text: '上海理工大学', value: '上海理工大学' },
156 - { text: '上海复旦大学', value: '上海复旦大学' },
157 - { text: '上海同济大学', value: '上海同济大学' },
158 - { text: '上海交通大学', value: '上海交通大学' }
159 -])
160 142
161 // 最新上架车辆数据 143 // 最新上架车辆数据
162 const newCars = ref([ 144 const newCars = ref([
...@@ -392,8 +374,41 @@ const showToast = (message, type = 'success') => { ...@@ -392,8 +374,41 @@ const showToast = (message, type = 'success') => {
392 } 374 }
393 375
394 // 初始化 376 // 初始化
395 -onMounted(() => { 377 +onMounted(async () => {
396 // 可以在这里加载初始数据 378 // 可以在这里加载初始数据
379 + // 获取全部品牌数据
380 + const vBrands = await getVehicleBrandsAPI()
381 + if (vBrands.code) {
382 + brandOptions.value = vBrands.data.map(brand => ({
383 + text: brand,
384 + value: brand
385 + }))
386 + brandOptions.value = [{
387 + text: '全部品牌',
388 + value: ''
389 + }, ...brandOptions.value]
390 + }
391 + // 生成从当前日期开始往前10年的年份
392 + yearOptions.value = Array.from({ length: 10 }, (_, i) => ({
393 + text: (new Date().getFullYear() - i).toString() + '年',
394 + value: (new Date().getFullYear() - i).toString()
395 + }))
396 + yearOptions.value = [{
397 + text: '全部年份',
398 + value: ''
399 + }, ...yearOptions.value]
400 + // 获取全部学校数据
401 + const schoolData = await getSchoolsAPI()
402 + if (schoolData.code) {
403 + schoolOptions.value = schoolData.data.map(school => ({
404 + text: school.name,
405 + value: school.id
406 + }))
407 + }
408 + schoolOptions.value = [{
409 + text: '全部学校',
410 + value: ''
411 + }, ...schoolOptions.value]
397 }) 412 })
398 </script> 413 </script>
399 414
......