my-activities.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="my-activities-page">
  3. <view class="status-bar-placeholder" :style="{height: statusBarHeight + 'px', backgroundColor: '#FCE4EC'}"></view>
  4. <!-- 自定义导航栏 -->
  5. <view class="custom-navbar">
  6. <view class="navbar-left" @click="goBack">
  7. <text class="back-icon">←</text>
  8. </view>
  9. <view class="navbar-title">我的活动</view>
  10. <view class="navbar-right"></view>
  11. </view>
  12. <!-- 活动列表 -->
  13. <view class="activity-grid">
  14. <view class="activity-card" v-for="(item, index) in activityList" :key="index"
  15. @click="goToDetail(item.id)">
  16. <image :src="item.cover_image" class="activity-image" mode="aspectFill"></image>
  17. <view class="activity-info">
  18. <view class="activity-name">{{ item.name }}</view>
  19. <view class="activity-meta">
  20. <text class="activity-location">📍 {{ item.location }}</text>
  21. </view>
  22. <view class="activity-footer">
  23. <view class="activity-points">
  24. <text class="points-symbol">💎</text>
  25. <text class="points-value">{{ item.points }}</text>
  26. </view>
  27. <text class="activity-participants">{{ item.participants || 0 }}人参加</text>
  28. </view>
  29. <view class="activity-btn" @click.stop="goToDetail(item.id)">查看详情</view>
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 空状态 -->
  34. <view class="empty-state" v-if="activityList.length === 0 && !loading">
  35. <image src="https://img.icons8.com/color/96/000000/calendar--v1.png" class="empty-icon"></image>
  36. <text class="empty-text">暂无报名活动</text>
  37. <text class="empty-subtext">快去报名参加更多精彩活动吧</text>
  38. </view>
  39. <!-- 加载更多 -->
  40. <view class="load-more" v-if="hasMore">
  41. <text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
  42. </view>
  43. <view class="no-more" v-else-if="activityList.length > 0">
  44. <text class="no-more-text">没有更多了</text>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import api from '../../utils/api.js'
  50. export default {
  51. data() {
  52. return {
  53. statusBarHeight: 0,
  54. activityList: [],
  55. pageNum: 1,
  56. pageSize: 10,
  57. hasMore: true,
  58. loading: false,
  59. // 模拟数据,当API返回为空时使用
  60. mockActivities: [
  61. {
  62. id: 1,
  63. name: '姻缘一线牵·大型相亲会',
  64. location: '雄安新区',
  65. points: 299,
  66. participants: 18,
  67. cover_image: 'https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60'
  68. },
  69. {
  70. id: 2,
  71. name: '一期一会·红娘心得分享',
  72. location: '北京',
  73. points: 389,
  74. participants: 54,
  75. cover_image: 'https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60'
  76. }
  77. ]
  78. }
  79. },
  80. onLoad() {
  81. // 获取状态栏高度
  82. const systemInfo = uni.getSystemInfoSync()
  83. this.statusBarHeight = systemInfo.statusBarHeight
  84. this.loadMyActivityList()
  85. },
  86. onReachBottom() {
  87. if (this.hasMore && !this.loading) {
  88. this.pageNum++
  89. this.loadMyActivityList()
  90. }
  91. },
  92. methods: {
  93. // 加载我的活动列表
  94. async loadMyActivityList() {
  95. if (this.loading) return
  96. this.loading = true
  97. try {
  98. const userInfo = uni.getStorageSync('userInfo')
  99. const testUserId = 19
  100. const userId = userInfo && userInfo.userId ? userInfo.userId : testUserId
  101. const data = await api.activity.getMyActivities({
  102. pageNum: this.pageNum,
  103. pageSize: this.pageSize,
  104. userId: userId
  105. })
  106. if (data && data.length > 0) {
  107. this.activityList = [...this.activityList, ...data]
  108. this.hasMore = data.length >= this.pageSize
  109. } else {
  110. // 如果API返回为空,使用模拟数据
  111. this.hasMore = false
  112. if (this.pageNum === 1) {
  113. this.activityList = this.mockActivities
  114. }
  115. }
  116. } catch (error) {
  117. // 当API调用失败时,使用模拟数据
  118. if (this.pageNum === 1) {
  119. this.activityList = this.mockActivities
  120. }
  121. this.hasMore = false
  122. } finally {
  123. this.loading = false
  124. }
  125. },
  126. // 跳转到详情
  127. goToDetail(id) {
  128. uni.navigateTo({
  129. url: `/pages/activities/detail?id=${id}`
  130. })
  131. },
  132. // 返回
  133. goBack() {
  134. uni.navigateBack()
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .my-activities-page {
  141. min-height: 100vh;
  142. background-color: #FFF9F9;
  143. padding-top: 120rpx;
  144. }
  145. /* 状态栏占位符 */
  146. .status-bar-placeholder {
  147. position: fixed;
  148. top: 0;
  149. left: 0;
  150. right: 0;
  151. z-index: 998;
  152. }
  153. /* 自定义导航栏 */
  154. .custom-navbar {
  155. position: fixed;
  156. top: 0;
  157. left: 0;
  158. right: 0;
  159. height: 120rpx;
  160. display: flex;
  161. align-items: flex-end;
  162. justify-content: space-between;
  163. padding: 0 30rpx 25rpx;
  164. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  165. z-index: 999;
  166. .navbar-left,
  167. .navbar-right {
  168. width: 80rpx;
  169. }
  170. .back-icon {
  171. font-size: 40rpx;
  172. color: #333333;
  173. font-weight: bold;
  174. }
  175. .navbar-title {
  176. flex: 1;
  177. text-align: center;
  178. font-size: 32rpx;
  179. font-weight: bold;
  180. color: #333333;
  181. }
  182. }
  183. /* 活动列表 - 两列布局 */
  184. .activity-grid {
  185. display: grid;
  186. grid-template-columns: 1fr 1fr;
  187. gap: 20rpx;
  188. padding: 20rpx;
  189. .activity-card {
  190. position: relative;
  191. background-color: #FFFFFF;
  192. border-radius: 20rpx;
  193. overflow: hidden;
  194. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  195. .activity-image {
  196. width: 100%;
  197. height: 240rpx;
  198. background-color: #F5F5F5;
  199. }
  200. .activity-info {
  201. padding: 20rpx;
  202. .activity-name {
  203. font-size: 28rpx;
  204. font-weight: bold;
  205. color: #333333;
  206. margin-bottom: 10rpx;
  207. display: -webkit-box;
  208. -webkit-box-orient: vertical;
  209. -webkit-line-clamp: 2;
  210. overflow: hidden;
  211. }
  212. .activity-meta {
  213. margin-bottom: 15rpx;
  214. .activity-location {
  215. font-size: 24rpx;
  216. color: #666666;
  217. }
  218. }
  219. .activity-footer {
  220. display: flex;
  221. justify-content: space-between;
  222. align-items: center;
  223. margin-bottom: 15rpx;
  224. .activity-points {
  225. display: flex;
  226. align-items: center;
  227. .points-symbol {
  228. font-size: 24rpx;
  229. margin-right: 5rpx;
  230. }
  231. .points-value {
  232. font-size: 26rpx;
  233. color: #FF6B8A;
  234. font-weight: bold;
  235. }
  236. }
  237. .activity-participants {
  238. font-size: 22rpx;
  239. color: #999999;
  240. }
  241. }
  242. .activity-btn {
  243. width: 100%;
  244. height: 60rpx;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. background-color: #9C27B0;
  249. color: #FFFFFF;
  250. border-radius: 30rpx;
  251. font-size: 26rpx;
  252. }
  253. }
  254. }
  255. }
  256. /* 空状态 */
  257. .empty-state {
  258. display: flex;
  259. flex-direction: column;
  260. align-items: center;
  261. justify-content: center;
  262. padding: 100rpx 0;
  263. .empty-icon {
  264. width: 120rpx;
  265. height: 120rpx;
  266. opacity: 0.5;
  267. margin-bottom: 20rpx;
  268. }
  269. .empty-text {
  270. font-size: 32rpx;
  271. color: #666666;
  272. margin-bottom: 10rpx;
  273. }
  274. .empty-subtext {
  275. font-size: 26rpx;
  276. color: #999999;
  277. }
  278. }
  279. /* 加载更多 */
  280. .load-more,
  281. .no-more {
  282. padding: 30rpx 0;
  283. text-align: center;
  284. .load-text,
  285. .no-more-text {
  286. font-size: 24rpx;
  287. color: #999999;
  288. }
  289. }
  290. </style>