live-header.vue
4.58 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
<div class="header-container">
<div v-show="showLiveInfo">
<div class="anchor-info">
<img class="anchor-avatar" :src="avatar">
<div class="anchor-other">
<p class="anchor-nick">{{nick}}</p>
<p class="online-num">在线:{{onlineMemberCount}}</p>
</div>
</div>
<div class="online-info">
<p class="room-name">直播中</p>
<img class="living-icon" src="../../../assets/image/living-icon.gif" />
<span>{{` ${pusherTime}`}}</span>
</div>
</div>
<div class="close-box" @click="closeLiveMask">
<i class="el-icon-circle-close"></i>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'liveHeader',
props: {
fr: {
type: String,
requred: true
},
isPushingStream: {
type: Boolean,
default: false
},
stopPushStream: {
type: Function
},
pusherTime: {
type: String,
default: ''
}
},
data() {
return {
nick: '',
avatar: 'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-2.png',
onlineMemberCount: 0,
timer: null,
onlineList: []
}
},
computed: {
...mapState({
groupLiveInfo: state => state.groupLive.groupLiveInfo
}),
showLiveInfo() {
return (this.fr === 'pusher' && this.isPushingStream) || this.fr === 'player'
},
roomName() {
return this.groupLiveInfo.roomName || `${this.groupLiveInfo.anchorID}的直播`
}
},
mounted() {
this.getAnchorProfile()
if (this.fr === 'player') {
this.timer = setInterval(() => {
this.getGroupOnlineMemberCount()
}, 5000)
}
},
beforeDestroy() {
this.timer && clearInterval(this.timer)
},
methods: {
closeLiveMask() {
if (this.fr === 'pusher') {
this.stopPushStream()
return
}
this.$store.commit('updateGroupLiveInfo', { isNeededQuitRoom: 1 })
this.$bus.$emit('close-group-live')
},
async getAnchorProfile() {
const res = await this.tim.getUserProfile({userIDList: [this.groupLiveInfo.anchorID]})
if (res.code === 0) {
this.nick = res.data[0].nick || res.data[0].userID
this.avatar = res.data[0].avatar || 'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-2.png'
}
},
async getGroupOnlineMemberCount() {
const res = await this.tim.getGroupOnlineMemberCount(this.groupLiveInfo.roomID)
if (res.code === 0 && res.data) {
this.onlineMemberCount = res.data.memberCount
}
}
},
watch: {
isPushingStream: function(val) {
if (val && this.fr === 'pusher') {
this.timer = setInterval(() => {
this.getGroupOnlineMemberCount()
}, 5000)
}
}
}
}
</script>
<style lang="stylus" scoped>
.header-container {
position absolute
left 0
top 0
width 100%
height 100%
box-sizing border-box
z-index 99
padding 10px 10px 10px 20px
.anchor-info {
position absolute
top 50%
transform translateY(-50%)
width 200px
height 50px
background rgba(255, 255 ,255 ,0.1)
border-radius 30px
display flex
align-items center
.anchor-avatar {
width 50px
height 50px
border-radius 50%
margin 0 5px
}
.anchor-other {
height 100%
flex 1
p {
margin 0
}
.anchor-nick{
max-width 140px
margin 6px 0 0 0
color: #ffffff
font-weight 500
word-break keep-all
overflow hidden
text-overflow ellipsis
white-space nowrap
}
.online-num{
font-size 14px
font-weight 400
color #d2cbcbad
}
}
}
.online-info {
position absolute
left 50%
top 50%
transform translate(-50%, -50%)
height 50px
color #fff
display flex
align-items center
.room-name{
display inline-block
max-width 160px
overflow hidden
white-space nowrap
text-overflow ellipsis
margin 0
padding 0 0 0 10px
}
.living-icon{
position relative
top -3px
margin 0 5px
width 25px
}
span {
margin 2px 0 0 0
}
}
.close-box {
position absolute
right 0
top 0px
width 70px
height 70px
color: #959798
font-size 36px
cursor pointer
display flex
align-items center
justify-content center
}
}
</style>