lists.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view class="bg-white">
  3. <mescroll-uni ref="mescrollRef" top="0" bottom="200rpx" :height="height" @init="mescrollInit"
  4. @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  5. <u-waterfall ref="uWaterfall" v-model="lists" :add-time="50">
  6. <template v-slot:left="{leftList}">
  7. <view style="padding:0 9rpx 0 30rpx">
  8. <community-list width="336rpx" type="waterfall" :list="leftList"></community-list>
  9. </view>
  10. </template>
  11. <template v-slot:right="{rightList}">
  12. <view style="padding:0 30rpx 0 9rpx;">
  13. <community-list width="336rpx" type="waterfall" :list="rightList"></community-list>
  14. </view>
  15. </template>
  16. </u-waterfall>
  17. </mescroll-uni>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. getCommunityArticleLists
  23. } from '@/api/community.js';
  24. import {
  25. trottle
  26. } from "@/utils/tools.js"
  27. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  28. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  29. export default {
  30. mixins: [MescrollMixin, MescrollMoreItemMixin],
  31. props: {
  32. cateId: {
  33. type: [String, Number]
  34. }
  35. },
  36. data() {
  37. return {
  38. height: '',
  39. upOption: {
  40. empty: {
  41. icon: '/static/images/news_null.png',
  42. tip: '暂无任何内容...', // 提示
  43. fixed: true,
  44. top: "0",
  45. }
  46. },
  47. lists: []
  48. }
  49. },
  50. mounted() {
  51. uni.$on('changeItem', (event) => {
  52. const index = this.lists.findIndex(el => el.id == event.id)
  53. if (index == -1) return
  54. this.$refs.uWaterfall.modify(event.id, 'like', event.like)
  55. this.$refs.uWaterfall.modify(event.id, 'is_like', event.is_like)
  56. })
  57. uni.getSystemInfo({
  58. success: (res) => {
  59. this.height = res.windowHeight - 46 + 'px';
  60. }
  61. });
  62. },
  63. methods: {
  64. // 获取
  65. async upCallback(page) {
  66. const pageNum = page.num
  67. const pageSize = page.size
  68. getCommunityArticleLists({
  69. cate_id: this.cateId,
  70. page_no: pageNum,
  71. page_size: pageSize,
  72. }).then(res => {
  73. // 如果是第一页需手动置空列表
  74. if (pageNum == 1) {
  75. this.$refs.uWaterfall.clear()
  76. this.lists = []
  77. }
  78. // 重置列表数据
  79. const hasNext = !!res.data.more;
  80. // 异步:让vue能够监听到数据改变过了
  81. // has_new 是通知父组件将关注右上角的是否新更新小点显示或隐藏
  82. uni.$emit('hasNew', res.data.has_new)
  83. setTimeout(() => {
  84. this.lists = [...this.lists, ...res.data.list]
  85. }, 0)
  86. this.mescroll.endSuccess(res.data.list.length, hasNext);
  87. })
  88. }
  89. }
  90. }
  91. </script>
  92. <style>
  93. </style>