community_topic.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="topic">
  3. <view class="header flex row-between">
  4. <view class="normal lg bold"># {{ topicName }}</view>
  5. <view class="flex">
  6. <image src="/bundle_b/static/icon_see.png"></image>
  7. <text class="lighter sm m-l-10">{{ click }}</text>
  8. </view>
  9. </view>
  10. <!-- Menu -->
  11. <view class="menu flex">
  12. <view class="menu--item" :class="{'active': sortHot}" @click="handleSortHot">最热</view>
  13. <view class="menu--item" :class="{'active': sortNew}" @click="handleSortNew">最新</view>
  14. </view>
  15. <view>
  16. <view v-if="lists.length">
  17. <u-waterfall ref="uWaterfall" v-model="lists" :add-time="200">
  18. <template v-slot:left="{leftList}">
  19. <view style="padding:0 9rpx 0 30rpx">
  20. <community-list width="336rpx" type="waterfall" :list="leftList"></community-list>
  21. </view>
  22. </template>
  23. <template v-slot:right="{rightList}">
  24. <view style="padding:0 30rpx 0 9rpx;">
  25. <community-list width="336rpx" type="waterfall" :list="rightList"></community-list>
  26. </view>
  27. </template>
  28. </u-waterfall>
  29. </view>
  30. <view class="p-t-60" v-else>
  31. <view class="flex row-center m-t-40">
  32. <u-image width="300" height="300" :src="'/bundle_b/static/works_null.png'"></u-image>
  33. </view>
  34. <view class="text-center muted m-t-40">
  35. 暂无话题文章~
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. getCommunityTopicArticle
  44. } from "@/api/community.js"
  45. export default {
  46. data() {
  47. return {
  48. topicId: '',
  49. topicName: '',
  50. sortHot: true,
  51. sortNew: false,
  52. lists: [],
  53. click: 0, //查看|点击数
  54. page: 1,
  55. more: 1,
  56. pageSize: 10
  57. }
  58. },
  59. onLoad() {
  60. const options = this.$Route.query;
  61. this.topicId = options.id || '';
  62. this.topicName = options.name || '';
  63. },
  64. onShow() {
  65. this.getCommunityTopic()
  66. },
  67. // 触底加载
  68. onReachBottom() {
  69. console.log('触底')
  70. if (this.more) {
  71. this.getCommunityTopic()
  72. }
  73. },
  74. methods: {
  75. handleSortHot() {
  76. this.sortHot = !this.sortHot
  77. this.page = 1;
  78. this.getCommunityTopic()
  79. },
  80. handleSortNew() {
  81. this.sortNew = !this.sortNew
  82. this.page = 1;
  83. this.getCommunityTopic()
  84. },
  85. // 获取
  86. getCommunityTopic() {
  87. getCommunityTopicArticle({
  88. topic_id: this.topicId,
  89. sort_hot: this.sortHot ? 'desc' : 'asc',
  90. sort_new: this.sortNew ? 'desc' : 'asc',
  91. page_no: this.page,
  92. page_size: this.pageSize,
  93. }).then(res => {
  94. // 如果是第一页需手动置空列表
  95. if (this.page == 1) {
  96. if('uWaterfall' in this.$refs) this.$refs.uWaterfall.clear()
  97. this.lists = []
  98. }
  99. if (res.data.more === 1) {
  100. this.page += 1
  101. }
  102. this.click = res.data.click
  103. this.more = res.data.lists.more;
  104. // 异步:让vue能够监听到数据改变过了
  105. setTimeout(() => {
  106. this.lists = [...this.lists, ...res.data.lists.list]
  107. }, 0)
  108. })
  109. },
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. page {
  115. background-color: #FFFFFF;
  116. }
  117. .topic {
  118. .header {
  119. padding: 40rpx 40rpx 30rpx 30rpx;
  120. border-top: 1px solid $-color-body;
  121. border-bottom: 1px solid $-color-body;
  122. image {
  123. width: 42rpx;
  124. height: 42rpx;
  125. }
  126. }
  127. .menu {
  128. padding: 0 30rpx;
  129. &--item {
  130. margin: 20rpx 0;
  131. font-size: 28rpx;
  132. color: $-color-muted;
  133. margin-right: 50rpx;
  134. }
  135. .active {
  136. color: $-color-primary;
  137. font-weight: 500;
  138. }
  139. }
  140. }
  141. </style>