livingList.vue 3.0 KB

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