my-activities.vue 7.5 KB

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