community-works.vue 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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="works" :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="works" :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/works_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. getCommunityWorksLists
  30. } from "@/api/community.js"
  31. export default {
  32. name: 'community-works',
  33. props: {
  34. userId: {
  35. type: Number
  36. },
  37. worksNum: {
  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. worksNum: {
  51. handler(value) {
  52. if( this.more ) {
  53. this.getCommunityWorks()
  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.modify(event.id, 'like', event.like)
  64. this.$refs.uWaterfall.modify(event.id, 'is_like', event.is_like)
  65. })
  66. },
  67. methods: {
  68. // 获取
  69. getCommunityWorks() {
  70. getCommunityWorksLists({
  71. user_id: this.userId,
  72. page_no: this.page,
  73. page_size: this.pageSize,
  74. }).then(res => {
  75. if( res.code == 1 ) {
  76. // 如果是第一页需手动置空列表
  77. if (this.page == 1) {
  78. if('uWaterfall' in this.$refs) this.$refs.uWaterfall.clear()
  79. this.lists = []
  80. }
  81. if (res.data.more === 1) {
  82. this.page += 1
  83. }
  84. this.more = res.data.more;
  85. // 异步:让vue能够监听到数据改变过了
  86. setTimeout(() => {
  87. this.lists = [...this.lists, ...res.data.list]
  88. }, 0)
  89. } else {
  90. this.$toast({ title: res.msg })
  91. }
  92. })
  93. },
  94. }
  95. }
  96. </script>