index.vue 24.8 KB
Newer Older
李嘉林 committed
1 2
<template>
  <div class="lived">
李嘉林 committed
3 4
    <!-- 背景(未开始&&已结束) -->
    <div class="bgImg" v-if="liveNoticeInfo.coverUrl&&liveNoticeInfo.liveBroadcastState!=1">
程智春 committed
5 6
      <!-- <img :src="liveNoticeInfo.coverUrl" alt /> -->
      <image :src="liveNoticeInfo.coverUrl" mode="aspectFill" alt=""></image>
李嘉林 committed
7
    </div>
李嘉林 committed
8
    <!-- 直播展示层 -->
李嘉林 committed
9
    <div class="liveModel" v-if="liveNoticeInfo.liveBroadcastState>-1">
李嘉林 committed
10
      <!-- 自定义返回按钮 -->
李嘉林 committed
11 12
      <!-- ,'height':(navHeight*2-2)+'rpx' -->
      <div class="customBack flex" :style="{'top':(navHeight)+'rpx'}">
李嘉林 committed
13
        <div class="backIcon">
李嘉林 committed
14 15 16 17 18
          <img
            @click="back"
            src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAACWklEQVR4Xu3by2rVUBSH8fVXRCmiiCIWUbwi3tpSFRFFFBEviOKF4hv4BM51rO8htoPOfQZBHDgUBX0Gp58EVsGB5hx3drLXTk+mhxPy/bKSQC6yTb5ok/fbDGA2AYEFgDdm9sw38YOkF7k3N+QhAGwxs/d/xG90v5b0KidCOABgq8c//UfoUUnfcyGEAgC2efzjlsBlSZ9GBwBs9/hHLXFfzWxB0q9RAQA7PP7hhLAnktZzxTfrKX4IAHMe/2BC2IqktZzxxQGAnR5/v0R8UQBgl8ffLRVfDADY7fF3SsYXAQD2ePzt0vGDAwB7Pf5WhPhBAYB9ZrZqZjejxA8GAOz3PX8jUvwgAMABj78eLb53AGDex/5axPheAYCDvuevRo3vDQA45PFXIsf3AgAc9rG/HD0+OwBwxOMv1RCfFQA45mN/sZb4bADACY9frik+CwBw0sd+qbb4zgDAKd/zizXGdwIATnv8+VrjkwGAMz72Z2uO7wLwzsye1x6fBODX+m9jiE8FWDCzzy0Aa5JWJgCF+Tnptjjw0cwujAEhFeCemTVPbttOglVMQhJAs+envBKER0gGGAtCJ4AxIHQGqB0hC0DNCNkAakXIClAjQnaA2hB6AagJoTeAWhB6BagBoXeA6AiDAERGGAwgKsKgABERBgeIhlAEIBJCMYAoCEUBIiAUByiNEALgPxDeSnqZ8556GIApEX5Kal6/ybaEApgC4Yukc9nqI3wv8LeYllvu4/9oagMEOO4PX5r3in+YWRM/rg8mco5y6rrCnQNSQ1L/NwNIlRvL/34D8BMaUGntkTQAAAAASUVORK5CYII="
            alt
          />
李嘉林 committed
19 20
        </div>
        <div class="shopName flex">
李嘉林 committed
21
          <div class="img" v-if="shopLogo">
李嘉林 committed
22
            <img :src="shopLogo" alt />
李嘉林 committed
23 24
          </div>
          <div class="info">
李嘉林 committed
25
            <p class="name line-clamp1" v-if="shopName">{{shopName}}</p>
程智春 committed
26
            <p class="num" v-if="liveNoticeInfo.liveBroadcastState != 2 && liveNoticeInfo.liveBroadcastState != 4">
程智春 committed
27
              <span>{{historyWatchNum}}</span>
李嘉林 committed
28
              <span style="margin-left:6px;">观看</span>
李嘉林 committed
29 30
            </p>
          </div>
李嘉林 committed
31
          <div class="toShop" @click="toShop">进店</div>
李嘉林 committed
32 33
        </div>
      </div>
李嘉林 committed
34 35
      <!-- 未开始展示 -->
      <notStarted v-if="liveNoticeInfo.liveBroadcastState==0" :info="liveNoticeInfo"></notStarted>
李嘉林 committed
36 37
      <!-- 直播暂停展示 -->
      <isPauseShow v-if="liveNoticeInfo.liveBroadcastState==3" :info="liveNoticeInfo"></isPauseShow>
李嘉林 committed
38
      <!-- 结束展示 -->
