index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="ac-container">
  3. <!-- Tab 导航 -->
  4. <view class="ac-tabs">
  5. <scroll-view scroll-x enable-flex show-scrollbar="false" class="tab-scroll">
  6. <view
  7. v-for="tab in tabList"
  8. :key="tab.code"
  9. :class="['tab-item', currentTab === tab.code ? 'active' : '']"
  10. :style="currentTab === tab.code ? 'color:' + tab.color + ';border-bottom-color:' + tab.color : ''"
  11. @click="onTabChange(tab.code)"
  12. >
  13. {{ tab.name }}
  14. </view>
  15. </scroll-view>
  16. </view>
  17. <!-- 文章列表 -->
  18. <scroll-view scroll-y class="ac-list" @scrolltolower="onLoadMore">
  19. <!-- 骨架屏 -->
  20. <view v-if="loading && articles.length === 0" class="ac-skeleton">
  21. <view v-for="n in 3" :key="n" class="skeleton-card">
  22. <view class="skeleton-cover"></view>
  23. <view class="skeleton-body">
  24. <view class="skeleton-line skeleton-title"></view>
  25. <view class="skeleton-line skeleton-summary"></view>
  26. <view class="skeleton-line skeleton-summary short"></view>
  27. <view class="skeleton-line skeleton-meta"></view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 空状态 -->
  32. <view v-else-if="articles.length === 0" class="ac-empty">
  33. <image class="empty-img" src="/static/empty-article.png" mode="aspectFit"></image>
  34. <text class="empty-text">暂无文章</text>
  35. </view>
  36. <!-- 文章列表 -->
  37. <view v-else class="article-list">
  38. <view
  39. v-for="item in articles"
  40. :key="item.id"
  41. class="article-card"
  42. @click="goDetail(item.id)"
  43. >
  44. <image
  45. class="card-cover"
  46. :src="item.coverImage || '/static/default-article.png'"
  47. mode="aspectFill"
  48. />
  49. <view class="card-body">
  50. <view class="card-tags">
  51. <text class="card-category">{{ item.categoryName || '' }}</text>
  52. <text class="card-readtime">{{ item.readTime || 3 }}分钟</text>
  53. </view>
  54. <text class="card-title">{{ item.title }}</text>
  55. <text class="card-summary">{{ item.summary || '' }}</text>
  56. <view class="card-footer">
  57. <text class="card-author">{{ item.author || '浠艾福' }}</text>
  58. <text class="card-date">{{ formatDate(item.publishedAt) }}</text>
  59. <text class="card-fav">收藏 {{ item.favCount || 0 }}</text>
  60. </view>
  61. <!-- 五维彩条 -->
  62. <view v-if="item.relatedDimensions" class="card-dimensions">
  63. <view
  64. v-for="dim in parseDimensions(item.relatedDimensions)"
  65. :key="dim.code"
  66. class="dim-dot"
  67. :style="'background:' + dim.color"
  68. ></view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 加载更多 -->
  74. <view v-if="loadingMore" class="loading-more">
  75. <text class="loading-text">加载中...</text>
  76. </view>
  77. <view v-if="noMore && articles.length > 0" class="no-more">
  78. <text class="no-more-text">— 没有更多了 —</text>
  79. </view>
  80. <!-- 底部占位 -->
  81. <view class="bottom-spacer"></view>
  82. </scroll-view>
  83. <!-- 浮动发布按钮 -->
  84. <view class="ac-fab" @click="goEdit">
  85. <text class="fab-icon">+</text>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import { getArticleList } from '@/utils/api.js'
  91. export default {
  92. data() {
  93. return {
  94. tabList: [
  95. { code: '', name: '全部推荐', color: '#F97316' },
  96. { code: 'body', name: '身', color: '#FF8C42' },
  97. { code: 'mind', name: '智', color: '#6366F1' },
  98. { code: 'wisdom', name: '心', color: '#FF6B9D' },
  99. { code: 'action', name: '行', color: '#10B981' },
  100. { code: 'wealth', name: '富', color: '#F59E0B' }
  101. ],
  102. currentTab: '',
  103. articles: [],
  104. page: 1,
  105. size: 10,
  106. total: 0,
  107. loading: false,
  108. loadingMore: false,
  109. noMore: false
  110. }
  111. },
  112. onLoad() {
  113. this.loadArticles()
  114. },
  115. methods: {
  116. async loadArticles(isLoadMore) {
  117. if (!isLoadMore) {
  118. if (this.loading) return
  119. this.loading = true
  120. } else {
  121. if (this.loadingMore || this.noMore) return
  122. this.loadingMore = true
  123. }
  124. try {
  125. var params = { page: this.page, size: this.size }
  126. if (this.currentTab) {
  127. params.dimensionCode = this.currentTab
  128. }
  129. var res = await getArticleList(params)
  130. if (res.code === 200 && res.data) {
  131. var list = res.data.records || []
  132. if (this.page === 1) {
  133. this.articles = list
  134. } else {
  135. this.articles = this.articles.concat(list)
  136. }
  137. this.total = res.data.total || 0
  138. this.noMore = this.articles.length >= this.total
  139. }
  140. } catch (e) {
  141. uni.showToast({ title: '加载失败', icon: 'none' })
  142. } finally {
  143. this.loading = false
  144. this.loadingMore = false
  145. }
  146. },
  147. onTabChange(code) {
  148. if (this.currentTab === code) return
  149. this.currentTab = code
  150. this.page = 1
  151. this.articles = []
  152. this.noMore = false
  153. this.loadArticles()
  154. },
  155. onLoadMore() {
  156. if (this.noMore || this.loading || this.loadingMore) return
  157. this.page++
  158. this.loadArticles(true)
  159. },
  160. goDetail(id) {
  161. uni.navigateTo({ url: '/pages/article-center/article-detail?id=' + id })
  162. },
  163. goEdit() {
  164. uni.navigateTo({ url: '/pages/article-center/article-edit' })
  165. },
  166. formatDate(dateStr) {
  167. if (!dateStr) return ''
  168. return dateStr.slice(0, 10)
  169. },
  170. parseDimensions(str) {
  171. if (!str) return []
  172. var dimMap = {
  173. body: { code: 'body', color: '#FF8C42', name: '身' },
  174. mind: { code: 'mind', color: '#6366F1', name: '智' },
  175. wisdom: { code: 'wisdom', color: '#FF6B9D', name: '心' },
  176. action: { code: 'action', color: '#10B981', name: '行' },
  177. wealth: { code: 'wealth', color: '#F59E0B', name: '富' }
  178. }
  179. var codes = str.split(',').map(function(s) { return s.trim().toLowerCase() })
  180. return codes.filter(function(c) { return dimMap[c] }).map(function(c) { return dimMap[c] })
  181. }
  182. }
  183. }
  184. </script>
  185. <style scoped>
  186. .ac-container {
  187. min-height: 100vh;
  188. background: #f5f7fa;
  189. position: relative;
  190. }
  191. .ac-tabs {
  192. background: #fff;
  193. padding: 16rpx 0 12rpx;
  194. border-bottom: 1rpx solid #eee;
  195. position: sticky;
  196. top: 0;
  197. z-index: 10;
  198. }
  199. .tab-scroll {
  200. white-space: nowrap;
  201. padding: 0 20rpx;
  202. }
  203. .tab-item {
  204. display: inline-block;
  205. padding: 8rpx 24rpx;
  206. font-size: 26rpx;
  207. color: #666;
  208. margin-right: 12rpx;
  209. border-bottom: 3rpx solid transparent;
  210. flex-shrink: 0;
  211. }
  212. .tab-item.active {
  213. font-weight: bold;
  214. }
  215. .ac-list {
  216. height: calc(100vh - 100rpx);
  217. }
  218. /* 骨架屏 */
  219. .ac-skeleton { padding: 20rpx 24rpx; }
  220. .skeleton-card {
  221. background: #fff;
  222. border-radius: 16rpx;
  223. overflow: hidden;
  224. margin-bottom: 20rpx;
  225. }
  226. .skeleton-cover { height: 280rpx; background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
  227. .skeleton-body { padding: 20rpx; }
  228. .skeleton-line { height: 24rpx; background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; border-radius: 4rpx; margin-bottom: 12rpx; }
  229. .skeleton-title { width: 60%; }
  230. .skeleton-summary { width: 90%; }
  231. .skeleton-summary.short { width: 50%; }
  232. .skeleton-meta { width: 40%; height: 18rpx; }
  233. @keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
  234. /* 空状态 */
  235. .ac-empty { display: flex; flex-direction: column; align-items: center; padding-top: 200rpx; }
  236. .empty-img { width: 200rpx; height: 200rpx; margin-bottom: 24rpx; }
  237. .empty-text { font-size: 28rpx; color: #999; }
  238. /* 文章卡片 */
  239. .article-list { padding: 20rpx 24rpx; }
  240. .article-card {
  241. background: #fff;
  242. border-radius: 16rpx;
  243. overflow: hidden;
  244. margin-bottom: 20rpx;
  245. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  246. }
  247. .card-cover { width: 100%; height: 280rpx; background: #f0f0f0; }
  248. .card-body { padding: 20rpx; }
  249. .card-tags { display: flex; align-items: center; margin-bottom: 10rpx; }
  250. .card-category { font-size: 20rpx; color: #5B9BD5; background: rgba(91,155,213,0.1); padding: 2rpx 12rpx; border-radius: 8rpx; margin-right: 12rpx; }
  251. .card-readtime { font-size: 20rpx; color: #999; }
  252. .card-title { display: block; font-size: 28rpx; font-weight: bold; color: #333; margin-bottom: 8rpx; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  253. .card-summary { display: block; font-size: 24rpx; color: #666; line-height: 1.5; margin-bottom: 12rpx; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  254. .card-footer { display: flex; align-items: center; font-size: 20rpx; color: #999; }
  255. .card-author { margin-right: 16rpx; color: #5B9BD5; }
  256. .card-date { margin-right: 16rpx; }
  257. .card-fav { margin-left: auto; }
  258. /* 五维彩条 */
  259. .card-dimensions { display: flex; margin-top: 10rpx; gap: 8rpx; }
  260. .dim-dot { width: 20rpx; height: 20rpx; border-radius: 50%; }
  261. /* 加载更多 */
  262. .loading-more, .no-more { text-align: center; padding: 30rpx; }
  263. .loading-text { font-size: 24rpx; color: #999; }
  264. .no-more-text { font-size: 24rpx; color: #ccc; }
  265. .bottom-spacer { height: 120rpx; }
  266. /* 浮动按钮 */
  267. .ac-fab {
  268. position: fixed;
  269. right: 40rpx;
  270. bottom: 100rpx;
  271. width: 100rpx;
  272. height: 100rpx;
  273. background: linear-gradient(135deg, #F97316, #EA580C);
  274. color: #fff;
  275. border-radius: 50%;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. box-shadow: 0 4rpx 16rpx rgba(249,115,22,0.4);
  280. z-index: 100;
  281. }
  282. .fab-icon { font-size: 48rpx; font-weight: bold; line-height: 1; }
  283. </style>