test-page.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="app-page">
  3. <view v-if="loading != 'success' && articleList.length===0" class="loading-wrap">
  4. 加载中
  5. </view>
  6. <block v-else>
  7. <view v-if="articleList.length == 0" class="article-empty"><tm-empty icon="icon-shiliangzhinengduixiang-"
  8. label="博主还没有发表任何文章~"></tm-empty></view>
  9. <block v-else>
  10. <view style="width: 100%;text-align: center;display: flex;flex-direction: column;align-items: center;"
  11. v-for="(article, index) in articleList" :key="index">
  12. <image style="width: 100%;height: 250rpx;" :src="article.cover"></image>
  13. <view style="margin-top: 12rpx;">{{article.title}}</view>
  14. </view>
  15. <view class="load-text mt-12">{{ loadMoreText }}</view>
  16. </block>
  17. </block>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. components: {
  23. },
  24. data() {
  25. return {
  26. loading: 'loading',
  27. queryParams: {
  28. size: 30,
  29. page: 1
  30. },
  31. result: {},
  32. isLoadMore: false,
  33. loadMoreText: '加载中...',
  34. bannerCurrent: 0,
  35. bannerList: [],
  36. noticeList: [],
  37. articleList: [],
  38. categoryList: [],
  39. };
  40. },
  41. onLoad() {
  42. this.fnQuery();
  43. },
  44. onPullDownRefresh() {
  45. this.isLoadMore = false;
  46. this.queryParams.page = 1;
  47. this.fnQuery();
  48. },
  49. onReachBottom(e) {
  50. if (this.result.hasNext) {
  51. this.queryParams.page += 1;
  52. this.isLoadMore = true;
  53. this.fnGetArticleList();
  54. } else {
  55. uni.showToast({
  56. icon: 'none',
  57. title: '没有更多数据了'
  58. });
  59. }
  60. },
  61. methods: {
  62. fnQuery() {
  63. this.fnGetArticleList();
  64. },
  65. fnOnBannerChange(e) {
  66. this.bannerCurrent = e.current;
  67. },
  68. fnOnBannerClick(item) {
  69. if (item.id == '') return;
  70. this.fnToArticleDetail({
  71. metadata: {
  72. name: item.id
  73. }
  74. });
  75. },
  76. fnGetArticleList() {
  77. // 设置状态为加载中
  78. if (!this.isLoadMore) {
  79. this.loading = 'loading';
  80. }
  81. this.loadMoreText = '加载中...';
  82. const list = new Array(30).fill(10).map(item => {
  83. return {
  84. title: '红红火火恍恍惚惚哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈发放',
  85. cover: 'https://blog.925i.cn/upload/房间%20少女%20蓝色眼睛%20夏天的裙子%20室内绿色植物%20动漫壁纸_彼岸壁纸.webp'
  86. }
  87. })
  88. setTimeout(() => {
  89. setTimeout(() => {
  90. this.result = {
  91. hasNext: true
  92. };
  93. if (this.isLoadMore) {
  94. this.articleList = this.articleList.concat(list);
  95. } else {
  96. this.articleList = list;
  97. }
  98. }, 200)
  99. this.loading = 'success';
  100. this.loadMoreText = this.result ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  101. uni.hideLoading();
  102. uni.stopPullDownRefresh();
  103. }, 300)
  104. },
  105. //跳转文章详情
  106. fnToArticleDetail(article) {
  107. uni.navigateTo({
  108. url: '/pagesA/article-detail/article-detail?name=' + article.metadata.name,
  109. animationType: 'slide-in-right'
  110. });
  111. },
  112. // 快捷导航页面跳转
  113. fnToNavPage(item) {
  114. switch (item.type) {
  115. case 'tabbar':
  116. uni.switchTab({
  117. url: item.path
  118. });
  119. break;
  120. case 'page':
  121. uni.navigateTo({
  122. url: item.path
  123. });
  124. break;
  125. }
  126. },
  127. // 分类页面
  128. fnToCategoryPage() {
  129. uni.switchTab({
  130. url: '/pages/tabbar/category/category'
  131. });
  132. },
  133. // 所有的文章列表页面
  134. fnToArticlesPage() {
  135. uni.navigateTo({
  136. url: '/pagesA/articles/articles'
  137. });
  138. },
  139. // 根据slug查询分类下的文章
  140. fnToCategoryBy(category) {
  141. uni.navigateTo({
  142. url: `/pagesA/category-detail/category-detail?name=${category.metadata.name}&title=${category.spec.displayName}`
  143. });
  144. },
  145. fnChangeMode() {
  146. const isBlackTheme = this.$tm.vx.state().tmVuetify.black;
  147. this.$tm.theme.setBlack(!isBlackTheme);
  148. uni.setNavigationBarColor({
  149. backgroundColor: !isBlackTheme ? '#0a0a0a' : '#ffffff',
  150. frontColor: !isBlackTheme ? '#ffffff' : '#0a0a0a'
  151. });
  152. },
  153. fnToSearch() {
  154. uni.navigateTo({
  155. url: '/pagesA/articles/articles'
  156. });
  157. }
  158. }
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .app-page {
  163. width: 100vw;
  164. min-height: 100vh;
  165. display: flex;
  166. flex-direction: column;
  167. // background-color: #ffffff;
  168. .logo {
  169. width: 60rpx;
  170. height: 60rpx;
  171. box-sizing: border-box;
  172. }
  173. ::v-deep {
  174. .tm-menubars .body .body_wk .left {
  175. min-width: initial;
  176. }
  177. }
  178. }
  179. .loading-wrap {
  180. padding: 24rpx;
  181. }
  182. .search-input {
  183. background-color: #f5f5f5;
  184. align-items: center;
  185. /* #ifdef MP-WEIXIN */
  186. margin-right: 24rpx;
  187. /* #endif */
  188. &_icon {}
  189. &_text {}
  190. }
  191. .show-more {
  192. width: 42rpx;
  193. height: 42rpx;
  194. box-sizing: border-box;
  195. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.03);
  196. }
  197. .banner {
  198. overflow: hidden;
  199. }
  200. .quick-nav {
  201. background-color: #fff;
  202. box-sizing: border-box;
  203. // box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.03);
  204. .name {
  205. color: var(--main-text-color);
  206. }
  207. }
  208. .category {
  209. width: 94vw;
  210. display: flex;
  211. height: 200rpx;
  212. white-space: nowrap;
  213. margin: 0 24rpx;
  214. .content {
  215. display: inline-block;
  216. padding-left: 24rpx;
  217. &:first-child {
  218. padding-left: 0;
  219. }
  220. }
  221. .cate-empty {
  222. height: inherit;
  223. }
  224. }
  225. .page-item {
  226. &_title {
  227. position: relative;
  228. padding-left: 24rpx;
  229. font-size: 32rpx;
  230. z-index: 1;
  231. color: var(--main-text-color);
  232. &:before {
  233. content: '';
  234. position: absolute;
  235. left: 0rpx;
  236. top: 8rpx;
  237. width: 8rpx;
  238. height: 30rpx;
  239. background-color: rgba(33, 150, 243, 1);
  240. border-radius: 6rpx;
  241. z-index: 0;
  242. }
  243. }
  244. }
  245. .h_row_col2 {
  246. display: flex;
  247. flex-wrap: wrap;
  248. box-sizing: border-box;
  249. padding: 0 12rpx;
  250. .ani-item {
  251. width: 50%;
  252. }
  253. }
  254. </style>