DimensionActivities.vue 4.5 KB

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