李嘉林 committed
39
      <livedIsEnded
程智春 committed
40
        v-if="(liveNoticeInfo.openPlayback == 1 && (liveNoticeInfo.liveBroadcastState==2 || liveNoticeInfo.liveBroadcastState==4)) || (liveNoticeInfo.openPlayback == 0 && !liveNoticeInfo.playbackUrl && (liveNoticeInfo.liveBroadcastState==4 || liveNoticeInfo.liveBroadcastState==2))"
李嘉林 committed
41 42
        :updateGoods="updateGoods"
        :endInfo="endInfo"
程智春 committed
43
        :status="liveNoticeInfo.liveBroadcastState"
李嘉林 committed
44 45
        :goodsList="goodsList"
      ></livedIsEnded>
李嘉林 committed
46
      <!-- 控件层 -->
李嘉林 committed
47
      <livedControls
程智春 committed
48
        v-if="liveNoticeInfo.liveBroadcastState==0 || liveNoticeInfo.liveBroadcastState==1 || (liveNoticeInfo.liveBroadcastState==2 && liveNoticeInfo.openPlayback == 0 && liveNoticeInfo.playbackUrl) || liveNoticeInfo.liveBroadcastState==3"
李嘉林 committed
49
        :info="liveNoticeInfo"
李嘉林 committed
50
        :entryNoticeText="entryNoticeText"
李嘉林 committed
51
        :guestBookList="guestBookList"
李嘉林 committed
52
        :updateVal="updateVal"
李嘉林 committed
53
        :updateGoods="updateGoods"
李嘉林 committed
54
        :likeInfo="likeInfo"
李嘉林 committed
55
        :goodsList="goodsList"
李嘉林 committed
56
        @toSendMsg="toSendMsg"
李嘉林 committed
57
      ></livedControls>
程智春 committed
58 59 60 61 62 63 64 65 66 67

      <video
        v-if="liveNoticeInfo.openPlayback == 0 && liveNoticeInfo.playbackUrl && liveNoticeInfo.playbackUrl[0] && liveNoticeInfo.liveBroadcastState == 2"
        style="width:100%;height:100vh;z-index:-1"
        :src="liveNoticeInfo.playbackUrl[0]"
        autoplay
        :show-fullscreen-btn="false"
        object-fit="cover"
      />
      <div class="masker" ></div>
李嘉林 committed
68
    </div>
李嘉林 committed
69
    <!-- 直播 -->
李嘉林 committed
70
    <live-player
李嘉林 committed
71
      v-if="liveNoticeInfo.liveBroadcastState==1&&liveNoticeInfo.boStreamRTMP"
李嘉林 committed
72
      class="livePlayer"
李嘉林 committed
73
      id="liveDemo"
李嘉林 committed
74
      :src="liveNoticeInfo.boStreamRTMP"
李嘉林 committed
75
      mode="live"
李嘉林 committed
76
      :picture-in-picture-mode="['push','pop']"
李嘉林 committed
77
      autoplay
李嘉林 committed
78 79
      object-fit="fillCrop"
      orientation="vertical"
李嘉林 committed
80 81
      auto-pause-if-open-native="true"
      auto-pause-if-navigate="true"
李嘉林 committed
82
      @error="error"
李嘉林 committed
83
      @statechange="changes"
李嘉林 committed
84
    />
程智春 committed
85

程智春 committed
86
    
程智春 committed
87

程智春 committed
88
  
李嘉林 committed
89 90
    <!-- object-fit="fillCrop" -->
    <!-- orientation="horizontal" -->
李嘉林 committed
91 92 93 94
  </div>
</template>

