RecommendedSection.vue 3.5 KB

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