index.vue 4.0 KB

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