DimensionArticles.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. <view class="weight-badges" v-if="article._badges && article._badges.length">
  32. <text class="weight-badge" v-for="badge in article._badges" :key="badge.name" :style="{ background: badge.color + '20', color: badge.color }">{{ badge.name }}{{ badge.weight }}%</text>
  33. </view>
  34. <text class="article-summary" v-if="article.summary">{{ article.summary }}</text>
  35. <view class="article-meta">
  36. <view class="meta-item">
  37. <text class="meta-icon">&#x1F4D6;</text>
  38. <text class="meta-text">{{ article.views || '0' }}</text>
  39. </view>
  40. <view class="meta-item">
  41. <text class="meta-icon">&#x1F44D;</text>
  42. <text class="meta-text">{{ article.likes || '0' }}</text>
  43. </view>
  44. <text class="article-date" v-if="article.date">{{ article.date }}</text>
  45. </view>
  46. </view>
  47. </template>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. var DIMENSION_MAP = {
  53. body: { name: '身', color: '#FF8C42' },
  54. mind: { name: '心', color: '#FF6B9D' },
  55. wisdom: { name: '智', color: '#6366F1' },
  56. action: { name: '行', color: '#10B981' },
  57. wealth: { name: '富', color: '#F59E0B' }
  58. }
  59. var defaultGradientColors = [
  60. 'linear-gradient(135deg, #6366F1, #818CF8)',
  61. 'linear-gradient(135deg, #8B5CF6, #A78BFA)',
  62. 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
  63. 'linear-gradient(135deg, #10B981, #34D399)',
  64. 'linear-gradient(135deg, #F97316, #FB923C)'
  65. ]
  66. export default {
  67. props: {
  68. dimensionCode: { type: String, required: true },
  69. articles: { type: Array, default: function() { return [] } },
  70. isLoggedIn: { type: Boolean, default: false },
  71. colors: { type: Array, default: function() { return defaultGradientColors } }
  72. },
  73. computed: {
  74. defaultColors: function() {
  75. return defaultGradientColors
  76. },
  77. displayArticles: function() {
  78. var self = this
  79. return (this.articles || []).map(function(item) {
  80. item._badges = self.parseWeights(item.dimensionWeights)
  81. return item
  82. })
  83. }
  84. },
  85. methods: {
  86. parseWeights: function(str) {
  87. if (!str) return []
  88. try {
  89. var obj = JSON.parse(str)
  90. var result = []
  91. for (var key in obj) {
  92. if (obj[key] > 0 && DIMENSION_MAP[key]) {
  93. result.push({ name: DIMENSION_MAP[key].name, color: DIMENSION_MAP[key].color, weight: obj[key] })
  94. }
  95. }
  96. return result
  97. } catch (e) {
  98. return []
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped>
  105. .section {
  106. margin: 20rpx 20rpx;
  107. }
  108. .section-header {
  109. display: flex;
  110. justify-content: space-between;
  111. align-items: center;
  112. margin-bottom: 20rpx;
  113. }
  114. .section-title {
  115. font-size: 30rpx;
  116. font-weight: bold;
  117. color: #333;
  118. }
  119. .section-more {
  120. font-size: 24rpx;
  121. color: #999;
  122. }
  123. .article-list {
  124. display: flex;
  125. flex-direction: column;
  126. }
  127. .article-card {
  128. background: #fff;
  129. border-radius: 20rpx;
  130. padding: 28rpx 24rpx;
  131. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  132. margin-bottom: 20rpx;
  133. }
  134. .article-card:active {
  135. opacity: 0.8;
  136. }
  137. .article-category {
  138. display: inline-block;
  139. padding: 4rpx 18rpx;
  140. border-radius: 20rpx;
  141. margin-bottom: 14rpx;
  142. }
  143. .article-category-text {
  144. font-size: 20rpx;
  145. color: #fff;
  146. font-weight: 500;
  147. }
  148. .article-title {
  149. font-size: 28rpx;
  150. font-weight: bold;
  151. color: #333;
  152. display: block;
  153. margin-bottom: 10rpx;
  154. }
  155. .weight-badges {
  156. display: flex;
  157. flex-direction: row;
  158. flex-wrap: wrap;
  159. gap: 6rpx;
  160. margin-bottom: 10rpx;
  161. }
  162. .weight-badge {
  163. font-size: 18rpx;
  164. padding: 2rpx 10rpx;
  165. border-radius: 8rpx;
  166. font-weight: 500;
  167. }
  168. .article-summary {
  169. font-size: 24rpx;
  170. color: #888;
  171. line-height: 1.5;
  172. display: block;
  173. margin-bottom: 20rpx;
  174. }
  175. .article-meta {
  176. display: flex;
  177. flex-direction: row;
  178. align-items: center;
  179. }
  180. .meta-item {
  181. display: flex;
  182. flex-direction: row;
  183. align-items: center;
  184. margin-right: 24rpx;
  185. }
  186. .meta-icon {
  187. font-size: 24rpx;
  188. margin-right: 6rpx;
  189. }
  190. .meta-text {
  191. font-size: 22rpx;
  192. color: #999;
  193. }
  194. .article-date {
  195. font-size: 22rpx;
  196. color: #bbb;
  197. margin-left: auto;
  198. }
  199. </style>