<script type="text/ecmascript-6">
李嘉林 committed
95 96 97 98 99 100
import {
  serialize,
  getQueryVariable,
  DFSImg,
  getNavbarInfo
} from "@/utils/index";
李嘉林 committed
101
import live from "@/api/live";
李嘉林 committed
102 103 104
import notStarted from "@/components/livedModel/notStarted";
import livedControls from "@/components/livedModel/livedControls";
import livedIsEnded from "@/components/livedModel/livedIsEnded";
李嘉林 committed
105
import isPauseShow from "@/components/livedModel/isPauseShow";
李嘉林 committed
106 107
import spokesman from "@/api/spokesman";
import shop from "@/api/shop";
李嘉林 committed
108 109 110 111
export default {
  name: "",
  data() {
    return {
李嘉林 committed
112 113 114 115 116 117
      liveId: "", //直播间id
      livedUrl: "rtmp://58.200.131.2:1935/livetv/hunantv",
      shopName: "",
      shopLogo: "",
      backPath: "",
      isLoading: false,
李嘉林 committed
118
      status: 0, // 0:未开始 1:直播中 2:已结束
李嘉林 committed
119
      // 总数据
李嘉林 committed
120
      liveNoticeInfo: {}, //详情
程智春 committed
121
      historyWatchNum:0,
李嘉林 committed
122 123
      entryNoticeText: "", //用户通知
      guestBookList: [], // 定时查评论
李嘉林 committed
124
      goodsList: [], //商品列表
李嘉林 committed
125
      updateVal: 0, //子组件监听此数据进行数据赋值
李嘉林 committed
126
      updateGoods: 0, //商品相关组件监听
李嘉林 committed
127
      likeInfo: {}, //点赞
李嘉林 committed
128 129
      isVideo: false, //是否有直播或回放链接
      liveTime: null, //定时器
李嘉林 committed
130
      isWifi: true, //提示网络环境
李嘉林 committed
131 132 133
      infoTiming: null, //全局定时器
      goodTiming: null, //商品定时器
      endInfo: {}, //直播结束详情
李嘉林 committed
134 135
      firstComing: true, // 首次进入
      params: {},
程智春 committed
136
      // userId: "",
李嘉林 committed
137
      hasInvitationStatus: 0, // 邀请资格:0-不能够邀请下级,1-能够邀请下级
李嘉林 committed
138
      spokesmanObj: {}, //分销员信息
程智春 committed
139
      userId : '', //用户id
李嘉林 committed
140
      navTop: 0,
程智春 committed
141
      navHeight: 0,
程智春 committed
142
      isTimeLock: true, //时间锁
程智春 committed
143

程智春 committed
144
      isTimeFirstReq: true, //第一次数据请求
程智春 committed
145

程智春 committed
146
      newCommentsTime: 0,
程智春 committed
147 148
      userActivebeginTime: 0,
      videoContext:null,
程智春 committed
149 150

      openLiveTimer : null,
李嘉林 committed
151 152
    };
  },
李嘉林 committed
153
  components: {
李嘉林 committed
154
    notStarted,
李嘉林 committed
155
    livedControls,
李嘉林 committed
156 157
    livedIsEnded,
    isPauseShow
李嘉林 committed
158
  },
李嘉林 committed
159
  computed: {},
李嘉林 committed
160
  onLoad(options) {
程智春 committed
161 162 163 164 165
    if(this.videoContext){
      this.videoContext.resume()
      this.videoContext.play()
    }
    
程智春 committed
166
    console.log("onLoad",options);
程智春 committed
167 168
    this.isTimeLock = true;
    this.isTimeFirstReq = true;
程智春 committed
169
    this.newCommentsTime = 0;
李嘉林 committed
170
    wx.setKeepScreenOn({
李嘉林 committed
171 172
      keepScreenOn: true
    });
李嘉林 committed
173 174 175 176
    getNavbarInfo(res => {
      console.log(res, "--------------------125");
      this.navTop = res.navTop;
      this.navHeight = res.navHeight;
李嘉林 committed
177
    });
李嘉林 committed
178 179
    wx.getNetworkType({
      success: function(res) {
李嘉林 committed
180
        if (res.networkType != "wifi") {
李嘉林 committed
181 182
          wx.showModal({
            content: "您当前处于非wifi网络环境下",
李嘉林 committed
183
            confirmColor: "#ff877d",
李嘉林 committed
184 185 186 187 188 189 190 191 192
            success: function(res) {
              if (res.confirm) {
              } else if (res.cancel) {
              }
            }
          });
        }
      }
    });
程智春 committed
193
    if(options.params){
程智春 committed
194

程智春 committed
195
      this.params = JSON.parse(options.params);
程智春 committed
196

程智春 committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
      console.log(this.params, "-----------------133");
      this.$store.commit("setOfflineShopCode", this.params.offlineShopCode);
      this.liveId = this.params.liveId;
      this.shopName = this.params.shopName;
      this.backPath = this.params.fromPagePath || "/";
      this.shopLogo = DFSImg(this.params.shopLogo, 40, 40);
      // 是否有分销员信息
      if (this.params.spokesmanGroupId) {
        this.$store.commit("setSpokesman", {
          spokesmanGroupId: this.params.spokesmanGroupId,
          spokesmanShopId: this.params.spokesmanShopId,
          spokesmanRelId: this.params.spokesmanRelId,
          userId : this.params.userId
        });
      }
    }else if(options.scene){
      var scene = decodeURIComponent(options.scene); //参数二维码传递过来的参数
      console.log(scene)
      let sceneInfo = scene.split(',')
      console.log('sceneInfo',sceneInfo)
      this.liveId = sceneInfo[0].split('=')[1]
      this.backPath = '/';
      console.log('liveId',this.liveId)
      if(sceneInfo[1]){
        let fxyInfo = sceneInfo[1].split('=')[1]
        console.log('fxyInfo',fxyInfo)
        if(fxyInfo){
          let querys = fxyInfo.split('_');
          if(querys[1]){
            this.$store.commit("setSpokesman", {
              spokesmanGroupId: querys[1],
              spokesmanShopId: querys[2],
              spokesmanRelId: querys[3]
            });
            this.$set(this.params,'spokesmanGroupId',querys[1])
            this.$set(this.params,'spokesmanShopId',querys[2])
            this.$set(this.params,'spokesmanRelId',querys[3])

            console.log('this.params',this.params)
          }
        }
      }
      
李嘉林 committed
240
    }
程智春 committed
241

李嘉林 committed
242
    this.init();
程智春 committed
243 244 245 246
    this.openLiveTimer = setInterval(() => {
        this.init();
    },5000)
    
程智春 committed
247

程智春 committed
248
    // this.userEntry("IN");
李嘉林 committed
249 250 251 252

    // 通过分享进入直播间重新查询订阅消息配置
    this.getMsgConfig();
    this.isLogin();
程智春 committed
253 254

    this.getServerTimeNow();
李嘉林 committed
255 256 257
  },

  onShareAppMessage(options) {
李嘉林 committed
258 259 260 261 262
    let query = {
      liveBroadcastId: this.liveId,
      shareType: "WX"
    };
    live.addShareRecord(query).then();
李嘉林 committed
263
    let _this = this;
程智春 committed
264 265 266 267 268 269 270
    console.log(this.userId,'this.userId')
    if(this.userId){
      if (this.hasInvitationStatus == 1) {
        Object.assign(this.params, this.params, this.spokesmanObj,{userId : this.userId});
      }else{
        Object.assign(this.params, this.params,{userId : this.userId});
      }
李嘉林 committed
271
    }
程智春 committed
272 273
    
    console.log(options)
李嘉林 committed
274
    console.log(this.params, "--------------161");
程智春 committed
275
    console.log(`/pages/lived/main?params=${JSON.stringify(this.params)}`)
李嘉林 committed
276 277 278
    let shareObj = {
      title: this.liveNoticeInfo.title,
      path: `/pages/lived/main?params=${JSON.stringify(this.params)}`,
李嘉林 committed
279
      imageUrl: this.liveNoticeInfo.shareUrl,
李嘉林 committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
      success: function(res) {
        console.log("-----------success");
        // 转发成功之后的回调
        if (res.errMsg == "shareAppMessage:ok") {
          console.log(res, "分享成功");
        }
      },
      fail: function(res) {
        console.log("-----------fail");
        // 转发失败之后的回调
        if (res.errMsg == "shareAppMessage:fail cancel") {
          console.log(res, "取消转发");
        } else if (res.errMsg == "shareAppMessage:fail") {
          console.log(res, "转发失败");
        }
      }
    };
    console.log(shareObj, "----------------168");
    return shareObj;
李嘉林 committed
299
  },
程智春 committed
300
  onHide() {
程智春 committed
301 302
    this.userEntry("OUT");
  },
程智春 committed
303
  onShow() {
程智春 committed
304 305 306 307 308
    if(this.videoContext){
      this.videoContext.resume()
      this.videoContext.play()
    }
    
程智春 committed
309
    console.log("onShow");
程智春 committed
310
    this.userEntry("IN");
程智春 committed
311
    this.isLogin()
程智春 committed
312
  },
李嘉林 committed
313 314 315
  onUnload() {
    this.liveNoticeInfo.liveBroadcastState = -1;
    this.liveNoticeInfo = {};
李嘉林 committed
316
    this.liveNoticeInfo.boStreamRTMP = "";
程智春 committed
317 318
    this.videoContext = wx.createLivePlayerContext("liveDemo");
    this.videoContext.stop();
李嘉林 committed
319
    this.userEntry("OUT");
李嘉林 committed
320
    this.firstComing = true;
李嘉林 committed
321
    if (this.infoTiming) {
李嘉林 committed
322
      clearInterval(this.infoTiming);
李嘉林 committed
323
      this.infoTiming = null;
李嘉林 committed
324
    }
李嘉林 committed
325 326
    if (this.goodTiming) {
      clearInterval(this.goodTiming);
李嘉林 committed
327
      this.goodTiming = null;
李嘉林 committed
328
    }
程智春 committed
329 330 331 332
    if(this.openLiveTimer){
      clearInterval(this.openLiveTimer);
      this.openLiveTimer = null;
    }
李嘉林 committed
333
  },
李嘉林 committed
334
  mounted() {},
李嘉林 committed
335 336
  methods: {
    // 初始化数据
李嘉林 committed
337
    init() {
程智春 committed
338
      let  _this = this;
李嘉林 committed
339 340 341 342
      let liveBroadcastId = this.liveId;
      live.getLiveInfo(liveBroadcastId).then(res => {
        if (res.data.code == 200) {
          console.log(res.data.data, "------73");
程智春 committed
343 344
          this.shopName = res.data.data.orgName;
          this.shopLogo = DFSImg(res.data.data.logoUrl, 40, 40);
李嘉林 committed
345
          this.liveNoticeInfo = res.data.data;
程智春 committed
346 347
          this.liveNoticeInfo.coverUrl = this.liveNoticeInfo.coverUrl? DFSImg(this.liveNoticeInfo.coverUrl): "";
          this.liveNoticeInfo.shareUrl = this.liveNoticeInfo.coverUrl? DFSImg(this.liveNoticeInfo.coverUrl, 500, 400): "";
李嘉林 committed
348
          this.getGoodsList();
李嘉林 committed
349
          if (this.liveNoticeInfo.liveBroadcastState == 2) {
李嘉林 committed
350 351
            // 调直播结束
            this.endLived();
李嘉林 committed
352
          } else {
程智春 committed
353
            console.log("这里");
程智春 committed
354
            // this.timingGetInfo();
李嘉林 committed
355
          }
程智春 committed
356 357 358 359 360 361 362 363 364 365 366
          // if (this.liveNoticeInfo.liveBroadcastState != 2 && !this.goodTiming) {
          //   this.goodTiming = setInterval(() => {
          //     console.log("--------获取商品接口");
              
          //   }, 5000);
          // } else if (
          //   this.liveNoticeInfo.liveBroadcastState == 2 &&
          //   this.goodTiming
          // ) {
          //   clearInterval(this.goodTiming);
          // }
程智春 committed
367 368 369 370

          if(this.liveNoticeInfo.liveBroadcastState == 4){
            this.endLived();
          }
李嘉林 committed
371
        }
李嘉林 committed
372
      });
程智春 committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
      //绑定关系
      wx.getStorage({
        key: "sessionid",
        success : res => {
          // 查询分销员信息
          console.log(res,'绑定关系',this.params,this.params.spokesmanRelId,this.params.userId)
          if(this.params.spokesmanRelId){
            live.becomepokesmanCustomer(this.params.spokesmanRelId).then(res=>{
              console.log(res,"----------------------becomepokesmanCustomer")
            })
          }else if(this.params.userId){
            live.saveCustomerInviterInviteeRel(this.params.userId).then(res=>{
              console.log(res,"----------------------saveCustomerInviterInviteeRel")
            })
          }
        },
        fail(res) {}
      });
李嘉林 committed
391
    },
李嘉林 committed
392
    back() {
程智春 committed
393
      console.log(this.backPath,'this.backPath')
程智春 committed
394 395 396
      let query = {
        sessionid: wx.getStorageSync("sessionid") || ""
      };
李嘉林 committed
397 398
      // 返回商城
      wx.reLaunch({
程智春 committed
399 400 401
        url: `../index/main?from=livedBackShop&backpath=${
          this.backPath
        }&params=${JSON.stringify(query)}`
李嘉林 committed
402
      });
李嘉林 committed
403
    },
李嘉林 committed
404 405 406 407 408 409 410 411
    // 是否登录
    isLogin() {
      let _this = this;
      wx.getStorage({
        key: "sessionid",
        success(res) {
          // 查询分销员信息
          _this.getSpokesman();
程智春 committed
412
          _this.getUserId();
李嘉林 committed
413
        },
李嘉林 committed
414
        fail(res) {}
李嘉林 committed
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
      });
    },
    getMsgConfig() {
      if (!this.$store.state.subscribeMessageObj) {
        shop.getWxMiniSubscribeMessageConfig().then(res => {
          if (res.data.code == 200) {
            const data = res.data.data;
            console.log("wx mini subscribe message data: ", data);
            if (data != null) {
              const subscribeMessageObj = {};
              for (var key in data) {
                if (data[key] && data[key].template_id) {
                  subscribeMessageObj[key] = data[key].template_id;
                }
              }

              this.$store.commit("setSubscribeMessageObj", subscribeMessageObj);
            }
          }
        });
      }
    },
程智春 committed
437
    //获取分销员信息
李嘉林 committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451
    getSpokesman() {
      spokesman.getSpokesmanidByShare().then(res => {
        if (res.data.code == 200) {
          if (res.data.data.hasInvitationStatus == 1) {
            this.hasInvitationStatus = 1;
            this.spokesmanObj = {
              spokesmanGroupId: res.data.data.groupId,
              spokesmanShopId: res.data.data.shopId,
              spokesmanRelId: res.data.data.spokesmanId
            };
          }
        }
      });
    },
程智春 committed
452 453 454 455 456 457 458 459
    getUserId(){
      live.getUserInfo().then(res => {
        if(res.data.code=="200"&&res.data.data){ 
          console.log('getUserId')
          this.userId = res.data.data.userId
        }
      })
    },
李嘉林 committed
460
    toShop() {
李嘉林 committed
461
      // 到商城首页
李嘉林 committed
462 463 464 465
      this.backPath = "/";
      wx.reLaunch({
        url: `../index/main?from=livedToIndex&backpath=${this.backPath}`
      });
李嘉林 committed
466
    },
李嘉林 committed
467
    // 定时查询直播数据
程智春 committed
468
    timingGetInfo(serverTime) {
程智春 committed
469
      if (this.isTimeLock) {
程智春 committed
470
        this.isTimeLock = false;
程智春 committed
471 472 473
        let dataTime = this.isTimeFirstReq
          ? serverTime - 2000
          : this.newCommentsTime;
程智春 committed
474 475 476
        let userTime = this.isTimeFirstReq
          ? serverTime - 2000
          : this.userActivebeginTime;
程智春 committed
477 478 479
        // 前五秒
        let query = {
          id: Number(this.liveId),
程智春 committed
480
          beginTime: dataTime,
程智春 committed
481
          userActivebeginTime: userTime //用户进入时间
程智春 committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
        };
        live.getLiveStateById(query).then(res => {
          this.isTimeFirstReq = false;
          this.isTimeLock = true;
          if (res.data.code == 200) {
            let resData = res.data.data;
            // 1、判断状态如果发生改变才init();
            // 2、直播中给用户进入通知、评论、点赞数赋值
            if (
              this.liveNoticeInfo.liveBroadcastState == 0 &&
              resData.liveState == "NO_LIVE"
            ) {
              // 未开始且接口也未开始不作操作
            } else if (
              this.liveNoticeInfo.liveBroadcastState == 1 &&
              resData.liveState == "IN_LIVE"
            ) {
            } else if (
              this.liveNoticeInfo.liveBroadcastState == 0 &&
              resData.liveState == "IN_LIVE"
            ) {
              console.log("未开始----直播中");
              // 未开始且接口直播中/直播中且接口已结束
李嘉林 committed
505
              this.init();
程智春 committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
            } else if (
              (this.liveNoticeInfo.liveBroadcastState == 2 &&
                resData.liveState == "END_LIVE") ||
              (this.liveNoticeInfo.liveBroadcastState == 1 &&
                resData.liveState == "END_LIVE")
            ) {
              //直播结束且接口已结束
              if (this.firstComing) {
                this.firstComing = false;
                this.init();
              }
            } else if (
              this.liveNoticeInfo.liveBroadcastState == 1 &&
              resData.liveState == "PAUSE_LIVE"
            ) {
              this.liveNoticeInfo.liveBroadcastState = 3;
            } else if (
              this.liveNoticeInfo.liveBroadcastState == 3 &&
              resData.liveState == "IN_LIVE"
            ) {
              this.liveNoticeInfo.liveBroadcastState = 1;
李嘉林 committed
527
            }
程智春 committed
528 529
            // console.log("resData.guestBookList---》", resData.guestBookList)
            this.guestBookList = resData.guestBookList; //评论列表
程智春 committed
530 531 532 533 534
            if (resData.guestBookList && resData.guestBookList.length) {
              this.newCommentsTime =
                resData.guestBookList[
                  resData.guestBookList.length - 1
                ].createTimeStamp;
李嘉林 committed
535
            }
程智春 committed
536 537 538 539 540
            if (resData.entryNoticeList && resData.entryNoticeList.length) {
              this.userActivebeginTime =
                resData.entryNoticeList[
                  resData.entryNoticeList.length - 1
                ].createTimeStamp;
程智春 committed
541
            }
程智春 committed
542 543 544 545
            this.likeInfo = resData.likeInfo; //点赞信息
            // 直播中且接口直播中---主要操作
            // 数据初始化
            this.entryNoticeText = "";
程智春 committed
546
            this.liveNoticeInfo.historyWatchNum = resData.historyWatchNum - 0 >= 10000 ? ((resData.historyWatchNum - 0) / 10000).toFixed(1) + 'w' : resData.historyWatchNum; //观看人数
程智春 committed
547
            this.historyWatchNum = resData.historyWatchNum - 0 >= 10000 ? ((resData.historyWatchNum - 0) / 10000).toFixed(1) + 'w' : resData.historyWatchNum; //观看人数
程智春 committed
548 549 550 551
            if (resData.entryNoticeList.length > 0) {
              if (resData.entryNoticeList.length == 1) {
                this.entryNoticeText = `${resData.entryNoticeList[0].userName}`; //用户进入
              } else {
程智春 committed
552 553 554
                this.entryNoticeText = `${
                  resData.entryNoticeList[0].userName
                }${resData.entryNoticeList.length}人`; //用户进入
程智春 committed
555 556
              }
            }
程智春 committed
557

程智春 committed
558
            this.updateVal = new Date().getTime(); //监听使用数据
程智春 committed
559 560 561 562
          } else {
            // if (this.infoTiming) {
            //   clearInterval(this.infoTiming);
            // }
李嘉林 committed
563
          }
程智春 committed
564
        });
程智春 committed
565 566
      } else {
        console.log("上次请求未结束,进行了下一次请求");
程智春 committed
567
      }
李嘉林 committed
568
    },
李嘉林 committed
569
    // 获取商品列表
李嘉林 committed
570 571 572 573 574 575 576 577 578 579 580
    getGoodsList() {
      let id = this.liveId;
      live.getListByLiveBroadcastId(id).then(res => {
        if (res.data.code == 200) {
          this.goodsList = [];
          let arr = [];
          if (res.data.data.length > 0) {
            this.goodsList = res.data.data.forEach((item, index) => {
              if (item.productImgUrl) {
                item.productImgUrl = DFSImg(item.productImgUrl);
                item.minPrice = Number(item.minPrice);
李嘉林 committed
581
              }
李嘉林 committed
582
              arr.push(item);
李嘉林 committed
583 584
            });
            this.goodsList = arr;
李嘉林 committed
585
            this.updateGoods = Math.random();
李嘉林 committed
586 587
          }
        }
李嘉林 committed
588
      });
李嘉林 committed
589
    },
李嘉林 committed
590
    // 直播结束数据
李嘉林 committed
591 592 593 594 595 596
    endLived() {
      let query = {
        id: Number(this.liveId)
      };
      live.getLiveStatisticsById(query).then(res => {
        if (res.data.code == 200) {
程智春 committed
597 598 599 600 601
          let result = res.data.data
          result.watchNum = result.watchNum - 0 > 10000 ? ((result.watchNum - 0) / 10000).toFixed(1) + 'w' :  result.watchNum
          result.guestBookNum = result.guestBookNum - 0 > 10000 ? ((result.guestBookNum - 0) / 10000).toFixed(1) + 'w' :  result.guestBookNum
          result.likeNum = result.likeNum - 0 > 10000 ? ((result.likeNum - 0) / 10000).toFixed(1) + 'w' :  result.likeNum
          this.endInfo = result;
李嘉林 committed
602 603
        }
      });
李嘉林 committed
604
    },
李嘉林 committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
    userEntry(type) {
      let query = {
        liveBroadcastId: Number(this.liveId),
        activityType: type
      };
      live.userEntryOrExitsLiveRoom(query).then(res => {});
    },
    toSendMsg(val) {
      live.addGuestbook(val).then(res => {
        if (res.data.code == 200) {
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          });
        }
      });
李嘉林 committed
622
    },
