category.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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" style="height: 70vh;">
  11. <!-- 空布局 -->
  12. <tm-empty icon="icon-shiliangzhinengduixiang-" label="暂无数据"></tm-empty>
  13. </view>
  14. <block v-else>
  15. <tm-translate v-for="(item, index) in dataList" :key="index"
  16. style="box-sizing: border-box;width: 50%;padding: 0 8rpx;" animation-name="fadeUp"
  17. :wait="calcAniWait(index)">
  18. <view class="catgory-card" :style="{backgroundImage:`url(${item.spec.cover})`}">
  19. <view class="content" @click="handleToCategory(item)">
  20. <view style="font-size: 32rpx;color: #ffffff;">{{ item.spec.displayName }}</view>
  21. <view v-if="!haloConfigs.basicConfig.auditModeEnabled" style="font-size: 24rpx;color: #ffffff;margin-top: 6rpx;">
  22. 共 {{ item.postCount }} 篇文章
  23. </view>
  24. <view v-else style="font-size: 24rpx;color: #ffffff;margin-top: 6rpx;">
  25. 共 {{ item.postCount }} 篇内容
  26. </view>
  27. </view>
  28. </view>
  29. </tm-translate>
  30. <tm-flotbutton @click="fnToTopPage" size="m" color="light-blue"
  31. icon="icon-angle-up"></tm-flotbutton>
  32. <view class="load-text">{{ loadMoreText }}</view>
  33. </block>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  39. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  40. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  41. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  42. import MarkdownConfig from '@/common/markdown/markdown.config.js';
  43. import mpHtml from '@/components/mp-html/components/mp-html/mp-html.vue';
  44. export default {
  45. components: {
  46. tmSkeleton,
  47. tmFlotbutton,
  48. tmTranslate,
  49. tmEmpty,
  50. mpHtml
  51. },
  52. data() {
  53. return {
  54. markdownConfig: MarkdownConfig,
  55. loading: 'loading',
  56. queryParams: {
  57. size: 20,
  58. page: 1
  59. },
  60. hasNext: false,
  61. dataList: [],
  62. isLoadMore: false,
  63. loadMoreText: '加载中...'
  64. };
  65. },
  66. computed: {
  67. haloConfigs() {
  68. return this.$tm.vx.getters().getConfigs;
  69. },
  70. mockJson() {
  71. return this.$tm.vx.getters().getMockJson;
  72. }
  73. },
  74. onLoad() {
  75. this.fnGetData();
  76. },
  77. onPullDownRefresh() {
  78. this.isLoadMore = false;
  79. this.queryParams.page = 0;
  80. this.fnGetData();
  81. },
  82. onReachBottom(e) {
  83. if (this.haloConfigs.basicConfig.auditModeEnabled) {
  84. uni.showToast({
  85. icon: 'none',
  86. title: '没有更多数据了'
  87. });
  88. return
  89. }
  90. if (this.hasNext) {
  91. this.queryParams.page += 1;
  92. this.isLoadMore = true;
  93. this.fnGetData();
  94. } else {
  95. uni.showToast({
  96. icon: 'none',
  97. title: '没有更多数据了'
  98. });
  99. }
  100. },
  101. methods: {
  102. fnGetData() {
  103. if (this.haloConfigs.basicConfig.auditModeEnabled) {
  104. this.dataList = this.mockJson.category.list.map((item) => {
  105. return {
  106. metadata: {
  107. name: Date.now() * Math.random(),
  108. },
  109. spec: {
  110. displayName: item.title,
  111. cover: this.$utils.checkImageUrl(item.cover)
  112. },
  113. postCount: 0
  114. }
  115. });
  116. this.loading = 'success';
  117. this.loadMoreText = '呜呜,没有更多数据啦~';
  118. uni.hideLoading();
  119. uni.stopPullDownRefresh();
  120. return;
  121. }
  122. uni.showLoading({
  123. mask: true,
  124. title: '加载中...'
  125. });
  126. // 设置状态为加载中
  127. if (!this.isLoadMore) {
  128. this.loading = 'loading';
  129. }
  130. this.loadMoreText = '加载中...';
  131. this.$httpApi.v2
  132. .getCategoryList(this.queryParams)
  133. .then(res => {
  134. console.log('请求结果:');
  135. console.log(res);
  136. this.loading = 'success';
  137. this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  138. // 处理数据
  139. this.hasNext = res.hasNext;
  140. const tempItems = res.items.map(item => {
  141. item.spec.cover = this.$utils.checkThumbnailUrl(item.spec.cover, true)
  142. return item;
  143. })
  144. if (this.isLoadMore) {
  145. this.dataList = this.dataList.concat(tempItems);
  146. } else {
  147. this.dataList = tempItems;
  148. }
  149. })
  150. .catch(err => {
  151. console.error(err);
  152. this.loading = 'error';
  153. this.loadMoreText = '加载失败,请下拉刷新!';
  154. })
  155. .finally(() => {
  156. setTimeout(() => {
  157. uni.hideLoading();
  158. uni.stopPullDownRefresh();
  159. }, 500);
  160. });
  161. },
  162. handlePreview(index, list) {
  163. uni.previewImage({
  164. current: index,
  165. urls: list.map(item => item.url)
  166. })
  167. },
  168. handleToCategory(data) {
  169. if (this.haloConfigs.basicConfig.auditModeEnabled) {
  170. return;
  171. }
  172. uni.navigateTo({
  173. url: `/pagesA/category-detail/category-detail?name=${data.metadata.name}&title=${data.spec.displayName}`
  174. })
  175. }
  176. }
  177. };
  178. </script>
  179. <style lang="scss" scoped>
  180. .app-page {
  181. width: 100vw;
  182. display: flex;
  183. flex-direction: column;
  184. padding: 24rpx 0;
  185. }
  186. .auditModeEnabled {
  187. width: 100%;
  188. height: 80vh;
  189. display: flex;
  190. flex-direction: column;
  191. align-items: center;
  192. justify-content: center;
  193. }
  194. .loading-wrap {
  195. padding: 24rpx;
  196. }
  197. .app-page-content {
  198. display: flex;
  199. flex-wrap: wrap;
  200. padding: 0 12rpx;
  201. gap: 20rpx 0;
  202. }
  203. .catgory-card {
  204. width: 100%;
  205. height: 200rpx;
  206. position: relative;
  207. display: flex;
  208. flex-direction: column;
  209. box-sizing: border-box;
  210. border-radius: 12rpx;
  211. background-color: #ffff;
  212. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.03);
  213. overflow: hidden;
  214. background-repeat: no-repeat;
  215. background-size: cover;
  216. &:before {
  217. content: '';
  218. position: absolute;
  219. left: 0;
  220. top: 0;
  221. right: 0;
  222. bottom: 0;
  223. background-color: rgba(0, 0, 0, 0.15);
  224. z-index: 1;
  225. }
  226. }
  227. .content {
  228. width: 100%;
  229. height: 100%;
  230. position: relative;
  231. z-index: 2;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. justify-content: center;
  236. }
  237. .load-text {
  238. width: 100%;
  239. text-align: center;
  240. }
  241. </style>