DimensionActivities.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="section">
  3. <view class="section-header">
  4. <text class="section-title">🔥 推荐活动</text>
  5. <text class="section-more" @click="$emit('moreActivities')">更多 ›</text>
  6. </view>
  7. <view class="activity-list">
  8. <!-- 无数据时显示占位卡片 -->
  9. <template v-if="!displayActivities || displayActivities.length === 0">
  10. <view class="activity-card" v-for="i in 3" :key="i">
  11. <view class="article-category" :style="{ background: gradientColors[(i-1) % gradientColors.length] }">
  12. <text class="article-category-text">推荐活动</text>
  13. </view>
  14. <text class="article-title">暂无推荐活动</text>
  15. <text class="article-summary">精彩活动即将上线,敬请期待</text>
  16. <view class="activity-bottom-placeholder">
  17. <text class="article-date">--</text>
  18. </view>
  19. </view>
  20. </template>
  21. <!-- 有数据时显示活动卡片(垂直布局) -->
  22. <template v-else><view class="activity-card" v-for="act in displayActivities" :key="act.id" @click.stop="$emit('activityClick', act)">
  23. <view class="activity-color-bar" :style="{ background: gradientColors[act.id % gradientColors.length] }">
  24. <text class="activity-color-text">{{ statusText(act.status) }}</text>
  25. </view>
  26. <text class="article-title">{{ act.title }}</text>
  27. <text class="article-summary" v-if="act.startTime">{{ act.startTime }}</text>
  28. <view class="article-meta">
  29. <text class="activity-fee" v-if="act.priceLabel">{{ act.priceLabel }}</text>
  30. <text class="activity-fee" v-else-if="act.price && act.price > 0">{{ formatPriceWithSymbol(act.price) }}</text>
  31. <text class="activity-fee fee-free" v-else>免费</text>
  32. </view>
  33. </view>
  34. </template>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. var activityGradientColors = [
  40. 'linear-gradient(135deg, #10B981, #34D399)',
  41. 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
  42. 'linear-gradient(135deg, #8B5CF6, #C084FC)',
  43. 'linear-gradient(135deg, #F97316, #FB923C)',
  44. 'linear-gradient(135deg, #6366F1, #818CF8)'
  45. ]
  46. export default {
  47. props: {
  48. dimensionCode: { type: String, required: true },
  49. activities: { type: Array, default: function() { return [] } },
  50. isLoggedIn: { type: Boolean, default: false }
  51. },
  52. data: function() {
  53. return {
  54. gradientColors: activityGradientColors
  55. }
  56. },
  57. computed: {
  58. displayActivities: function() {
  59. return (this.activities || []).slice(0, 3)
  60. }
  61. },
  62. methods: {
  63. statusText: function(status) {
  64. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  65. return map[status] || '即将开始'
  66. },
  67. formatPriceWithSymbol: function(price) {
  68. if (price == null) return '免费'
  69. return '¥' + (Number(price) / 100).toFixed(0)
  70. }
  71. }
  72. }
  73. </script>
  74. <style scoped>
  75. .section {
  76. margin: 20rpx 20rpx;
  77. }
  78. .section-header {
  79. display: flex;
  80. justify-content: space-between;
  81. align-items: center;
  82. margin-bottom: 20rpx;
  83. }
  84. .section-title {
  85. font-size: 30rpx;
  86. font-weight: bold;
  87. color: #333;
  88. }
  89. .section-more {
  90. font-size: 24rpx;
  91. color: #999;
  92. }
  93. .activity-list {
  94. display: flex;
  95. flex-direction: column;
  96. gap: 16rpx;
  97. }
  98. .activity-card {
  99. background: #fff;
  100. border-radius: 16rpx;
  101. padding: 24rpx;
  102. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  103. }
  104. .activity-card:active {
  105. opacity: 0.8;
  106. }
  107. .activity-color-bar {
  108. display: inline-block;
  109. padding: 4rpx 14rpx;
  110. border-radius: 8rpx;
  111. margin-bottom: 10rpx;
  112. }
  113. .activity-color-text {
  114. font-size: 20rpx;
  115. color: #fff;
  116. }
  117. .activity-fee {
  118. font-size: 22rpx;
  119. color: #F97316;
  120. font-weight: 500;
  121. }
  122. .fee-free {
  123. color: #22C55E;
  124. }
  125. .activity-bottom-placeholder {
  126. display: flex;
  127. align-items: center;
  128. gap: 16rpx;
  129. }
  130. /* 共享文章卡片样式 */
  131. .article-category {
  132. display: inline-block;
  133. padding: 4rpx 14rpx;
  134. border-radius: 8rpx;
  135. margin-bottom: 10rpx;
  136. }
  137. .article-category-text {
  138. font-size: 20rpx;
  139. color: #fff;
  140. }
  141. .article-title {
  142. display: block;
  143. font-size: 28rpx;
  144. font-weight: bold;
  145. color: #333;
  146. margin-bottom: 8rpx;
  147. line-height: 1.4;
  148. }
  149. .article-summary {
  150. display: block;
  151. font-size: 24rpx;
  152. color: #888;
  153. line-height: 1.5;
  154. margin-bottom: 12rpx;
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. display: -webkit-box;
  158. -webkit-line-clamp: 2;
  159. -webkit-box-orient: vertical;
  160. }
  161. .article-meta {
  162. display: flex;
  163. align-items: center;
  164. gap: 16rpx;
  165. }
  166. .article-date {
  167. font-size: 22rpx;
  168. color: #bbb;
  169. }
  170. </style>