RecommendedFeed.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="section">
  3. <view class="section-header">
  4. <text class="section-title">🔥 发现好物</text>
  5. <text class="section-more" @click="$emit('more')">更多 ›</text>
  6. </view>
  7. <view class="feed-list">
  8. <!-- 无数据时显示占位 -->
  9. <template v-if="(!items || items.length === 0) && !loading">
  10. <view class="feed-card feed-placeholder" v-for="i in 4" :key="'ph-' + i">
  11. <view class="feed-img-placeholder"></view>
  12. <view class="feed-info">
  13. <text class="feed-title-placeholder line-clamp-2">精彩内容即将上线</text>
  14. <text class="feed-sub-placeholder">--</text>
  15. </view>
  16. </view>
  17. </template>
  18. <!-- 混合信息流 -->
  19. <template v-else>
  20. <view
  21. class="feed-card"
  22. v-for="item in displayItems"
  23. :key="item.id + '-' + item.type"
  24. @click="$emit('itemClick', item)"
  25. >
  26. <!-- 商品卡片 -->
  27. <template v-if="item.type === 'product'">
  28. <image class="feed-img" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
  29. <view class="feed-info">
  30. <view class="feed-tag-row">
  31. <text class="feed-type-badge product-badge">🛍️ 商品</text>
  32. </view>
  33. <text class="feed-title line-clamp-2">{{ item.name }}</text>
  34. <text class="feed-price">{{ formatPrice(item) }}</text>
  35. </view>
  36. </template>
  37. <!-- 活动卡片 -->
  38. <template v-else-if="item.type === 'activity'">
  39. <image class="feed-img" :src="item.coverImage || '/static/default-activity.png'" mode="aspectFill" />
  40. <view class="feed-info">
  41. <view class="feed-tag-row">
  42. <text class="feed-type-badge activity-badge">🔥 活动</text>
  43. <text v-if="item.statusText" class="feed-status-badge" :class="item.statusClass">{{ item.statusText }}</text>
  44. </view>
  45. <text class="feed-title line-clamp-2">{{ item.title }}</text>
  46. <view class="feed-meta-row">
  47. <text class="feed-price" v-if="item.priceLabel">{{ item.priceLabel }}</text>
  48. <text class="feed-price" v-else-if="item.price && item.price > 0">{{ formatPrice(item) }}</text>
  49. <text class="feed-price fee-free" v-else>免费</text>
  50. <text class="feed-date" v-if="item.startTime">{{ item.startTime }}</text>
  51. </view>
  52. </view>
  53. </template>
  54. </view>
  55. </template>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. props: {
  62. products: { type: Array, default: function() { return [] } },
  63. activities: { type: Array, default: function() { return [] } },
  64. maxItems: { type: Number, default: 6 },
  65. loading: { type: Boolean, default: false }
  66. },
  67. computed: {
  68. displayItems: function() {
  69. var productItems = (this.products || []).slice(0, 3).map(function(p) {
  70. return {
  71. id: p.id,
  72. type: 'product',
  73. name: p.name,
  74. coverImage: p.coverImage,
  75. price: p.price,
  76. priceLabel: p.priceLabel,
  77. memberPrice: p.memberPrice,
  78. source: p
  79. }
  80. })
  81. var activityItems = (this.activities || []).slice(0, 3).map(function(a) {
  82. return {
  83. id: a.id,
  84. type: 'activity',
  85. title: a.title,
  86. coverImage: a.coverImage,
  87. price: a.price,
  88. priceLabel: a.priceLabel,
  89. startTime: a.startTime,
  90. statusText: this.getStatusText(a.status),
  91. statusClass: this.getStatusClass(a.status),
  92. source: a
  93. }
  94. }.bind(this))
  95. // 交替合并:商品、活动、商品、活动...
  96. var merged = []
  97. var pi = 0, ai = 0
  98. var toggle = 0
  99. while ((pi < productItems.length || ai < activityItems.length) && merged.length < this.maxItems) {
  100. if (toggle % 2 === 0 && pi < productItems.length) {
  101. merged.push(productItems[pi++])
  102. } else if (ai < activityItems.length) {
  103. merged.push(activityItems[ai++])
  104. } else if (pi < productItems.length) {
  105. merged.push(productItems[pi++])
  106. }
  107. toggle++
  108. }
  109. return merged
  110. }
  111. },
  112. methods: {
  113. formatPrice: function(item) {
  114. var price = item.memberPrice || item.price
  115. if (price == null || price === 0) return '免费'
  116. return '¥' + (Number(price) / 100).toFixed(0)
  117. },
  118. getStatusText: function(status) {
  119. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  120. return map[status] || '即将开始'
  121. },
  122. getStatusClass: function(status) {
  123. var map = { upcoming: 'status-upcoming', ongoing: 'status-ongoing', ended: 'status-ended' }
  124. return map[status] || ''
  125. }
  126. }
  127. }
  128. </script>
  129. <style scoped>
  130. .section {
  131. margin: 20rpx 20rpx;
  132. }
  133. .section-header {
  134. display: flex;
  135. justify-content: space-between;
  136. align-items: center;
  137. margin-bottom: 20rpx;
  138. }
  139. .section-title {
  140. font-size: 30rpx;
  141. font-weight: bold;
  142. color: #333;
  143. }
  144. .section-more {
  145. font-size: 24rpx;
  146. color: #999;
  147. }
  148. .feed-list {
  149. display: flex;
  150. flex-direction: row;
  151. flex-wrap: wrap;
  152. gap: 16rpx;
  153. }
  154. .feed-card {
  155. width: calc(50% - 8rpx);
  156. background: #fff;
  157. border-radius: 16rpx;
  158. padding: 16rpx;
  159. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  160. box-sizing: border-box;
  161. }
  162. .feed-card:active {
  163. opacity: 0.8;
  164. }
  165. .feed-img {
  166. width: 100%;
  167. height: 200rpx;
  168. border-radius: 12rpx;
  169. background: #f0f0f0;
  170. display: block;
  171. margin-bottom: 12rpx;
  172. }
  173. .feed-img-placeholder {
  174. width: 100%;
  175. height: 200rpx;
  176. border-radius: 12rpx;
  177. background: linear-gradient(135deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  178. background-size: 200% 100%;
  179. animation: shimmer 1.5s infinite;
  180. margin-bottom: 12rpx;
  181. }
  182. @keyframes shimmer {
  183. 0% { background-position: 200% 0; }
  184. 100% { background-position: -200% 0; }
  185. }
  186. .feed-info {
  187. display: flex;
  188. flex-direction: column;
  189. }
  190. .feed-tag-row {
  191. display: flex;
  192. align-items: center;
  193. gap: 8rpx;
  194. margin-bottom: 6rpx;
  195. }
  196. .feed-type-badge {
  197. font-size: 20rpx;
  198. padding: 2rpx 8rpx;
  199. border-radius: 6rpx;
  200. font-weight: 500;
  201. }
  202. .product-badge {
  203. background: #FFF0E6;
  204. color: #F97316;
  205. }
  206. .activity-badge {
  207. background: #FEF2E6;
  208. color: #EA580C;
  209. }
  210. .feed-status-badge {
  211. font-size: 18rpx;
  212. padding: 2rpx 8rpx;
  213. border-radius: 6rpx;
  214. }
  215. .status-upcoming { background: #DBEAFE; color: #2563EB; }
  216. .status-ongoing { background: #D1FAE5; color: #16A34A; }
  217. .status-ended { background: #F3F4F6; color: #9CA3AF; }
  218. .feed-title {
  219. font-size: 26rpx;
  220. color: #333;
  221. font-weight: 500;
  222. display: block;
  223. margin-bottom: 6rpx;
  224. min-height: 36rpx;
  225. line-height: 1.4;
  226. }
  227. .feed-title-placeholder {
  228. font-size: 26rpx;
  229. color: #ccc;
  230. display: block;
  231. margin-bottom: 6rpx;
  232. min-height: 36rpx;
  233. }
  234. .feed-price {
  235. font-size: 24rpx;
  236. color: #F97316;
  237. font-weight: 600;
  238. }
  239. .fee-free {
  240. color: #22C55E;
  241. }
  242. .feed-meta-row {
  243. display: flex;
  244. align-items: center;
  245. gap: 12rpx;
  246. margin-top: 4rpx;
  247. }
  248. .feed-date {
  249. font-size: 20rpx;
  250. color: #bbb;
  251. }
  252. .feed-sub-placeholder {
  253. font-size: 24rpx;
  254. color: #ccc;
  255. }
  256. .line-clamp-2 {
  257. overflow: hidden;
  258. text-overflow: ellipsis;
  259. display: -webkit-box;
  260. -webkit-line-clamp: 2;
  261. -webkit-box-orient: vertical;
  262. }
  263. </style>