DimensionArticles.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="section">
  3. <view class="section-header">
  4. <text class="section-title">🔥 推荐阅读</text>
  5. <text class="section-more" @click="$emit('moreArticles')">更多 ›</text>
  6. </view>
  7. <view class="article-list">
  8. <!-- 无数据时显示占位卡片 -->
  9. <template v-if="!displayArticles || displayArticles.length === 0">
  10. <view class="article-card" v-for="i in 3" :key="'ph-' + i">
  11. <view class="article-category" :style="{ background: colors[(i-1) % colors.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="article-meta">
  17. <view class="meta-item">
  18. <text class="meta-icon">&#x1F4D6;</text>
  19. <text class="meta-text">0</text>
  20. </view>
  21. <text class="article-date">--</text>
  22. </view>
  23. </view>
  24. </template>
  25. <!-- 有数据时显示文章卡片 -->
  26. <view v-else class="article-card" v-for="article in displayArticles" :key="article.id" @click="$emit('articleClick', article)">
  27. <view class="article-category" :style="{ background: article.categoryColor || defaultColors[0] }">
  28. <text class="article-category-text">{{ article.category || '推荐文章' }}</text>
  29. </view>
  30. <text class="article-title">{{ article.title }}</text>
  31. <text class="article-summary" v-if="article.summary">{{ article.summary }}</text>
  32. <view class="article-meta">
  33. <view class="meta-item">
  34. <text class="meta-icon">&#x1F4D6;</text>
  35. <text class="meta-text">{{ article.views || '0' }}</text>
  36. </view>
  37. <view class="meta-item">
  38. <text class="meta-icon">&#x1F44D;</text>
  39. <text class="meta-text">{{ article.likes || '0' }}</text>
  40. </view>
  41. <text class="article-date" v-if="article.date">{{ article.date }}</text>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. var defaultGradientColors = [
  49. 'linear-gradient(135deg, #6366F1, #818CF8)',
  50. 'linear-gradient(135deg, #8B5CF6, #A78BFA)',
  51. 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
  52. 'linear-gradient(135deg, #10B981, #34D399)',
  53. 'linear-gradient(135deg, #F97316, #FB923C)'
  54. ]
  55. export default {
  56. props: {
  57. dimensionCode: { type: String, required: true },
  58. articles: { type: Array, default: function() { return [] } },
  59. isLoggedIn: { type: Boolean, default: false },
  60. colors: { type: Array, default: function() { return defaultGradientColors } }
  61. },
  62. computed: {
  63. defaultColors: function() {
  64. return defaultGradientColors
  65. },
  66. displayArticles: function() {
  67. return this.articles
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped>
  73. .section {
  74. margin: 20rpx 20rpx;
  75. }
  76. .section-header {
  77. display: flex;
  78. justify-content: space-between;
  79. align-items: center;
  80. margin-bottom: 20rpx;
  81. }
  82. .section-title {
  83. font-size: 30rpx;
  84. font-weight: bold;
  85. color: #333;
  86. }
  87. .section-more {
  88. font-size: 24rpx;
  89. color: #999;
  90. }
  91. .article-list {
  92. display: flex;
  93. flex-direction: column;
  94. }
  95. .article-card {
  96. background: #fff;
  97. border-radius: 20rpx;
  98. padding: 28rpx 24rpx;
  99. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  100. margin-bottom: 20rpx;
  101. }
  102. .article-card:active {
  103. opacity: 0.8;
  104. }
  105. .article-category {
  106. display: inline-block;
  107. padding: 4rpx 18rpx;
  108. border-radius: 20rpx;
  109. margin-bottom: 14rpx;
  110. }
  111. .article-category-text {
  112. font-size: 20rpx;
  113. color: #fff;
  114. font-weight: 500;
  115. }
  116. .article-title {
  117. font-size: 28rpx;
  118. font-weight: bold;
  119. color: #333;
  120. display: block;
  121. margin-bottom: 10rpx;
  122. }
  123. .article-summary {
  124. font-size: 24rpx;
  125. color: #888;
  126. line-height: 1.5;
  127. display: block;
  128. margin-bottom: 20rpx;
  129. }
  130. .article-meta {
  131. display: flex;
  132. flex-direction: row;
  133. align-items: center;
  134. }
  135. .meta-item {
  136. display: flex;
  137. flex-direction: row;
  138. align-items: center;
  139. margin-right: 24rpx;
  140. }
  141. .meta-icon {
  142. font-size: 24rpx;
  143. margin-right: 6rpx;
  144. }
  145. .meta-text {
  146. font-size: 22rpx;
  147. color: #999;
  148. }
  149. .article-date {
  150. font-size: 22rpx;
  151. color: #bbb;
  152. margin-left: auto;
  153. }
  154. .empty-state {
  155. display: flex;
  156. justify-content: center;
  157. padding: 40rpx 0;
  158. }
  159. .empty-tip {
  160. font-size: 24rpx;
  161. color: #999;
  162. }
  163. </style>