图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
4.4 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
  1. <template>
  2. <view class="activity-list">
  3. <!-- 下拉刷新区域 -->
  4. <scroll-view
  5. scroll-y
  6. refresher-enabled
  7. :refresher-triggered="refreshing"
  8. @refresherrefresh="onRefresh"
  9. @scrolltolower="onLoadMore"
  10. lower-threshold="100"
  11. >
  12. <!-- 活动列表 -->
  13. <view class="activity-item" v-for="(item, index) in activityList" @click="toActivityDetail(item)" :key="index">
  14. <image class="activity-img" :src="item.imgUrl"></image>
  15. <view class="activity-info">
  16. <view class="activity-info-left">
  17. <text class="title">{{ item.title }}</text>
  18. <view class="time">
  19. <uni-icons class="time-icon" custom-prefix="iconfont" type="icon-shijian" size="15"></uni-icons>
  20. <text>{{ item.time }}</text>
  21. </view>
  22. </view>
  23. <button
  24. class="activity-btn"
  25. :class="item.status === 0 ? 'disabled-btn' : ''"
  26. type="primary"
  27. :disabled="item.status === 0"
  28. >
  29. {{ item.status === 1 ? '立即参加' : '活动结束' }}
  30. </button>
  31. </view>
  32. </view>
  33. <!-- 空状态没有活动时显示 -->
  34. <view class="empty-box" v-if="activityList.length === 0 && !loading">
  35. <uni-icons custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons>
  36. <text style="margin-top: 20px;">暂无活动敬请期待~</text>
  37. </view>
  38. <!-- 加载提示 -->
  39. <view class="load-tip" v-if="loading">
  40. <text>加载中...</text>
  41. </view>
  42. <view class="load-tip" v-if="noMore && activityList.length > 0">
  43. <text>没有更多数据了</text>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. activityList: [], // 活动列表数据
  53. refreshing: false, // 下拉刷新状态
  54. loading: false, // 加载中
  55. noMore: false, // 是否没有更多数据
  56. page: 1, // 当前页码
  57. pageSize: 5, // 每页条数
  58. total: 20, // 模拟总数据量
  59. };
  60. },
  61. onLoad() {
  62. this.getActivityList();
  63. },
  64. methods: {
  65. getActivityList() {
  66. this.loading = true;
  67. setTimeout(() => {
  68. // 模拟接口没数据
  69. // const list = this.mockData(this.page, this.pageSize);
  70. const list = []; // 测试空状态
  71. if (this.refreshing) {
  72. this.activityList = list;
  73. this.refreshing = false;
  74. } else {
  75. this.activityList = [...this.activityList, ...list];
  76. }
  77. if (this.activityList.length >= this.total) {
  78. this.noMore = true;
  79. } else {
  80. this.noMore = false;
  81. }
  82. this.loading = false;
  83. }, 500);
  84. },
  85. mockData(page, pageSize) {
  86. let arr = [];
  87. for (let i = 0; i < pageSize; i++) {
  88. const num = (page - 1) * pageSize + i + 1;
  89. arr.push({
  90. imgUrl: "https://qiniu.aiyxlib.com/1605060269830",
  91. title: `活动标题${num}`,
  92. time: "2025-11-03 00:00 ~2025-11-09 00:00",
  93. status: num % 3 === 0 ? 0 : 1,
  94. });
  95. }
  96. return arr;
  97. },
  98. onRefresh() {
  99. this.page = 1;
  100. this.noMore = false;
  101. this.refreshing = true;
  102. this.getActivityList();
  103. },
  104. onLoadMore() {
  105. if (this.loading || this.noMore) return;
  106. this.page++;
  107. this.getActivityList();
  108. },
  109. toActivityDetail(item){
  110. uni.navigateTo({
  111. url: "/subpkg/pages/activity-detail/activity-detail?title=" + item.title
  112. });
  113. }
  114. },
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .activity-list {
  119. padding: 20px;
  120. height: 100vh;
  121. box-sizing: border-box;
  122. }
  123. scroll-view {
  124. height: 100%;
  125. }
  126. /* 空状态 */
  127. .empty-box {
  128. display: flex;
  129. flex-direction: column;
  130. justify-content: center;
  131. align-items: center;
  132. height: calc(100vh - 150rpx);
  133. color: #999;
  134. font-size: 15px;
  135. }
  136. .load-tip {
  137. text-align: center;
  138. padding: 20px;
  139. color: #999;
  140. font-size: 14px;
  141. }
  142. .activity-item {
  143. background: #fff;
  144. border-radius: 12px;
  145. margin-bottom: 15px;
  146. overflow: hidden;
  147. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  148. .activity-img {
  149. width: 100%;
  150. height: 180rpx;
  151. }
  152. .activity-info {
  153. padding: 15px;
  154. display: flex;
  155. justify-content: space-between;
  156. align-items: center;
  157. .activity-info-left {
  158. flex: 1;
  159. .title {
  160. font-size: 16px;
  161. font-weight: bold;
  162. color: #333;
  163. display: block;
  164. margin-bottom: 8px;
  165. }
  166. .time {
  167. display: flex;
  168. align-items: center;
  169. font-size: 12px;
  170. color: #999;
  171. .time-icon {
  172. margin-right: 4px;
  173. }
  174. }
  175. }
  176. .activity-btn {
  177. background-color: #01a4fe;
  178. font-size: 14px;
  179. border-radius: 30px;
  180. padding: 0 15px;
  181. height: 36px;
  182. line-height: 36px;
  183. }
  184. .disabled-btn {
  185. background-color: #ccc !important;
  186. }
  187. }
  188. }
  189. </style>