DimensionArticles.vue 3.4 KB

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