123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <template>
- <view class=" content ">
- <mescroll-body bottom="0" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
- :down="downOption" :up="upOption">
- <view class="list">
- <view class="list-item" @click="goLive(item)" v-for="(item,index) in list" :key="index">
- <image :src="item.liveImgUrl"></image>
- <view class="info">
- <text>{{item.liveName}}</text>
- </view>
- </view>
- </view>
- </mescroll-body>
- </view>
- </template>
- <script>
- import {
- liveList
- } from '@/api/list'
- import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
- // import { LiveWS } from '@/utils/liveWS'
- // import { login,loginByWeChat,getUserInfo,loginByApple } from '@/api/user'
- export default {
- mixins: [MescrollMixin], // 使用mixin
- data() {
- return {
- list: [],
- liveId: null, // mescroll配置
- downOption: {
- offset: 80,
- use: true,
- auto: false // 是否在初始化后自动执行下拉回调
- },
- upOption: {
- use: true,
- auto: true, // 是否在初始化时自动执行上拉回调
- page: {
- num: 0, // 当前页码
- size: 10 // 每页数据条数
- }
-
- },
- mescroll: null // mescroll实例
- }
- },
- methods: {
- goLive(item) {
- this.liveId = item.liveId
- console.log("要传的liveId", this.liveId)
- uni.navigateTo({
- url: `/pages/home/living?liveId=${item.liveId}&immediate=true`
- });
- },
- // mescroll初始化
- mescrollInit(mescroll) {
- this.mescroll = mescroll;
- },
- // 下拉刷新回调
- downCallback(mescroll) {
- // 重置列表数据
- this.list = [];
- mescroll.resetUpScroll();
- },
- // 上拉加载回调
- upCallback(mescroll) {
- const pageNum = mescroll.num;
- const pageSize = mescroll.size;
- let data = {
- pageSize: pageSize,
- page: pageNum,
- }
- liveList(data).then(res => {
- if (res.code == 200) {
- // 请求成功,处理数据
- let curPageData = res.rows || [];
- let curPageLen = curPageData.length;
- let totalSize = res.total || 0;
- // 如果是第一页,直接赋值
- if (pageNum === 1) {
- this.list = [];
- }
- // 追加新数据
- this.list = this.list.concat(curPageData);
- mescroll.endBySize(curPageLen, totalSize);
- } else {
- // 请求失败
- mescroll.endErr();
- uni.showToast({
- title: res.msg,
- icon: 'none'
- });
- }
- }).catch(err => {
- // 请求异常
- mescroll.endErr();
- console.log("请求异常:" + JSON.stringify(err));
- });
- },
- // getList() {
- // const data = {
- // page: 1,
- // page_size: 10,
- // };
- // uni.showLoading({
- // title: "处理中..."
- // });
- // liveList(data)
- // .then(res => {
- // if (res.code == 200) {
- // this.list = res.rows; // 直接赋值给 this.list
- // console.log("list>>", this.list); // ✅ 打印已定义的 this.list
- // } else {
- // uni.showToast({
- // title: res.msg,
- // icon: 'none'
- // });
- // }
- // })
- // .catch(rej => {
- // console.log("请求失败:", JSON.stringify(rej));
- // })
- // .finally(() => {
- // uni.hideLoading();
- // });
- // }
- }
- }
- </script>
- <style lang="scss" scoped>
- .content {
- background-color: #111;
- min-height: 100vh;
- padding: 24rpx;
- .list {
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- .list-item {
- border-radius: 16rpx;
- width: 340rpx;
- height: 600rpx;
- background-color: #0d0d0d;
- margin-right: 10rpx;
- margin-bottom: 24rpx;
- overflow: hidden;
- position: relative;
- .info {
- position: absolute;
- left: 20rpx;
- bottom: 14rpx;
- color: #ffffff;
- }
- image {
- width: 100%;
- height: 100%;
- }
- }
- }
- }
- </style>
|