程智春 committed
623
    //服务器时间戳
程智春 committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637
    getServerTimeNow() {
      live.queryServerTimeNow().then(res => {
        if (res.data.code == 200) {

          this.newCommentsTime = res.data.data;
          this.userActivebeginTime = res.data.data;
          console.log("newCommentsTime", this.newCommentsTime);
          // setTimeout(() => {
          this.infoTiming = setInterval(() => {
            this.timingGetInfo(res.data.data);
          }, 2000);
          // }, 2000);
        }
      });
程智春 committed
638
    },
李嘉林 committed
639 640
    error(res) {
      console.log(res, "------------------237");
李嘉林 committed
641
    },
李嘉林 committed
642 643
    changes(res) {
      console.log(res, "---------------241");
李嘉林 committed
644
    }
李嘉林 committed
645 646 647 648
  }
};
</script>

李嘉林 committed
649
<style lang="scss" scoped>
李嘉林 committed
650 651 652
img {
  display: block;
}
李嘉林 committed
653
.flex {
李嘉林 committed
654 655 656 657 658 659 660 661 662
  display: flex;
}
/*清除浮动*/
.clearfix {
  zoom: 1;
}

.clearfix:after {
  clear: both;
李嘉林 committed
663
  content: ".";
李嘉林 committed
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
  display: block;
  width: 0;
  height: 0;
  visibility: hidden;
}
/* 一行否则出现省略号 */
.line-clamp1 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.line-clamp2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 22px;
}

