message-group-live-status.vue
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<template>
<div class="group-live-custom-message-card" @click="handleClick">
<p class="card-title">{{cardTitle}}</p>
<p class="card-content">{{cardContent}}</p>
<div class="card-footer">
<img class="avatar" :src="roomCover" alt="">
<span>群直播</span>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import axios from 'axios'
export default {
name: 'MessageGroupLiveStatus',
props: {
liveInfo: {
type: Object,
required: true
}
},
computed: {
...mapState({
userID: state => state.user.userID
}),
cardTitle() {
return `${this.liveInfo.anchorName || this.liveInfo.anchorId}的直播`
},
cardContent() {
return Number(this.liveInfo.roomStatus) === 1 ? '正在直播' : '结束直播'
},
roomCover() {
return this.liveInfo.roomCover || 'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-2.png'
}
},
methods: {
async handleClick() {
const isExisting = await this.checkRoomExist()
const { roomId: roomID, anchorId: anchorID, roomName } = this.liveInfo
if (!isExisting) {
this.$store.commit('showMessage', {
message: '直播已结束',
type: 'info'
})
return
}
// 主播多实例登录时,点击卡片直接返回
if (anchorID === this.userID) {
this.$store.commit('showMessage', {
message: '您正在其它终端或者Web实例上开播,请勿重复开播!',
type: 'info'
})
return
}
this.$store.commit('updateGroupLiveInfo', {
groupID: this.toAccount,
roomID: roomID,
anchorID: anchorID,
roomName: roomName,
})
this.$bus.$emit('open-group-live', { channel: 3 })
},
// 检查房间是否存在
async checkRoomExist() {
const checkRes = await axios ('https://service-c2zjvuxa-1252463788.gz.apigw.tencentcs.com/release/forTest?method=getRoomList&appId=1400187352&type=groupLive')
const list = (checkRes.data && checkRes.data.data) || []
const roomIDList = []
list.forEach(item => {
roomIDList.push(item.roomId)
})
return roomIDList.includes(this.liveInfo.roomId)
}
}
}
</script>
<style lang="stylus" scoped>
.group-live-custom-message-card {
min-width: 160px;
max-width: 220px;
height 100px;
padding: 10px;
background-color: #fff;
color: #000;
cursor: pointer;
overflow: hidden;
text-overflow: ellipsis;
// white-space: nowrap;
.card-title {
font-weight: 500;
margin: 0;
}
.card-content {
margin-bottom: 5px;
font-weight: 400;
border-bottom: 1px solid #e6e6e6;
}
.card-footer {
display: flex;
align-items: center;
color: #8e8b8b;
font-weight: 400;
font-size: 13px;
.avatar {
width: 28px;
height: 28px;
border-radius: 50%;
margin-right: 5px;
}
}
}
</style>