category.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. fieldSelector: ['spec.hideFromList=false']
  60. },
  61. hasNext: false,
  62. dataList: [],
  63. isLoadMore: false,
  64. loadMoreText: '加载中...'
  65. };
  66. },
  67. computed: {
  68. haloConfigs() {
  69. return this.$tm.vx.getters().getConfigs;
  70. },
  71. mockJson() {
  72. return this.$tm.vx.getters().getMockJson;
  73. }
  74. },
  75. onLoad() {
  76. this.fnGetData();
  77. },
  78. onPullDownRefresh() {
  79. this.isLoadMore = false;
  80. this.queryParams.page = 0;
  81. this.fnGetData();
  82. },
  83. onReachBottom(e) {
  84. if (this.haloConfigs.basicConfig.auditModeEnabled) {
  85. uni.showToast({
  86. icon: 'none',
  87. title: '没有更多数据了'
  88. });
  89. return
  90. }
  91. if (this.hasNext) {
  92. this.queryParams.page += 1;
  93. this.isLoadMore = true;
  94. this.fnGetData();
  95. } else {
  96. uni.showToast({
  97. icon: 'none',
  98. title: '没有更多数据了'
  99. });
  100. }
  101. },
  102. methods: {
  103. fnGetData() {
  104. if (this.haloConfigs.basicConfig.auditModeEnabled) {
  105. this.dataList = this.mockJson.category.list.map((item) => {
  106. return {
  107. metadata: {
  108. name: Date.now() * Math.random(),
  109. },
  110. spec: {
  111. displayName: item.title,
  112. cover: this.$utils.checkImageUrl(item.cover)
  113. },
  114. postCount: 0
  115. }
  116. });
  117. this.loading = 'success';
  118. this.loadMoreText = '呜呜,没有更多数据啦~';
  119. uni.hideLoading();
  120. uni.stopPullDownRefresh();
  121. return;
  122. }
  123. uni.showLoading({
  124. mask: true,
  125. title: '加载中...'
  126. });
  127. // 设置状态为加载中
  128. if (!this.isLoadMore) {
  129. this.loading = 'loading';
  130. }
  131. this.loadMoreText = '加载中...';
  132. this.$httpApi.v2
  133. .getCategoryList(this.queryParams)
  134. .then(res => {
  135. console.log('请求结果:');
  136. console.log(res);
  137. this.loading = 'success';
  138. this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  139. // 处理数据
  140. this.hasNext = res.hasNext;
  141. const tempItems = res.items.map(item => {
  142. item.spec.cover = this.$utils.checkThumbnailUrl(item.spec.cover, true)
  143. return item;
  144. })
  145. if (this.isLoadMore) {
  146. this.dataList = this.dataList.concat(tempItems);
  147. } else {
  148. this.dataList = tempItems;
  149. }
  150. })
  151. .catch(err => {
  152. console.error(err);
  153. this.loading = 'error';
  154. this.loadMoreText = '加载失败,请下拉刷新!';
  155. })
  156. .finally(() => {
  157. setTimeout(() => {
  158. uni.hideLoading();
  159. uni.stopPullDownRefresh();
  160. }, 500);
  161. });
  162. },
  163. handlePreview(index, list) {
  164. uni.previewImage({
  165. current: index,
  166. urls: list.map(item => item.url)
  167. })
  168. },
  169. handleToCategory(data) {
  170. if (this.haloConfigs.basicConfig.auditModeEnabled) {
  171. return;
  172. }
  173. uni.navigateTo({
  174. url: `/pagesA/category-detail/category-detail?name=${data.metadata.name}&title=${data.spec.displayName}`
  175. })
  176. }
  177. }
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. .app-page {
  182. width: 100vw;
  183. display: flex;
  184. flex-direction: column;
  185. padding: 24rpx 0;
  186. }
  187. .auditModeEnabled {
  188. width: 100%;
  189. height: 80vh;
  190. display: flex;
  191. flex-direction: column;
  192. align-items: center;
  193. justify-content: center;
  194. }
  195. .loading-wrap {
  196. padding: 24rpx;
  197. }
  198. .app-page-content {
  199. display: flex;
  200. flex-wrap: wrap;
  201. padding: 0 12rpx;
  202. gap: 20rpx 0;
  203. }
  204. .catgory-card {
  205. width: 100%;
  206. height: 200rpx;
  207. position: relative;
  208. display: flex;
  209. flex-direction: column;
  210. box-sizing: border-box;
  211. border-radius: 12rpx;
  212. background-color: #ffff;
  213. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.03);
  214. overflow: hidden;
  215. background-repeat: no-repeat;
  216. background-size: cover;
  217. &:before {
  218. content: '';
  219. position: absolute;
  220. left: 0;
  221. top: 0;
  222. right: 0;
  223. bottom: 0;
  224. background-color: rgba(0, 0, 0, 0.15);
  225. z-index: 1;
  226. }
  227. }
  228. .content {
  229. width: 100%;
  230. height: 100%;
  231. position: relative;
  232. z-index: 2;
  233. display: flex;
  234. flex-direction: column;
  235. align-items: center;
  236. justify-content: center;
  237. }
  238. .load-text {
  239. width: 100%;
  240. text-align: center;
  241. }
  242. </style>