123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // 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() {
- // 页面卸载时执行的函数
- }
- })
|