wws 2 rokov pred
rodič
commit
6d3e0832b6

+ 85 - 3
src/components/live-footer/LiveFooter.vue

@@ -1,5 +1,6 @@
 <script>
 import LiveInput from "@/components/live-input/LiveInput.vue";
+import {ChatEvents} from "@polyv/live-watch-sdk";
 
 export default {
   name: "LiveFooter",
@@ -9,13 +10,92 @@ export default {
     isFullScreen: {
       type: Boolean,
       default: false,
+    },
+
+    watchCore: {
+      type: Object,
+      default: () => ({})
+    },
+
+    // 待发送点赞数
+    waitSendLikes: {
+      type: Number,
+      default: 0
+    }
+  },
+  data() {
+    return {
+      // 当前点赞数
+      currentRealtimeLikes: 0,
+      timer: null,
+
+      // 是否自己已点赞
+      isSelf: false,
+    }
+  },
+  watch: {
+    watchCore() {
+      this.getImLikeCount();
+      this.handleSendLike();
+
     }
   },
   methods: {
+    // 获取实时点赞数
+    getImLikeCount() {
+      const realtimeLikes = this.watchCore.chat.getRealtimeLikes();
+      this.currentRealtimeLikes = realtimeLikes;
+
+      this.watchCore.chat.eventEmitter.on(ChatEvents.ChatLikeCountChange, (data) => {
+        this.isSelf = data?.isSelf || false;
+        console.log('daqtqa', data)
+        this.currentRealtimeLikes = data.realtimeLikes;
+      });
+    },
+
+    // 发送点赞
+    handleSendLike() {
+      if(this.timer) {
+        clearInterval(this.timer);
+        this.timer = null;
+      }
+
+      this.timer = setInterval( async() => {
+        // 设置定时器,五秒发送一次
+        if (!this.waitSendLikes) return;
+        try {
+          const realtimeLikes = await this.watchCore.chat.sendLike(this.waitSendLikes);
+          this.currentRealtimeLikes = realtimeLikes;
+        } finally {
+          // 清空待点赞数
+          this.$emit("clearCount", 0)
+        }
+      }, 10000)
+    },
+
     handleShowInput() {
-      console.log("点击了")
       this.$refs.liveInput.show();
     }
+  },
+  computed: {
+    // 格式化点赞数
+    likeCount() {
+      // 过千 以 K 为单位 过万 以 W 为耽误
+      const count = this.currentRealtimeLikes + this.waitSendLikes;
+      if(count > 1000 && count < 10000) {
+        return( count / 1000) + "k"
+      }
+
+      if(count > 10000) {
+        return (count / 10000) + "W"
+      }
+      return count;
+    }
+  },
+  beforeDestroy () {
+    if(this.timer) {
+      clearInterval(this.timer)
+    }
   }
 }
 </script>
@@ -33,8 +113,10 @@ export default {
     </div>
 
     <div class="live-footer-item">
-      <img src="@/assets/like_active.png" class="live-footer-icon" />
-      <span class="live-footer-count">999.9K</span>
+      <img v-if="isSelf" src="@/assets/like_active.png" class="live-footer-icon" />
+      <img v-else src="@/assets/like.png" class="live-footer-icon" />
+
+      <span class="live-footer-count">{{ likeCount }}</span>
     </div>
 
     <live-input ref="liveInput" v-on="$listeners" />

+ 21 - 2
src/components/live/LiveInteract.vue

@@ -37,10 +37,17 @@ export default {
       chatList: [],
       // 公告内容
       noticeContent: null,
+
+
+      // 待发送的点赞数
+      waitSendLikes: 0,
+
+      watchCore: null,
     }
   },
   mounted() {
     this.$nextTick(() => {
+      this.watchCore = this.liveInstance.watchCore;
       this.liveInstance.on("init_live", () => {
         this.liveInstance.getChatContent((list) => {
           this.chatList = list;
@@ -63,10 +70,17 @@ export default {
   methods: {
     // 发送消息
     handleSendMessage(val) {
+      if(!val) return;
       this.liveInstance.sendMessage(val);
       console.log("val", val)
     },
 
+    // 点击swipe-item
+    handleClickSwiperItem() {
+      console.log("hhh")
+      this.waitSendLikes ++;
+    },
+
     // 点击返回
     handleClickBack() {
       // 判断当前状态是否全屏,如果是则退出全屏
@@ -188,12 +202,17 @@ export default {
           <span>退出清屏</span>
         </div>
       </van-swipe-item>
-      <van-swipe-item>
+      <van-swipe-item @click="handleClickSwiperItem">
         <div class="interact-box">
           <live-header @back="handleClickBack" :is-full-screen="isLandscape" :noticeContent="noticeContent" />
           <div class="footer">
             <chat-wrapper :list="chatList" v-show="!isLandscape" />
-            <live-footer :is-full-screen="isLandscape" @send="handleSendMessage" />
+            <live-footer
+                :wait-send-likes="waitSendLikes"
+                @clearCount="waitSendLikes = 0"
+                :watchCore="watchCore"
+                :is-full-screen="isLandscape"
+                @send="handleSendMessage" />
             <div class="shop-and-gift">
               <div class="guide-box">
                 <img src="https://picsum.photos/200" class="guide-cover" />

+ 18 - 0
src/utils/Live.js

@@ -35,6 +35,8 @@ export default class Live {
             this.emit("init_live", this.watchCore);
 
             this.getNotice();
+
+            this.getCard();
         } catch (err) {
             console.error(err);
         }
@@ -102,6 +104,22 @@ export default class Live {
         });
     }
 
+    // todo 需要找到管理端怎么发送卡片
+    // 获取卡片推送
+    getCard() {
+        const pushCardSdk = this.watchCore.interactReceive.getPushCard();
+        pushCardSdk.on(pushCardSdk.events.START, async (msg) => {
+            console.log(`卡片开始推送:`, msg);
+            // const res = await pushCardSdk.getPushCardData(msg.roomId, msg.id);
+        });
+
+    }
+
+
+    getWatchCore() {
+        return this.watchCore;
+    }
+
     on(key, callback) {
         if (!this.callbackMap[key]) {
             this.callbackMap[key] = new Set();