// index.js const { request, cosBaseUrl } = require('../../utils/newServices'); Page({ data: { // 轮播图配置 indicatorDots: true, autoplay: true, interval: 5000, duration: 1000, circular: true, // 轮播图数据 swiperList: [], // 最新上传数据 latestUploads: [], // 分页数据 currentPage: 1, pageSize: 9, hasMoreData: true, loading: false }, onLoad: function(options) { // 加载轮播图数据 this.loadSwiperData(); // 初始化最新上传数据 this.loadLatestUploads(); }, // 加载轮播图数据 loadSwiperData: function() { const params = { orderBy: 'pv', sortBy: 'DESC', pageNo: 1, pageSize: 1 }; request.getAntiqueList( params, 'GET', (res) => { console.log('轮播图数据加载成功:', res.data.data.pageData); if (res.data && res.data.data && res.data.data.pageData) { const swiperData = res.data.data.pageData.map(item => ({ id: item.id, imageUrl: cosBaseUrl + item.coverImgUrl, title: item.name, date: item.createTime ? item.createTime.split(' ')[0] : '', source: item.source || '归藏' })); this.setData({ swiperList: swiperData }); } }, (err) => { console.error('轮播图数据加载失败:', err); // 加载失败时使用默认数据 this.setData({ swiperList: [] }); } ); }, // 加载最新上传数据 loadLatestUploads: function() { if (!this.data.hasMoreData || this.data.loading) return; this.setData({ loading: true }); const params = { pageNo: this.data.currentPage, pageSize: 20 }; request.getAntiqueList( params, 'GET', (res) => { console.log('最新上传数据加载成功:', res); if (res.data && res.data.data && res.data.data.pageData) { const newItems = res.data.data.pageData.map(item => ({ id: item.id, imageUrl: cosBaseUrl + item.coverImgUrl, title: item.name, date: item.createTime ? item.createTime.split(' ')[0] : '', source: item.source || '归藏' })); const hasMore = res.data.data.pageData.length === 20; // 如果返回数据等于pageSize,说明可能还有更多数据 this.setData({ latestUploads: [...this.data.latestUploads, ...newItems], currentPage: this.data.currentPage + 1, hasMoreData: hasMore, loading: false }); } else { this.setData({ hasMoreData: false, loading: false }); } }, (err) => { console.error('最新上传数据加载失败:', err); this.setData({ loading: false }); } ); }, // 跳转到详情页 goToDetail: function(e) { const id = e.currentTarget.dataset.id; wx.navigateTo({ url: '../guicangDetails/index?id=' + id }); }, // 下拉刷新 onPullDownRefresh: function() { this.setData({ latestUploads: [], currentPage: 1, hasMoreData: true }); this.loadLatestUploads(); wx.stopPullDownRefresh(); }, // 上拉加载更多 onReachBottom: function() { if (!this.data.loading && this.data.hasMoreData) { this.loadLatestUploads(); } }, onReady: function() { // 页面初次渲染完成时执行的函数 }, onShow: function() { // 页面显示时执行的函数 }, onHide: function() { // 页面隐藏时执行的函数 }, onUnload: function() { // 页面卸载时执行的函数 } })