DimensionArticles.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. <template v-else><view 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. </template>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. var defaultGradientColors = [
  50. 'linear-gradient(135deg, #6366F1, #818CF8)',
  51. 'linear-gradient(135deg, #8B5CF6, #A78BFA)',
  52. 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
  53. 'linear-gradient(135deg, #10B981, #34D399)',
  54. 'linear-gradient(135deg, #F97316, #FB923C)'
  55. ]
  56. export default {
  57. props: {
  58. dimensionCode: { type: String, required: true },
  59. articles: { type: Array, default: function() { return [] } },
  60. isLoggedIn: { type: Boolean, default: false },
  61. colors: { type: Array, default: function() { return defaultGradientColors } }
  62. },
  63. computed: {
  64. defaultColors: function() {
  65. return defaultGradientColors
  66. },
  67. displayArticles: function() {
  68. return this.articles
  69. }
  70. }
  71. }
  72. </script>
  73. <style scoped>
  74. .section {
  75. margin: 20rpx 20rpx;
  76. }
  77. .section-header {
  78. display: flex;
  79. justify-content: space-between;
  80. align-items: center;
  81. margin-bottom: 20rpx;
  82. }
  83. .section-title {
  84. font-size: 30rpx;
  85. font-weight: bold;
  86. color: #333;
  87. }
  88. .section-more {
  89. font-size: 24rpx;
  90. color: #999;
  91. }
  92. .article-list {
  93. display: flex;
  94. flex-direction: column;
  95. }
  96. .article-card {
  97. background: #fff;
  98. border-radius: 20rpx;
  99. padding: 28rpx 24rpx;
  100. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  101. margin-bottom: 20rpx;
  102. }
  103. .article-card:active {
  104. opacity: 0.8;
  105. }
  106. .article-category {
  107. display: inline-block;
  108. padding: 4rpx 18rpx;
  109. border-radius: 20rpx;
  110. margin-bottom: 14rpx;
  111. }
  112. .article-category-text {
  113. font-size: 20rpx;
  114. color: #fff;
  115. font-weight: 500;
  116. }
  117. .article-title {
  118. font-size: 28rpx;
  119. font-weight: bold;
  120. color: #333;
  121. display: block;
  122. margin-bottom: 10rpx;
  123. }
  124. .article-summary {
  125. font-size: 24rpx;
  126. color: #888;
  127. line-height: 1.5;
  128. display: block;
  129. margin-bottom: 20rpx;
  130. }
  131. .article-meta {
  132. display: flex;
  133. flex-direction: row;
  134. align-items: center;
  135. }
  136. .meta-item {
  137. display: flex;
  138. flex-direction: row;
  139. align-items: center;
  140. margin-right: 24rpx;
  141. }
  142. .meta-icon {
  143. font-size: 24rpx;
  144. margin-right: 6rpx;
  145. }
  146. .meta-text {
  147. font-size: 22rpx;
  148. color: #999;
  149. }
  150. .article-date {
  151. font-size: 22rpx;
  152. color: #bbb;
  153. margin-left: auto;
  154. }
  155. </style>