index页面动态轮播图

This commit is contained in:
WindowBird 2025-08-18 17:58:18 +08:00
parent 1d4aa8cb67
commit f5467db360
2 changed files with 63 additions and 18 deletions

18
api/banner/banner.js Normal file
View File

@ -0,0 +1,18 @@
import request from '@/utils/request'
/**
* 获取轮播图列表
* @param {Object} params - 查询参数
* @param {string} params.appId - 应用ID默认为1
* @returns {Promise} 返回轮播图数据
*/
export function getBannerList(params = {}) {
return request({
url: '/app/banner',
method: 'GET',
params: {
appId: '1',
...params,
},
})
}

View File

@ -40,6 +40,7 @@ import AnnouncementBar from '../../components/announcement-bar/announcement-bar.
import BannerSwiper from '../../components/banner-swiper/banner-swiper.vue'
import EquipmentList from '../../components/equipment-list/equipment-list.vue'
import { getNewAnnouncement } from '../../api/article/article.js'
import { getBannerList } from '../../api/banner/banner.js'
export default {
components: {
@ -66,20 +67,7 @@ export default {
//
currentBannerIndex: 0,
bannerList: [
{
image: commonEnum.TEMP1,
},
{
image: commonEnum.TEMP1,
},
{
image: commonEnum.TEMP2,
},
{
image: commonEnum.TEMP1,
},
],
bannerList: [],
//
equipmentList: [
@ -106,6 +94,7 @@ export default {
//
onLoad() {
this.fetchAnnouncement()
this.fetchBannerList()
},
methods: {
@ -126,6 +115,42 @@ export default {
}
},
//
async fetchBannerList() {
try {
const response = await getBannerList()
if (response.code === 200 && response.data && Array.isArray(response.data)) {
// orderNum
const sortedBanners = response.data
.filter(banner => banner.state === '1') //
.sort((a, b) => parseInt(a.orderNum) - parseInt(b.orderNum))
.map(banner => ({
id: banner.id,
image: banner.imgUrl,
link: banner.link,
name: `轮播图${banner.id}`
}))
this.bannerList = sortedBanners
}
} catch (error) {
console.error('获取轮播图失败:', error)
// 使
this.bannerList = [
{
id: 'default1',
image: commonEnum.TEMP1,
name: '默认轮播图1'
},
{
id: 'default2',
image: commonEnum.TEMP2,
name: '默认轮播图2'
}
]
}
},
//
onLocationClick() {
uni.showToast({
@ -161,10 +186,12 @@ export default {
//
onBannerClick({ item, index }) {
uni.showToast({
title: `查看${item.name}详情`,
icon: 'none',
})
if (item.link) {
//
uni.navigateTo({
url: item.link
})
}
},
//