RecommendedSection.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="recommended-section" v-if="items && items.length > 0">
  3. <view class="section-header">
  4. <text class="section-icon">✨</text>
  5. <text class="section-title">为你推荐</text>
  6. <text class="section-more" v-if="hasMore" @click="$emit('more')">更多 ›</text>
  7. </view>
  8. <scroll-view class="scroll-x" scroll-x show-scrollbar="false">
  9. <view class="card-list">
  10. <view
  11. class="card-item"
  12. v-for="(item, idx) in items"
  13. :key="idx"
  14. @click="onItemClick(item)"
  15. hover-class="card-hover"
  16. >
  17. <image class="card-img" :src="item.coverImage || '/static/default.png'" mode="aspectFill" />
  18. <view class="card-body">
  19. <text class="card-title line-clamp-2">{{ item.title }}</text>
  20. <view class="card-footer">
  21. <text class="card-reason line-clamp-1">{{ item.recommendReason }}</text>
  22. <text class="card-badge" v-if="item.badge" :class="'badge-' + item.badge">{{ badgeLabel(item.badge) }}</text>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. props: {
  33. items: {
  34. type: Array,
  35. default: function() { return [] }
  36. },
  37. hasMore: {
  38. type: Boolean,
  39. default: false
  40. }
  41. },
  42. methods: {
  43. onItemClick(item) {
  44. this.$emit('itemClick', item)
  45. },
  46. badgeLabel(badge) {
  47. var map = {
  48. hot: '热门',
  49. new: '最新',
  50. renew: '续费',
  51. task: '任务'
  52. }
  53. return map[badge] || badge
  54. }
  55. }
  56. }
  57. </script>
  58. <style scoped>
  59. .recommended-section {
  60. margin: 20rpx 30rpx;
  61. }
  62. .section-header {
  63. display: flex;
  64. flex-direction: row;
  65. align-items: center;
  66. margin-bottom: 16rpx;
  67. }
  68. .section-icon {
  69. font-size: 28rpx;
  70. margin-right: 8rpx;
  71. }
  72. .section-title {
  73. font-size: 30rpx;
  74. font-weight: 700;
  75. color: #333;
  76. flex: 1;
  77. }
  78. .section-more {
  79. font-size: 24rpx;
  80. color: #999;
  81. }
  82. .scroll-x {
  83. white-space: nowrap;
  84. overflow: hidden;
  85. }
  86. .card-list {
  87. display: flex;
  88. flex-direction: row;
  89. gap: 16rpx;
  90. }
  91. .card-item {
  92. display: flex;
  93. flex-direction: column;
  94. width: 240rpx;
  95. background: #fff;
  96. border-radius: 16rpx;
  97. overflow: hidden;
  98. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  99. flex-shrink: 0;
  100. }
  101. .card-hover {
  102. opacity: 0.85;
  103. }
  104. .card-img {
  105. width: 240rpx;
  106. height: 160rpx;
  107. background: #f5f5f5;
  108. }
  109. .card-body {
  110. padding: 12rpx;
  111. display: flex;
  112. flex-direction: column;
  113. gap: 8rpx;
  114. }
  115. .card-title {
  116. font-size: 26rpx;
  117. font-weight: 600;
  118. color: #333;
  119. line-height: 1.4;
  120. height: 72rpx;
  121. }
  122. .card-footer {
  123. display: flex;
  124. flex-direction: row;
  125. align-items: center;
  126. justify-content: space-between;
  127. }
  128. .card-reason {
  129. font-size: 20rpx;
  130. color: #999;
  131. flex: 1;
  132. margin-right: 8rpx;
  133. }
  134. .card-badge {
  135. font-size: 20rpx;
  136. padding: 2rpx 10rpx;
  137. border-radius: 6rpx;
  138. flex-shrink: 0;
  139. }
  140. .badge-hot {
  141. background: #fff1f0;
  142. color: #f56c6c;
  143. }
  144. .badge-new {
  145. background: #e6f7ff;
  146. color: #1890ff;
  147. }
  148. .badge-renew {
  149. background: #fff7e6;
  150. color: #fa8c16;
  151. }
  152. .badge-task {
  153. background: #f6ffed;
  154. color: #52c41a;
  155. }
  156. .line-clamp-1 {
  157. overflow: hidden;
  158. text-overflow: ellipsis;
  159. white-space: nowrap;
  160. }
  161. .line-clamp-2 {
  162. display: -webkit-box;
  163. -webkit-box-orient: vertical;
  164. -webkit-line-clamp: 2;
  165. overflow: hidden;
  166. }
  167. </style>