community-like.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view>
  3. <view v-if="lists.length">
  4. <u-waterfall ref="uWaterfall" v-model="lists" :add-time="50">
  5. <template v-slot:left="{leftList}">
  6. <view style="padding:0 9rpx 0 30rpx">
  7. <community-list width="336rpx" type="waterfall" :list="leftList"></community-list>
  8. </view>
  9. </template>
  10. <template v-slot:right="{rightList}">
  11. <view style="padding:0 30rpx 0 9rpx;">
  12. <community-list width="336rpx" type="waterfall" :list="rightList"></community-list>
  13. </view>
  14. </template>
  15. </u-waterfall>
  16. </view>
  17. <view class="p-t-60" v-else>
  18. <view class="flex row-center m-t-40">
  19. <u-image width="300" height="300" :src="'/bundle_b/static/like_null.png'"></u-image>
  20. </view>
  21. <view class="text-center muted m-t-40">
  22. 暂未点赞过作品哦~
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. getCommunityLikeLists
  30. } from "@/api/community.js"
  31. export default {
  32. name: 'community-like',
  33. props: {
  34. userId: {
  35. type: Number
  36. },
  37. likeNum: {
  38. type: Number
  39. }
  40. },
  41. data() {
  42. return {
  43. lists: [],
  44. page: 1,
  45. more: 1,
  46. pageSize: 10
  47. }
  48. },
  49. watch: {
  50. likeNum: {
  51. handler(value) {
  52. if (this.more) {
  53. this.getCommunityLike()
  54. }
  55. },
  56. immediate: true
  57. }
  58. },
  59. mounted() {
  60. uni.$on('changeItem', (event) => {
  61. const index = this.lists.findIndex(el => el.id == event.id)
  62. if (index == -1) return
  63. this.$refs.uWaterfall.remove(event.id)
  64. })
  65. },
  66. methods: {
  67. // 获取
  68. getCommunityLike() {
  69. getCommunityLikeLists({
  70. user_id: this.userId,
  71. page_no: this.page,
  72. page_size: this.pageSize,
  73. }).then(res => {
  74. if (res.code == 1) {
  75. // 如果是第一页需手动置空列表
  76. if (this.page == 1) {
  77. if ('uWaterfall' in this.$refs) this.$refs.uWaterfall.clear()
  78. this.lists = []
  79. }
  80. if (res.data.more === 1) {
  81. this.page += 1
  82. }
  83. this.more = res.data.more;
  84. // 异步:让vue能够监听到数据改变过了
  85. setTimeout(() => {
  86. this.lists = [...this.lists, ...res.data.list]
  87. }, 0)
  88. } else {
  89. this.$toast({
  90. title: res.msg
  91. })
  92. }
  93. })
  94. },
  95. }
  96. }
  97. </script>