Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
jgdl
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-07-10 21:24:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
67a6ee87bac9a5b1116832078c4ad9be0de00eb7
67a6ee87
1 parent
48090c0b
feat(车辆列表): 从API动态获取品牌、年份和学校数据
移除硬编码的车辆品牌、年份和学校选项,改为从API动态获取 首页和最新上架页面的车辆数据改为从API获取
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
113 deletions
src/pages/index/index.vue
src/pages/newCarList/index.vue
src/pages/index/index.vue
View file @
67a6ee8
<!--
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-10
18:30:25
* @LastEditTime: 2025-07-10
20:17:31
* @FilePath: /jgdl/src/pages/index/index.vue
* @Description: 捡个电驴首页
-->
...
...
@@ -184,89 +184,10 @@ const onSearchHandle = () => {
const bannerImages = ref([])
// 精品推荐数据
const featuredScooters = ref([
{
id: '1',
name: '小龟电动车',
year: '2023',
school: '上海理工大学',
price: 3880,
imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
isVerified: true
},
{
id: '2',
name: '立马电动车',
year: '2022',
school: '上海复旦大学',
price: 2999,
imageUrl: 'https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
isVerified: true
},
{
id: '3',
name: '雅迪电动车',
year: '2023',
school: '上海理工大学',
price: 4299,
imageUrl: 'https://images.unsplash.com/photo-1591637333184-19aa84b3e01f?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
},
{
id: '4',
name: '爱玛电动车',
year: '2022',
school: '上海复旦大学',
price: 3599,
imageUrl: 'https://images.unsplash.com/photo-1558980664-3a031cf67ea8?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
isVerified: true
}
])
const featuredScooters = ref([])
// 最新上架数据
const latestScooters = ref([
{
id: '5',
name: '雅迪 豪华版',
year: '2023',
school: '上海理工大学',
price: 3200,
imageUrl: 'https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
isVerified: true,
batteryHealth: 98,
mileage: 1200
},
{
id: '6',
name: '台铃 战速',
year: '2022',
school: '上海理工大学',
price: 3800,
imageUrl: 'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
batteryHealth: 92,
mileage: 2500
},
{
id: '7',
name: '小鸟电车',
year: '2023',
school: '上海复旦大学',
price: 3100,
imageUrl: 'https://images.unsplash.com/photo-1558980664-3a031cf67ea8?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
batteryHealth: 92,
mileage: 2000
},
{
id: '8',
name: '新日电动车',
year: '2024',
school: '上海同济大学',
price: 6700,
imageUrl: 'https://images.unsplash.com/photo-1595941069915-4ebc5197c14a?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
isVerified: true,
batteryHealth: 96,
mileage: 500
}
])
const latestScooters = ref([])
/**
* 切换收藏状态
...
...
@@ -335,7 +256,6 @@ useDidShow(() => {
})
useReady(async () => {
console.warn('index onReady')
// 版本更新检查
if (!wx.canIUse("getUpdateManager")) {
wx.showModal({
...
...
@@ -388,7 +308,7 @@ onMounted(async () => {
featuredScooters.value = res2.data
}
// 获取最新上架
const res3 = await getVehicleListAPI({ page: 0,
page_size
: 5 })
const res3 = await getVehicleListAPI({ page: 0,
limit
: 5 })
if (res3.code) {
latestScooters.value = res3.data.list
}
...
...
src/pages/newCarList/index.vue
View file @
67a6ee8
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-10
09:54:21
* @LastEditTime: 2025-07-10
21:19:50
* @FilePath: /jgdl/src/pages/newCarList/index.vue
* @Description: 最新上架页面
-->
...
...
@@ -117,6 +117,9 @@ import { ref, computed, onMounted } from 'vue'
import { Search2, Heart1, HeartFill } from '@nutui/icons-vue-taro'
import TabBar from '@/components/TabBar.vue'
import './index.less'
// 导入接口
import { getVehicleListAPI } from '@/api/car';
import { getVehicleBrandsAPI, getSchoolsAPI } from '@/api/other';
// 响应式数据
const searchValue = ref('')
...
...
@@ -126,37 +129,16 @@ const onBlurSearch = () => {
const favoriteIds = ref(['2', '4', '6'])
// Filter states - 使用NutUI Menu组件
const selectedBrand = ref('
all
')
const selectedYear = ref('
all
')
const selectedSchool = ref('
all
')
const selectedBrand = ref('')
const selectedYear = ref('')
const selectedSchool = ref('')
// Menu选项数据
const brandOptions = ref([
{ text: '全部品牌', value: 'all' },
{ text: '雅迪', value: '雅迪' },
{ text: '台铃', value: '台铃' },
{ text: '小鸟', value: '小鸟' },
{ text: '新日', value: '新日' },
{ text: '爱玛', value: '爱玛' },
{ text: '小牛', value: '小牛' }
])
const brandOptions = ref([])
const yearOptions = ref([
{ text: '出厂年份', value: 'all' },
{ text: '2024年', value: '2024年' },
{ text: '2023年', value: '2023年' },
{ text: '2022年', value: '2022年' },
{ text: '2021年', value: '2021年' },
{ text: '2020年', value: '2020年' }
])
const yearOptions = ref([])
const schoolOptions = ref([
{ text: '所在学校', value: 'all' },
{ text: '上海理工大学', value: '上海理工大学' },
{ text: '上海复旦大学', value: '上海复旦大学' },
{ text: '上海同济大学', value: '上海同济大学' },
{ text: '上海交通大学', value: '上海交通大学' }
])
const schoolOptions = ref([])
// 最新上架车辆数据
const newCars = ref([
...
...
@@ -392,8 +374,41 @@ const showToast = (message, type = 'success') => {
}
// 初始化
onMounted(() => {
onMounted(
async
() => {
// 可以在这里加载初始数据
// 获取全部品牌数据
const vBrands = await getVehicleBrandsAPI()
if (vBrands.code) {
brandOptions.value = vBrands.data.map(brand => ({
text: brand,
value: brand
}))
brandOptions.value = [{
text: '全部品牌',
value: ''
}, ...brandOptions.value]
}
// 生成从当前日期开始往前10年的年份
yearOptions.value = Array.from({ length: 10 }, (_, i) => ({
text: (new Date().getFullYear() - i).toString() + '年',
value: (new Date().getFullYear() - i).toString()
}))
yearOptions.value = [{
text: '全部年份',
value: ''
}, ...yearOptions.value]
// 获取全部学校数据
const schoolData = await getSchoolsAPI()
if (schoolData.code) {
schoolOptions.value = schoolData.data.map(school => ({
text: school.name,
value: school.id
}))
}
schoolOptions.value = [{
text: '全部学校',
value: ''
}, ...schoolOptions.value]
})
</script>
...
...
Please
register
or
login
to post a comment