tag-detail.vue 3.8 KB

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