template.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. </view>
  8. <!-- 内容区域 -->
  9. <view v-else class="app-page-content">
  10. <view v-if="dataList.length == 0" class="content-empty flex flex-center">
  11. <!-- 空布局 -->
  12. <tm-empty icon="icon-shiliangzhinengduixiang-" label="该分类下暂无数据"></tm-empty>
  13. </view>
  14. <block v-else>
  15. <block v-for="(item, index) in dataList" :key="index">
  16. <!-- 卡片 -->
  17. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50">
  18. <!-- 列表项 -->
  19. {{ item }}
  20. </tm-translate>
  21. </block>
  22. <tm-flotbutton @click="fnToTopPage" size="m" color="light-blue" icon="icon-angle-up"></tm-flotbutton>
  23. <view class="load-text">{{ loadMoreText }}</view>
  24. </block>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  30. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  31. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  32. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  33. export default {
  34. components: {
  35. tmSkeleton,
  36. tmFlotbutton,
  37. tmTranslate,
  38. tmEmpty
  39. },
  40. data() {
  41. return {
  42. loading: 'loading',
  43. queryParams: {
  44. size: 10,
  45. page: 0
  46. },
  47. result: null,
  48. dataList: [],
  49. hasNext:false,
  50. isLoadMore: false,
  51. loadMoreText: '加载中...'
  52. };
  53. },
  54. onLoad() {
  55. this.fnSetPageTitle();
  56. },
  57. created() {
  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.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. return;
  80. uni.showLoading({
  81. mask: true,
  82. title: '加载中...'
  83. });
  84. // 设置状态为加载中
  85. if (!this.isLoadMore) {
  86. this.loading = 'loading';
  87. }
  88. this.loadMoreText = '加载中...';
  89. this.$httpApi
  90. .getXXX(this.queryParams)
  91. .then(res => {
  92. console.log('请求结果:');
  93. console.log(res);
  94. this.loading = 'success';
  95. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  96. // 处理数据
  97. this.result = res.data;
  98. if (this.isLoadMore) {
  99. this.dataList = this.dataList.concat(res.data.content);
  100. } else {
  101. this.dataList = res.data.content;
  102. }
  103. })
  104. .catch(err => {
  105. console.error(err);
  106. this.loading = 'error';
  107. this.loadMoreText = '加载失败,请下拉刷新!';
  108. })
  109. .finally(() => {
  110. setTimeout(() => {
  111. uni.hideLoading();
  112. uni.stopPullDownRefresh();
  113. }, 500);
  114. });
  115. }
  116. }
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. .app-page {
  121. width: 100vw;
  122. display: flex;
  123. flex-direction: column;
  124. padding: 24rpx 0;
  125. padding-bottom: 144rpx;
  126. }
  127. .loading-wrap {
  128. padding: 24rpx;
  129. }
  130. </style>