index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 :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/list'
  20. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  21. // import { LiveWS } from '@/utils/liveWS'
  22. // import { login,loginByWeChat,getUserInfo,loginByApple } from '@/api/user'
  23. export default {
  24. mixins: [MescrollMixin], // 使用mixin
  25. data() {
  26. return {
  27. list: [],
  28. liveId: null, // mescroll配置
  29. downOption: {
  30. offset: 80,
  31. use: true,
  32. auto: false // 是否在初始化后自动执行下拉回调
  33. },
  34. upOption: {
  35. use: true,
  36. auto: true, // 是否在初始化时自动执行上拉回调
  37. page: {
  38. num: 0, // 当前页码
  39. size: 10 // 每页数据条数
  40. }
  41. },
  42. mescroll: null // mescroll实例
  43. }
  44. },
  45. methods: {
  46. goLive(item) {
  47. this.liveId = item.liveId
  48. console.log("要传的liveId", this.liveId)
  49. uni.navigateTo({
  50. url: `/pages/home/living?liveId=${item.liveId}&immediate=true`
  51. });
  52. },
  53. // mescroll初始化
  54. mescrollInit(mescroll) {
  55. this.mescroll = mescroll;
  56. },
  57. // 下拉刷新回调
  58. downCallback(mescroll) {
  59. // 重置列表数据
  60. this.list = [];
  61. mescroll.resetUpScroll();
  62. },
  63. // 上拉加载回调
  64. upCallback(mescroll) {
  65. const pageNum = mescroll.num;
  66. const pageSize = mescroll.size;
  67. let data = {
  68. pageSize: pageSize,
  69. page: pageNum,
  70. }
  71. liveList(data).then(res => {
  72. if (res.code == 200) {
  73. // 请求成功,处理数据
  74. let curPageData = res.rows || [];
  75. let curPageLen = curPageData.length;
  76. let totalSize = res.total || 0;
  77. // 如果是第一页,直接赋值
  78. if (pageNum === 1) {
  79. this.list = [];
  80. }
  81. // 追加新数据
  82. this.list = this.list.concat(curPageData);
  83. mescroll.endBySize(curPageLen, totalSize);
  84. } else {
  85. // 请求失败
  86. mescroll.endErr();
  87. uni.showToast({
  88. title: res.msg,
  89. icon: 'none'
  90. });
  91. }
  92. }).catch(err => {
  93. // 请求异常
  94. mescroll.endErr();
  95. console.log("请求异常:" + JSON.stringify(err));
  96. });
  97. },
  98. // getList() {
  99. // const data = {
  100. // page: 1,
  101. // page_size: 10,
  102. // };
  103. // uni.showLoading({
  104. // title: "处理中..."
  105. // });
  106. // liveList(data)
  107. // .then(res => {
  108. // if (res.code == 200) {
  109. // this.list = res.rows; // 直接赋值给 this.list
  110. // console.log("list>>", this.list); // ✅ 打印已定义的 this.list
  111. // } else {
  112. // uni.showToast({
  113. // title: res.msg,
  114. // icon: 'none'
  115. // });
  116. // }
  117. // })
  118. // .catch(rej => {
  119. // console.log("请求失败:", JSON.stringify(rej));
  120. // })
  121. // .finally(() => {
  122. // uni.hideLoading();
  123. // });
  124. // }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .content {
  130. background-color: #111;
  131. min-height: 100vh;
  132. padding: 24rpx;
  133. .list {
  134. display: flex;
  135. justify-content: space-between;
  136. flex-wrap: wrap;
  137. .list-item {
  138. border-radius: 16rpx;
  139. width: 340rpx;
  140. height: 600rpx;
  141. background-color: #0d0d0d;
  142. margin-right: 10rpx;
  143. margin-bottom: 24rpx;
  144. overflow: hidden;
  145. position: relative;
  146. .info {
  147. position: absolute;
  148. left: 20rpx;
  149. bottom: 14rpx;
  150. color: #ffffff;
  151. }
  152. image {
  153. width: 100%;
  154. height: 100%;
  155. }
  156. }
  157. }
  158. }
  159. </style>