category-detail.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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="calcAniWait(index)"><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. name: '',
  44. pageTitle: '加载中...',
  45. result: null,
  46. dataList: [],
  47. isLoadMore: false,
  48. loadMoreText: ''
  49. };
  50. },
  51. onLoad(e) {
  52. this.name = e.name;
  53. this.pageTitle = e.title;
  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.name, this.queryParams)
  86. .then(res => {
  87. console.log("请求成功:",res)
  88. this.fnSetPageTitle(`${this.pageTitle} (共${res.total}篇)`);
  89. this.result = res;
  90. if (this.isLoadMore) {
  91. this.dataList = this.dataList.concat(res.items);
  92. } else {
  93. this.dataList = res.items;
  94. }
  95. this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  96. setTimeout(() => {
  97. this.loading = 'success';
  98. }, 500);
  99. })
  100. .catch(err => {
  101. console.error(err);
  102. this.loading = 'error';
  103. this.loadMoreText = '加载失败,请下拉刷新!';
  104. })
  105. .finally(() => {
  106. setTimeout(() => {
  107. uni.hideLoading();
  108. uni.stopPullDownRefresh();
  109. }, 500);
  110. });
  111. },
  112. //跳转文章详情
  113. fnToArticleDetail(article) {
  114. uni.navigateTo({
  115. url: '/pagesA/article-detail/article-detail?name=' + article.metadata.name,
  116. animationType: 'slide-in-right'
  117. });
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. .app-page {
  124. width: 100vw;
  125. min-height: 100vh;
  126. display: flex;
  127. flex-direction: column;
  128. padding: 24rpx 0;
  129. background-color: #fafafd;
  130. }
  131. .loading-wrap {
  132. padding: 0 24rpx;
  133. min-height: 100vh;
  134. }
  135. .empty {
  136. height: 60vh;
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. }
  141. </style>