index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. onLoad() {
  46. if(!uni.getStorageSync("AppToken")){
  47. uni.navigateTo({
  48. url: '/pages/auth/login'
  49. });
  50. }
  51. },
  52. methods: {
  53. goLive(item) {
  54. this.liveId = item.liveId
  55. console.log("要传的liveId", this.liveId)
  56. uni.navigateTo({
  57. url: `/pages/home/living?liveId=${item.liveId}&immediate=true`
  58. });
  59. },
  60. // mescroll初始化
  61. mescrollInit(mescroll) {
  62. this.mescroll = mescroll;
  63. },
  64. // 下拉刷新回调
  65. downCallback(mescroll) {
  66. // 重置列表数据
  67. this.list = [];
  68. mescroll.resetUpScroll();
  69. },
  70. // 上拉加载回调
  71. upCallback(mescroll) {
  72. const pageNum = mescroll.num;
  73. const pageSize = mescroll.size;
  74. let data = {
  75. pageSize: pageSize,
  76. page: pageNum,
  77. }
  78. liveList(data).then(res => {
  79. if (res.code == 200) {
  80. // 请求成功,处理数据
  81. let curPageData = res.rows || [];
  82. let curPageLen = curPageData.length;
  83. let totalSize = res.total || 0;
  84. // 如果是第一页,直接赋值
  85. if (pageNum === 1) {
  86. this.list = [];
  87. }
  88. // 追加新数据
  89. this.list = this.list.concat(curPageData);
  90. mescroll.endBySize(curPageLen, totalSize);
  91. } else {
  92. // 请求失败
  93. mescroll.endErr();
  94. uni.showToast({
  95. title: res.msg,
  96. icon: 'none'
  97. });
  98. }
  99. }).catch(err => {
  100. // 请求异常
  101. mescroll.endErr();
  102. console.log("请求异常:" + JSON.stringify(err));
  103. });
  104. },
  105. // getList() {
  106. // const data = {
  107. // page: 1,
  108. // page_size: 10,
  109. // };
  110. // uni.showLoading({
  111. // title: "处理中..."
  112. // });
  113. // liveList(data)
  114. // .then(res => {
  115. // if (res.code == 200) {
  116. // this.list = res.rows; // 直接赋值给 this.list
  117. // console.log("list>>", this.list); // ✅ 打印已定义的 this.list
  118. // } else {
  119. // uni.showToast({
  120. // title: res.msg,
  121. // icon: 'none'
  122. // });
  123. // }
  124. // })
  125. // .catch(rej => {
  126. // console.log("请求失败:", JSON.stringify(rej));
  127. // })
  128. // .finally(() => {
  129. // uni.hideLoading();
  130. // });
  131. // }
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. .content {
  137. background-color: #111;
  138. min-height: 100vh;
  139. padding: 24rpx;
  140. .list {
  141. display: flex;
  142. justify-content: space-between;
  143. flex-wrap: wrap;
  144. .list-item {
  145. border-radius: 16rpx;
  146. width: 340rpx;
  147. height: 600rpx;
  148. background-color: #0d0d0d;
  149. margin-right: 10rpx;
  150. margin-bottom: 24rpx;
  151. overflow: hidden;
  152. position: relative;
  153. .info {
  154. position: absolute;
  155. left: 20rpx;
  156. bottom: 14rpx;
  157. color: #ffffff;
  158. }
  159. image {
  160. width: 100%;
  161. height: 100%;
  162. }
  163. }
  164. }
  165. }
  166. </style>