category-detail.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="app-page">
  3. <view v-if="loading != 'success'" class="loading-wrap">
  4. <tm-skeleton model="listAvatr"></tm-skeleton>
  5. <tm-skeleton model="listAvatr"></tm-skeleton>
  6. <tm-skeleton model="listAvatr"></tm-skeleton>
  7. <tm-skeleton model="listAvatr"></tm-skeleton>
  8. </view>
  9. <block v-else>
  10. <view class="empty" v-if="dataList.length == 0"><tm-empty icon="icon-shiliangzhinengduixiang-" label="该分类下暂无文章"></tm-empty></view>
  11. <block v-else>
  12. <block v-for="(article, index) in dataList" :key="article.createTime">
  13. <!-- 文章卡片 -->
  14. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50"><article-card :article="article" @on-click="fnToArticleDetail"></article-card></tm-translate>
  15. </block>
  16. <view class="load-text">{{ loadMoreText }}</view>
  17. </block>
  18. <tm-flotbutton @click="fnToTopPage" color="light-blue" size="m" icon="icon-angle-up"></tm-flotbutton>
  19. </block>
  20. </view>
  21. </template>
  22. <script>
  23. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  24. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  25. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  26. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  27. import ArticleCard from '@/components/article-card/article-card.vue';
  28. export default {
  29. components: {
  30. tmSkeleton,
  31. tmTranslate,
  32. tmFlotbutton,
  33. tmEmpty,
  34. ArticleCard
  35. },
  36. data() {
  37. return {
  38. loading: 'loading',
  39. queryParams: {
  40. size: 10,
  41. page: 0
  42. },
  43. slug: '',
  44. pageTitle: '加载中...',
  45. result: null,
  46. dataList: [],
  47. isLoadMore: false,
  48. loadMoreText: ''
  49. };
  50. },
  51. onLoad(e) {
  52. this.slug = e.slug;
  53. this.pageTitle = e.name;
  54. this.fnGetData();
  55. },
  56. onPullDownRefresh() {
  57. this.isLoadMore = false;
  58. this.queryParams.page = 0;
  59. this.fnGetData();
  60. },
  61. onReachBottom(e) {
  62. if (this.result.hasNext) {
  63. this.queryParams.page += 1;
  64. this.isLoadMore = true;
  65. this.fnGetData();
  66. } else {
  67. uni.showToast({
  68. icon: 'none',
  69. title: '没有更多数据了'
  70. });
  71. }
  72. },
  73. methods: {
  74. fnGetData() {
  75. uni.showLoading({
  76. mask: true,
  77. title: '加载中...'
  78. });
  79. // 设置状态为加载中
  80. if (!this.isLoadMore) {
  81. this.loading = 'loading';
  82. }
  83. this.loadMoreText = '加载中...';
  84. this.$httpApi
  85. .getCategoryPostList(this.slug, this.queryParams)
  86. .then(res => {
  87. this.fnSetPageTitle(`分类:${this.pageTitle} (共${res.data.total}篇)`);
  88. this.result = res.data;
  89. if (this.isLoadMore) {
  90. this.dataList = this.dataList.concat(res.data.content);
  91. } else {
  92. this.dataList = res.data.content;
  93. }
  94. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  95. setTimeout(() => {
  96. this.loading = 'success';
  97. }, 500);
  98. })
  99. .catch(err => {
  100. console.error(err);
  101. this.loading = 'error';
  102. this.loadMoreText = '加载失败,请下拉刷新!';
  103. })
  104. .finally(() => {
  105. setTimeout(() => {
  106. uni.hideLoading();
  107. uni.stopPullDownRefresh();
  108. }, 500);
  109. });
  110. },
  111. //跳转文章详情
  112. fnToArticleDetail(article) {
  113. uni.navigateTo({
  114. url: '/pagesA/article-detail/article-detail?articleId=' + article.id,
  115. animationType: 'slide-in-right'
  116. });
  117. }
  118. }
  119. };
  120. </script>
  121. <style lang="scss">
  122. .app-page {
  123. width: 100vw;
  124. min-height: 100vh;
  125. display: flex;
  126. flex-direction: column;
  127. padding: 24rpx 0;
  128. background-color: #fafafd;
  129. }
  130. .loading-wrap {
  131. padding: 0 24rpx;
  132. min-height: 100vh;
  133. }
  134. .empty {
  135. height: 60vh;
  136. display: flex;
  137. align-items: center;
  138. justify-content: center;
  139. }
  140. </style>