liveBox.vue
12.3 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<template>
<view class="live-box">
<view class="live-ongoing" v-if="liveData.liveStatus === 101" @click="toLive">
<image class="cover-img" :src="liveData.feedsImg" />
<view class="status">
<view class="status-state">
<image class="img" src="https://jy.scjysm.asia:18086/cdwlMall/questionnaire/file/static/img//live/icon-live-num.png" />直播中
</view>
<!-- <view class="status-num">1000人</view> -->
</view>
<view class="user">
<view class="user-pic">
<image class="img" :src="liveData.anchorHeadImg" />
</view>
<view class="user-name">{{ liveData.anchorNickName }}</view>
</view>
<view class="products">
<view class="uni-padding-wrap">
<view class="page-section swiper">
<view class="page-section-spacing">
<swiper class="swiper"
:indicator-dots="indicatorDots"
:autoplay="autoplay"
:interval="interval"
:duration="duration"
:vertical="true"
>
<swiper-item
v-for="item in liveData.goods"
:key="item.goods_id"
>
<view class="swiper-item">{{ item.name }}</view>
</swiper-item>
</swiper>
</view>
</view>
</view>
</view>
</view>
<view class="live-other" v-else @click="toLive">
<image class="cover-img" :src="liveData.feedsImg" />
<div class="filter-box-warp">
<div class="filter-box">
<image class="cover-img" :src="liveData.feedsImg" />
</div>
</div>
<view class="user">
<view class="user-pic"><image class="img" :src="liveData.anchorHeadImg" /></view>
<view class="user-name">{{ liveData.anchorNickName }}</view>
</view>
<view class="count-down" v-if="liveStatus === 102">
<image v-if="isLate" class="img" src="../../../static/images/live/live-late.png"/>
<view class="text">{{ liveTimeTitle }}</view>
<view v-if="!isLate" class="time">
<view class="time-item">{{times[0]}}</view>
<view class="dot">:</view>
<view class="time-item">{{times[1]}}</view>
<view class="dot">:</view>
<view class="time-item">{{times[2]}}</view>
</view>
</view>
<!-- #ifdef MP-WEIXIN -->
<view
v-if="liveStatus === 102 && !isLate"
class="btn-subscribe"
:class="{subscribed : subscribeLive === '已预约'}"
@click.stop="onSubscribe"
>{{ subscribeLive }}</view>
<!-- #endif -->
<view class="endContainer" v-if="liveStatus === 103">
<view class="endBox">
<view></view>
<view></view>
<view></view>
<view></view>
</view>
<view>直播已结束</view>
</view>
</view>
</view>
</template>
<script>
const NET = require('@/utils/request')
const API = require('@/config/api')
import { startLiveTemplate } from '@/config/subscribe.js'
import { liveAppid } from '@/config/live.js'
// #ifdef MP-WEIXIN
const livePlayer = requirePlugin('live-player-plugin')
// #endif
export default {
props: {
liveData: {
type: Object,
default: () => ({
roomId: 0,
anchorNickName: '',
feedsImg: '' // 官方收录封面
})
}
},
data () {
return {
background: ['color1', 'color2', 'color3'],
indicatorDots: false,
autoplay: true,
interval: 2000, // 自动播放间隔时长
duration: 500, // 幻灯片切换时长(ms)
d: 0,
m: 0,
s: 0,
times: ['00', '00', '00'],
liveStatus: 100,
liveTimeTitle: '开播倒计时',
subscribeLive: '立即预约',
timer: null,
isLate: false,
}
},
created() {
this.liveStatus = this.liveData.liveStatus
this.subscribeLive = this.liveData.subscribeStatus === 0 ? '立即预约' : '已预约'
this.getStatus()
this.countTime()
// this.getSubscribeStatus()
},
destroyed() {
clearTimeout(this.timer)
},
methods: {
getStatus() {
if (!this.liveData.roomId) { return }
let _this = this
// #ifdef MP-WEIXIN
livePlayer.getLiveStatus({ room_id: this.liveData.roomId })
.then(res => {
// 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期
// _this.liveData.liveStatus = res.liveStatus
_this.liveStatus = res.liveStatus
})
.catch(err => {
console.log('get live status', err)
})
this.timer = setInterval(() => {
livePlayer.getLiveStatus({ room_id: this.liveData.roomId })
.then(res => {
// 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期
_this.liveStatus = res.liveStatus
this.countTime()
console.log('get live status', res.liveStatus)
})
.catch(err => {
console.log('get live status', err)
})
}, 60000)
// #endif
},
changeIndicatorDots(e) {
this.indicatorDots = !this.indicatorDots
},
changeAutoplay(e) {
this.autoplay = !this.autoplay
},
intervalChange(e) {
this.interval = e.target.value
},
durationChange(e) {
this.duration = e.target.value
},
countTime(){
const nowtime = new Date().getTime() //获取当前时间
const starttime = new Date(this.liveData.startTime).getTime()
if(this.liveStatus === 102){
if(starttime > nowtime){
var lefttime = starttime - nowtime //距离结束时间的毫秒数
var leftd = Math.floor(lefttime/(1000*60*60)), //计算小时数
leftm = Math.floor(lefttime/(1000*60)%60), //计算分钟数
lefts = Math.floor(lefttime/1000%60); //计算秒数
this.times = [leftd < 10?'0'+ leftd:leftd,leftm < 10?'0'+ leftm:leftm,lefts < 10?'0'+ lefts:lefts]
this.liveTimeTitle = '开播倒计时'
setTimeout(() => {
this.countTime()
},1000)
} else {
this.times = ['00', '00', '00']
this.isLate = true
this.liveTimeTitle = '正在赶来的路上...'
}
}
},
toLive() {
if (!liveAppid || !this.liveData) { return }
// 跳转直播间携带路由参数
// let customParams = encodeURIComponent(JSON.stringify({ path: 'livePage/index', pid: 1 }))
// #ifdef MP-WEIXIN
wx.navigateTo({
url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}`
// url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}&custom_params=${customParams}`
})
// #endif
},
onSubscribe() {
if (this.subscribeLive === '立即预约') {
const _this = this
// #ifdef MP-WEIXIN
uni.requestSubscribeMessage({
tmplIds: [startLiveTemplate],
success (res) {
if (res[startLiveTemplate] === "accept") {
NET.request(API.SubScribeLive, {id: _this.liveData.id }, 'post')
.then(res => {
if (res.data) {
_this.subscribeLive = '已预约'
} else {
uni.showToast({
title: res.message || '订阅失败,请稍后再试!',
icon: "none"
})
}
})
.catch(err => {
console.log(err)
uni.showToast({
title: res.message || '订阅失败,请稍后再试!',
icon: "none"
})
})
}
}
})
// #endif
}
}
}
}
</script>
<style lang="scss" scoped>
.live-box{
position: relative;
color: #fff;
width: 100%;
height: 100%;
.cover-img{
width: 100%;
height: 100%;
position: absolute;
z-index: 0;
}
.user{
display: flex;
line-height: 60rpx;
height: 64rpx;
&-pic{
.img{
width: 60rpx;
height: 60rpx;
border: 2px solid rgba(255, 255, 255, 0.5019607843137255);
border-radius: 50%;
overflow: hidden;
}
}
&-name{
font-size: 28rpx;
margin-left: 16rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 245rpx;
}
}
.live-ongoing{
width: 100%;
height: 100%;
position: relative;
.status{
position: absolute;
top: 22rpx;
left: 22rpx;
//width: 212upx;
height: 48rpx;
// background: rgba(0,0,0,0.3);
// border: 2rpx solid rgba(255,255,255,0.3);
border-radius: 24rpx;
font-size: 20rpx;
line-height: 44rpx;
display: flex;
// padding-right: 8rpx;
&-state{
width: 118rpx;
height: 44rpx;
background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
opacity: 1;
border-radius: 26rpx;
display: flex;
align-items: center;
justify-content: center;
.img{
width: 20rpx;
height: 20rpx;
margin-right: 6rpx;
}
}
&-num{
min-width: 80rpx;
padding: 0 8rpx;
}
}
.user{
position: absolute;
bottom: 62rpx;
left: 20rpx;
}
.products{
position: absolute;
left: 0rpx;
bottom: 20rpx;
width: 100%;
padding:0 20rpx;
.swiper{
height: 34rpx;
line-height: 34rpx;
font-size: 24rpx;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
}
}
.live-other{
position: relative;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
.filter-box-warp{
background-color: #000000;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
.filter-box{
position: absolute;
top: -30rpx;
left: -30rpx;
width: 348rpx;
height: 464rpx;
display: flex;
align-items: center;
justify-content: center;
-webkit-filter: blur(20px);
-moz-filter: blur(21px);
-ms-filter: blur(20px);
-o-filter: blur(20px);
padding: 30rpx;
box-sizing: content-box;
}
}
.user{
position: absolute;
top: 20rpx;
left: 20rpx;
}
.count-down{
position: relative;
.text{
font-size: 26rpx;
line-height: 36rpx;
margin-bottom: 16rpx;
opacity: 0.5;
text-align: center;
}
.img{
display: block;
width: 80rpx;
height: 80rpx;
margin: 16rpx auto;
}
.time{
display: flex;
justify-content: space-around;
align-items: center;
&-item{
min-width: 52rpx;
padding: 0 5rpx;
height: 52rpx;
line-height: 52rpx;
background: #FFFFFF;
opacity: 1;
border-radius: 6rpx;
font-size: 26rpx;
color: #C83732;
text-align: center;
.dot{
line-height: 52rpx;
}
}
}
}
.btn-subscribe{
width: 200rpx;
height: 64rpx;
line-height: 64rpx;
background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
box-shadow: 0rpx 6rpx 12rpx rgba(233, 0, 0, 0.3);
opacity: 1;
border-radius: 6rpx;
color: #fff;
font-size: 24rpx;
text-align: center;
position: absolute;
bottom: 60rpx;
left: 50%;
margin-left: -100rpx;
&.subscribed{
background: #FFFFFF;
color: #999999;
box-shadow: none;
}
}
.endContainer{
position: relative;
.endBox{
width: 40%;
height: 60rpx;
margin: 20rpx auto;
display: flex;
justify-content: space-between;
align-items: flex-end;
view{
width: 0;
border: 2rpx solid #FFF;
}
view:nth-of-type(1){
height: 20%;
}
view:nth-of-type(2){
height: 50%;
}
view:nth-of-type(3){
height: 30%;
}
view:nth-of-type(4){
height: 70%;
}
}
}
}
}
</style>