ActionArticleRecommend.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <view class="rec-section">
  3. <view class="rec-header">
  4. <view class="rec-header-left">
  5. <text class="rec-icon">&#x1F4D6;</text>
  6. <text class="rec-title">推荐阅读</text>
  7. </view>
  8. <text class="rec-more" @click="$emit('moreArticles')">更多 ›</text>
  9. </view>
  10. <!-- 无数据 -->
  11. <view v-if="!displayArticles || displayArticles.length === 0" class="rec-empty">
  12. <text class="rec-empty-text">{{ isLoggedIn ? '暂无阅读推荐' : '登录后查看更多文章' }}</text>
  13. </view>
  14. <!-- 卡片列表 -->
  15. <view v-else class="rec-list">
  16. <view
  17. class="rec-card"
  18. v-for="(article, idx) in displayArticles"
  19. :key="article.id || idx"
  20. @click="$emit('articleClick', article)"
  21. >
  22. <!-- 封面图(可选) -->
  23. <view class="rec-card-cover" v-if="article.coverImage">
  24. <image class="rec-cover-img" :src="article.coverImage" mode="aspectFill" />
  25. <view class="rec-cover-dim" :style="{ background: article.categoryColor || gradient(idx) }">{{ article.category || '推荐文章' }}</view>
  26. </view>
  27. <!-- 文字区 -->
  28. <view class="rec-card-body" :class="{ 'rec-card-body-no-cover': !article.coverImage }">
  29. <view class="rec-category-row" v-if="!article.coverImage">
  30. <text class="rec-category-tag" :style="{ background: article.categoryColor || gradient(idx) }">{{ article.category || '推荐文章' }}</text>
  31. </view>
  32. <text class="rec-card-title">{{ article.title }}</text>
  33. <text class="rec-card-desc" v-if="article.summary">{{ article.summary }}</text>
  34. <view class="rec-card-foot">
  35. <text class="rec-card-date" v-if="article.date">{{ article.date }}</text>
  36. <view class="rec-card-stats">
  37. <text class="rec-stat">&#x1F441; {{ article.views || '0' }}</text>
  38. <text class="rec-stat">&#x2764; {{ article.likes || '0' }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. var defaultGradients = [
  48. 'linear-gradient(135deg, #10B981, #34D399)',
  49. 'linear-gradient(135deg, #059669, #10B981)',
  50. 'linear-gradient(135deg, #047857, #059669)',
  51. 'linear-gradient(135deg, #34D399, #6EE7B7)',
  52. 'linear-gradient(135deg, #10B981, #A7F3D0)'
  53. ]
  54. export default {
  55. name: 'ActionArticleRecommend',
  56. props: {
  57. articles: { type: Array, default: function() { return [] } },
  58. isLoggedIn: { type: Boolean, default: false }
  59. },
  60. computed: {
  61. displayArticles: function() {
  62. return this.articles && this.articles.length ? this.articles : []
  63. }
  64. },
  65. methods: {
  66. gradient: function(idx) {
  67. return defaultGradients[idx % defaultGradients.length]
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped>
  73. .rec-section {
  74. margin: 20rpx 20rpx 12rpx;
  75. }
  76. .rec-header {
  77. display: flex;
  78. flex-direction: row;
  79. align-items: center;
  80. justify-content: space-between;
  81. margin-bottom: 16rpx;
  82. padding: 0 4rpx;
  83. }
  84. .rec-header-left {
  85. display: flex;
  86. flex-direction: row;
  87. align-items: center;
  88. }
  89. .rec-icon {
  90. font-size: 34rpx;
  91. margin-right: 10rpx;
  92. }
  93. .rec-title {
  94. font-size: 32rpx;
  95. font-weight: 700;
  96. color: #065F46;
  97. letter-spacing: 1rpx;
  98. }
  99. .rec-more {
  100. font-size: 24rpx;
  101. color: #10B981;
  102. font-weight: 500;
  103. }
  104. /* 空状态 */
  105. .rec-empty {
  106. display: flex;
  107. justify-content: center;
  108. padding: 60rpx 0;
  109. }
  110. .rec-empty-text {
  111. font-size: 24rpx;
  112. color: #9CA3AF;
  113. }
  114. /* 卡片列表 */
  115. .rec-list {
  116. display: flex;
  117. flex-direction: column;
  118. }
  119. .rec-card {
  120. background: #FFFFFF;
  121. border-radius: 24rpx;
  122. overflow: hidden;
  123. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.08);
  124. margin-bottom: 20rpx;
  125. }
  126. .rec-card:active {
  127. opacity: 0.92;
  128. transform: scale(0.985);
  129. }
  130. /* 封面图 */
  131. .rec-card-cover {
  132. position: relative;
  133. width: 100%;
  134. height: 260rpx;
  135. background: #f0f0f0;
  136. }
  137. .rec-cover-img {
  138. width: 100%;
  139. height: 100%;
  140. }
  141. .rec-cover-dim {
  142. position: absolute;
  143. bottom: 0;
  144. left: 0;
  145. right: 0;
  146. padding: 10rpx 20rpx;
  147. background: rgba(0,0,0,0.45);
  148. }
  149. .rec-cover-dim text {
  150. font-size: 20rpx;
  151. color: #fff;
  152. font-weight: 500;
  153. }
  154. /* 文字内容区 */
  155. .rec-card-body {
  156. padding: 24rpx 24rpx 20rpx;
  157. }
  158. .rec-card-body-no-cover {
  159. padding-top: 28rpx;
  160. }
  161. .rec-category-row {
  162. margin-bottom: 12rpx;
  163. }
  164. .rec-category-tag {
  165. display: inline-block;
  166. font-size: 20rpx;
  167. color: #FFFFFF;
  168. font-weight: 500;
  169. padding: 4rpx 20rpx;
  170. border-radius: 20rpx;
  171. }
  172. .rec-card-title {
  173. font-size: 28rpx;
  174. font-weight: 700;
  175. color: #1F2937;
  176. line-height: 1.45;
  177. display: block;
  178. margin-bottom: 8rpx;
  179. }
  180. .rec-card-desc {
  181. font-size: 24rpx;
  182. color: #6B7280;
  183. line-height: 1.55;
  184. display: block;
  185. margin-bottom: 16rpx;
  186. display: -webkit-box;
  187. -webkit-box-orient: vertical;
  188. -webkit-line-clamp: 2;
  189. overflow: hidden;
  190. text-overflow: ellipsis;
  191. }
  192. .rec-card-foot {
  193. display: flex;
  194. flex-direction: row;
  195. align-items: center;
  196. justify-content: space-between;
  197. }
  198. .rec-card-date {
  199. font-size: 22rpx;
  200. color: #9CA3AF;
  201. }
  202. .rec-card-stats {
  203. display: flex;
  204. flex-direction: row;
  205. align-items: center;
  206. }
  207. .rec-stat {
  208. font-size: 22rpx;
  209. color: #9CA3AF;
  210. margin-left: 20rpx;
  211. }
  212. </style>