四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
6.2 KiB

  1. <template>
  2. <view class="article-section" v-if="articleList.length > 0">
  3. <view class="section-header">
  4. <text class="section-title">精选文章</text>
  5. </view>
  6. <view class="article-list">
  7. <view v-for="(article, index) in articleList" :key="article.id" class="article-item"
  8. @click="goArticleDetail(article)">
  9. <view class="article-content">
  10. <view class="article-title">{{ article.title }}</view>
  11. <view class="article-meta">
  12. <!-- <view class="article-tag">精选</view> -->
  13. <text class="article-time">{{ formatTime(article.createTime) }}</text>
  14. </view>
  15. </view>
  16. <view class="article-arrow">
  17. <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. articleList: {
  27. type: Array,
  28. default: () => []
  29. },
  30. },
  31. methods: {
  32. goArticleDetail(article) {
  33. uni.navigateTo({
  34. url: '/subPages/home/articleDetail?id=' + article.id
  35. })
  36. },
  37. formatTime(timeStr) {
  38. if (!timeStr) return ''
  39. // 处理iOS兼容性问题,将 "2025-10-23 16:36:43" 格式转换为 "2025/10/23 16:36:43"
  40. let formattedTimeStr = timeStr.replace(/-/g, '/')
  41. const date = new Date(formattedTimeStr)
  42. // 检查日期是否有效
  43. if (isNaN(date.getTime())) {
  44. console.warn('Invalid date format:', timeStr)
  45. return timeStr // 返回原始字符串
  46. }
  47. const year = date.getFullYear()
  48. const month = String(date.getMonth() + 1).padStart(2, '0')
  49. const day = String(date.getDate()).padStart(2, '0')
  50. return `${year}-${month}-${day}`
  51. },
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. // 文章列表样式
  57. .article-section {
  58. margin-top: 40rpx;
  59. padding: 0 30rpx;
  60. .article-scroll {
  61. white-space: nowrap;
  62. }
  63. .article-list {
  64. display: flex;
  65. flex-direction: column;
  66. padding: 0 20rpx;
  67. gap: 24rpx;
  68. .article-item {
  69. flex-shrink: 0;
  70. // width: 580rpx;
  71. height: 120rpx;
  72. background: #f8f9fa;
  73. border-radius: 16rpx;
  74. padding: 24rpx;
  75. display: flex;
  76. align-items: center;
  77. justify-content: space-between;
  78. transition: all 0.3s ease;
  79. &:active {
  80. transform: scale(0.98);
  81. background: #f0f1f2;
  82. }
  83. .article-content {
  84. flex: 1;
  85. display: flex;
  86. flex-direction: column;
  87. gap: 12rpx;
  88. .article-title {
  89. font-size: 32rpx;
  90. font-weight: 600;
  91. color: $primary-text-color;
  92. line-height: 1.4;
  93. display: -webkit-box;
  94. -webkit-box-orient: vertical;
  95. -webkit-line-clamp: 2;
  96. overflow: hidden;
  97. word-break: break-word;
  98. }
  99. .article-meta {
  100. display: flex;
  101. align-items: center;
  102. gap: 16rpx;
  103. .article-tag {
  104. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  105. color: #fff;
  106. font-size: 20rpx;
  107. padding: 4rpx 12rpx;
  108. border-radius: 12rpx;
  109. font-weight: 500;
  110. }
  111. .article-time {
  112. font-size: 24rpx;
  113. color: $secondary-text-color;
  114. }
  115. }
  116. }
  117. .article-arrow {
  118. margin-left: 16rpx;
  119. opacity: 0.6;
  120. }
  121. }
  122. }
  123. }
  124. // 书本列表样式(从搜索页面复制)
  125. .book-list-container {
  126. background: #fff;
  127. min-height: 50vh;
  128. }
  129. .book-list-results {
  130. padding: 32rpx;
  131. display: flex;
  132. flex-direction: column;
  133. gap: 32rpx;
  134. }
  135. .book-list-item {
  136. display: flex;
  137. align-items: center;
  138. background: #F8F8F8;
  139. height: 212rpx;
  140. gap: 16rpx;
  141. border-radius: 16rpx;
  142. padding: 0rpx 16rpx;
  143. &:last-child {
  144. border-bottom: none;
  145. }
  146. .book-list-cover {
  147. width: 136rpx;
  148. height: 180rpx;
  149. border-radius: 16rpx;
  150. overflow: hidden;
  151. margin-right: 16rpx;
  152. image {
  153. width: 100%;
  154. height: 100%;
  155. }
  156. }
  157. .book-list-info {
  158. flex: 1;
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: space-between;
  162. }
  163. .book-list-title {
  164. font-size: 32rpx;
  165. font-weight: 600;
  166. color: $primary-text-color;
  167. line-height: 48rpx;
  168. letter-spacing: 0;
  169. margin-bottom: 12rpx;
  170. overflow: hidden;
  171. text-overflow: ellipsis;
  172. }
  173. .book-list-author {
  174. font-size: 24rpx;
  175. color: $secondary-text-color;
  176. margin-bottom: 16rpx;
  177. overflow: hidden;
  178. text-overflow: ellipsis;
  179. white-space: nowrap;
  180. }
  181. .book-list-meta {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. }
  186. .book-list-duration {
  187. display: flex;
  188. align-items: center;
  189. font-size: 22rpx;
  190. color: #999;
  191. .book-list-icon {
  192. width: 18rpx;
  193. height: 18rpx;
  194. }
  195. text {
  196. margin-left: 8rpx;
  197. }
  198. }
  199. .book-list-membership {
  200. padding: 8rpx 16rpx;
  201. border-radius: 8rpx;
  202. font-size: 24rpx;
  203. color: #211508;
  204. }
  205. }
  206. .book-membership-premium {
  207. background: #E9F1FF;
  208. border: 2rpx solid #C4DAFF;
  209. }
  210. .book-membership-vip {
  211. background: #FFF4E9;
  212. border: 2rpx solid #FFE2C4;
  213. }
  214. .book-membership-basic {
  215. background: #FFE9E9;
  216. border: 2rpx solid #FFDBC4;
  217. }
  218. </style>