李嘉林 committed
687 688
.lived {
  width: 100vw;
李嘉林 committed
689
  height: 100vh;
李嘉林 committed
690
  position: relative;
李嘉林 committed
691
  overflow: hidden;
李嘉林 committed
692
  .bgImg {
李嘉林 committed
693 694 695 696 697 698
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    z-index: -1;
程智春 committed
699
    
程智春 committed
700
    image {
李嘉林 committed
701 702 703 704 705 706 707
      width: 100%;
      height: 100%;
      object-fit: cover;
      // 亮度
      filter: brightness(0.8);
    }
  }
李嘉林 committed
708
  .liveModel {
李嘉林 committed
709 710 711 712 713 714
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
程智春 committed
715
    background-color: rgba(102,102,102,.38);
李嘉林 committed
716
    .customBack {
李嘉林 committed
717 718
      position: absolute;
      left: 12px;
李嘉林 committed
719
      width: 70%;
李嘉林 committed
720
      z-index: 2;
李嘉林 committed
721
      align-items: center;
李嘉林 committed
722
      .backIcon {
李嘉林 committed
723 724 725 726
        img {
          width: 18px;
          height: 18px;
        }
李嘉林 committed
727
      }
李嘉林 committed
728
      .shopName {
李嘉林 committed
729
        margin-left: 20px;
李嘉林 committed
730
        background: rgba(0, 0, 0, 0.6);
李嘉林 committed
731 732
        border-radius: 30px;
        align-items: center;
程智春 committed
733
        padding: 2px 10px 2px 2px;
李嘉林 committed
734
        .img {
李嘉林 committed
735 736
          width: 30px;
          height: 30px;
李嘉林 committed
737
          border-radius: 50%;
程智春 committed
738
          overflow: hidden; 
李嘉林 committed
739
          img {
李嘉林 committed
740 741 742 743
            width: 100%;
            height: 100%;
          }
        }
李嘉林 committed
744
        .info {
李嘉林 committed
745
          margin: 0 8px;
李嘉林 committed
746 747 748
          color: #fff;
          flex: 1;
          font-size: 14px;
李嘉林 committed
749
          padding: 2px 0;
李嘉林 committed
750
          .num {
李嘉林 committed
751 752
            font-size: 12px;
          }
李嘉林 committed
753
        }
李嘉林 committed
754
        .toShop {
李嘉林 committed
755 756 757 758 759
          background: linear-gradient(
            90deg,
            rgba(255, 135, 125, 1),
            rgba(251, 86, 109, 1)
          );
李嘉林 committed
760
          padding: 0 8px;
李嘉林 committed
761 762 763
          color: #fff;
          font-size: 14px;
          display: inline-block;
李嘉林 committed
764
          border-radius: 10px;
李嘉林 committed
765 766 767
          height: 20px;
          line-height: 20px;
        }
李嘉林 committed
768 769 770
      }
    }
  }
李嘉林 committed
771
  .livePlayer {
李嘉林 committed
772
    position: fixed;
李嘉林 committed
773 774
    top: 0;
    left: 0;
李嘉林 committed
775 776
    bottom: 0;
    right: 0;
李嘉林 committed
777 778 779 780
    width: 100vw;
    height: 100vh;
    z-index: -1;
  }
李嘉林 committed
781
}
程智春 committed
782 783 784 785 786 787 788 789 790 791
.masker{
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  background-color: rgba(102,102,102,0.38);
  z-index: 1;
  pointer-events: none;
}
李嘉林 committed
792
</style>