|
|
@@ -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" />
|