livingList.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="content">
  3. <mescroll-body bottom="0" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  4. :down="downOption" :up="upOption">
  5. <view class="list">
  6. <view class="list-item" @click="goLive(item)" v-for="(item,index) in list" :key="index">
  7. <image class="img" v-if="item.liveImgUrl" :src="item.liveImgUrl"></image>
  8. <view class="info">
  9. <text>{{item.liveName}}</text>
  10. </view>
  11. </view>
  12. </view>
  13. </mescroll-body>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. liveList
  19. } from '@/api/living.js'
  20. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  21. export default {
  22. mixins: [MescrollMixin],
  23. data() {
  24. return {
  25. liveId: 712,
  26. recordId: 1,
  27. list: [],
  28. downOption: {
  29. offset: 80,
  30. use: true,
  31. auto: false
  32. },
  33. upOption: {
  34. use: true,
  35. auto: true,
  36. page: {
  37. num: 0,
  38. size: 10
  39. }
  40. },
  41. mescroll: null,
  42. }
  43. },
  44. onLoad() {
  45. // if (!uni.getStorageSync("AppToken")) {
  46. // uni.navigateTo({
  47. // url: '/pages/auth/login'
  48. // });
  49. // }
  50. },
  51. onUnload() {
  52. },
  53. methods: {
  54. mescrollInit(mescroll) {
  55. this.mescroll = mescroll;
  56. },
  57. // 下拉刷新回调
  58. downCallback(mescroll) {
  59. this.list = [];
  60. mescroll.resetUpScroll();
  61. },
  62. // 上拉加载回调
  63. upCallback(mescroll) {
  64. const pageNum = mescroll.num;
  65. const pageSize = mescroll.size;
  66. let data = {
  67. pageSize: pageSize,
  68. pageNum: pageNum,
  69. }
  70. liveList(data).then(res => {
  71. if (!res) {
  72. mescroll.endErr();
  73. return;
  74. }
  75. if (res.code == 200) {
  76. let curPageData = Array.isArray(res.data.list) ? res.data.list : [];
  77. let totalSize = Number(res.data.total) || 0;
  78. if (pageNum === 1) {
  79. this.list = [];
  80. }
  81. this.list = this.list.concat(curPageData);
  82. mescroll.endBySize(curPageData.length, totalSize);
  83. } else {
  84. mescroll.endErr();
  85. uni.showToast({
  86. title: res.msg,
  87. icon: 'none'
  88. });
  89. }
  90. }).catch(err => {
  91. mescroll.endErr();
  92. });
  93. },
  94. goLive(item) {
  95. uni.navigateTo({
  96. // &immediate=true
  97. url: `./living?liveId=${item.liveId}`
  98. });
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. .content {
  105. background-color: #111;
  106. min-height: 100vh;
  107. padding: 24rpx;
  108. .list {
  109. display: flex;
  110. justify-content: space-between;
  111. flex-wrap: wrap;
  112. .list-item {
  113. border-radius: 16rpx;
  114. width: 340rpx;
  115. height: 450rpx;
  116. background-color: #0d0d0d;
  117. margin-bottom: 24rpx;
  118. overflow: hidden;
  119. position: relative;
  120. .img {
  121. width: 100%;
  122. height: 100%;
  123. }
  124. .info {
  125. position: absolute;
  126. box-sizing: border-box;
  127. width: 100%;
  128. bottom: 0;
  129. padding: 20rpx;
  130. color: #ffffff;
  131. display: flex;
  132. background-color: rgba(0, 0, 0, 0.6);
  133. align-items: center;
  134. text {
  135. white-space: nowrap;
  136. overflow: hidden;
  137. text-overflow: ellipsis;
  138. }
  139. }
  140. }
  141. .list-item:nth-child(2n) {
  142. margin-right: 0;
  143. }
  144. }
  145. }
  146. </style>