index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // index.js
  2. Page({
  3. data: {
  4. // 轮播图配置
  5. indicatorDots: true,
  6. autoplay: true,
  7. interval: 5000,
  8. duration: 1000,
  9. circular: true,
  10. // 轮播图数据
  11. swiperList: [
  12. {
  13. id: 1,
  14. imageUrl: '../../imgs/guicang/haiwaiwenwu.png',
  15. title: '唐代三彩骆驼骑俑',
  16. date: '2023-06-30',
  17. source: '珍藏馆'
  18. },
  19. {
  20. id: 2,
  21. imageUrl: '../../imgs/guicang/haiwaiwenwu.png',
  22. title: '明代青花瓷器',
  23. date: '2023-06-29',
  24. source: '国家博物馆'
  25. },
  26. {
  27. id: 3,
  28. imageUrl: '../../imgs/guicang/haiwaiwenwu.png',
  29. title: '清代玉器',
  30. date: '2023-06-28',
  31. source: '故宫博物院'
  32. },
  33. {
  34. id: 4,
  35. imageUrl: '../../imgs/guicang/haiwaiwenwu.png',
  36. title: '宋代瓷器',
  37. date: '2023-06-27',
  38. source: '上海博物馆'
  39. }
  40. ],
  41. // 最新上传数据
  42. latestUploads: [],
  43. // 分页数据
  44. currentPage: 1,
  45. pageSize: 9,
  46. hasMoreData: true,
  47. loading: false
  48. },
  49. onLoad: function(options) {
  50. // 初始化最新上传数据
  51. this.loadLatestUploads();
  52. },
  53. // 加载最新上传数据
  54. loadLatestUploads: function() {
  55. if (!this.data.hasMoreData) return;
  56. this.setData({ loading: true });
  57. // 模拟数据加载
  58. setTimeout(() => {
  59. const newItems = this.getMockData(this.data.currentPage, this.data.pageSize);
  60. const hasMore = this.data.currentPage < 3; // 模拟只有3页数据
  61. this.setData({
  62. latestUploads: [...this.data.latestUploads, ...newItems],
  63. currentPage: this.data.currentPage + 1,
  64. hasMoreData: hasMore,
  65. loading: false
  66. });
  67. }, 1000);
  68. },
  69. // 生成模拟数据
  70. getMockData: function(page, pageSize) {
  71. const result = [];
  72. const startIndex = (page - 1) * pageSize;
  73. for (let i = 0; i < pageSize; i++) {
  74. result.push({
  75. id: startIndex + i + 1,
  76. imageUrl: '../../imgs/guicang/haiwaiwenwu.png'
  77. });
  78. }
  79. return result;
  80. },
  81. // 跳转到详情页
  82. goToDetail: function(e) {
  83. const id = e.currentTarget.dataset.id;
  84. wx.navigateTo({
  85. url: '../guicangDetails/index?id=' + id
  86. });
  87. },
  88. // 下拉刷新
  89. onPullDownRefresh: function() {
  90. this.setData({
  91. latestUploads: [],
  92. currentPage: 1,
  93. hasMoreData: true
  94. });
  95. this.loadLatestUploads();
  96. wx.stopPullDownRefresh();
  97. },
  98. // 上拉加载更多
  99. onReachBottom: function() {
  100. if (!this.data.loading && this.data.hasMoreData) {
  101. this.loadLatestUploads();
  102. }
  103. },
  104. onReady: function() {
  105. // 页面初次渲染完成时执行的函数
  106. },
  107. onShow: function() {
  108. // 页面显示时执行的函数
  109. },
  110. onHide: function() {
  111. // 页面隐藏时执行的函数
  112. },
  113. onUnload: function() {
  114. // 页面卸载时执行的函数
  115. }
  116. })