zengh
2022-05-09 52c39f5e2711e5535b689b66dfa5e100c7882b7f
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<template>
    <div class="page">
        <div class="cover-view-center" v-if="distanceX==0">
            <div :style="{ height: `${sysheight-60}px`,width: width }" ref="touch" @click="clickVideo(index)"
                @touchstart="ListTouchStart" @touchmove="ListTouchMove">
                <div class="cover-view-right" v-if="distanceX==0">
                    <image class="img" @click.stop="tapAvater"></image>
                    <text class="right-text"> </text>
                    <image class="img" @click.stop="tapLove"></image>
                    <text class="right-text"> </text>
                    <image class="img" @click.stop="tapMsg"></image>
                    <text class="right-text"> </text>
                    <image class="img" @click.stop="tapCollect"></image>
                    <text class="right-text"> </text>
                    <image class="img" @click.stop="tapShare"></image>
                    <text class="right-text"> </text>
                </div>
            </div>
        </div>
        <div class="swiper" ref="swiper">
            <block v-for="(item, idx) in videoList" :key="idx">
                <div class="video-box" :style="{ height: height }">
                    <!-- 视频渲染数预加载数影响性能 -->
                    <block v-if="Math.abs(index-idx)<=1">
                        <chunlei-video class="video" :src="item.src" :height="height" :width="width" :play="item.flag"
                            :gDuration="item.duration" :objectFit="item.objectFit" :initialTime="item.initialTime"
                            @pause="pauseVideo" :rotateImg="`//static/avatar.png`" :danmuList="danmuList">
                        </chunlei-video>
                        <cover-view class="cover-view-left">
                            <text class="left-text">@{{item.at}}</text>
                            <text class="left-text">{{item.content}}</text>
                        </cover-view>
                        <cover-view class="cover-view-right">
                            <cover-image :src="item.avater" class="avater img" @click.stop="tapAvater"></cover-image>
                            <text class="right-text-avater">+</text>
                            <text class="right-text"></text>
                            <cover-image :src="item.check?'../../static/aixinRed.png':'../../static/aixin.png'"
                                class="img" @click.stop="tapLove"></cover-image>
                            <text class="right-text">{{item.like}}</text>
                            <cover-image src="../../static/xiaoxi.png" class="img" @click.stop="tapMsg"></cover-image>
                            <text class="right-text">{{item.comment}}</text>
                            <cover-image :src="item.iscollect?'../../static/collectred.png':'../../static/collect.png'"
                                class="img" @click.stop="tapCollect"></cover-image>
                            <text class="right-text">{{item.collect}}</text>
                            <cover-image src="../../static/share-fill.png" class="img" @click.stop="tapShare">
                            </cover-image>
                            <text class="right-text">分享</text>
                        </cover-view>
 
                    </block>
                </div>
 
            </block>
        </div>
 
        <div class="left-div" :style="{ height: height,width: width,left:`${-parseInt(width)}px` }" ref="left"
            @touchstart="ListTouchStart" @touchmove="ListTouchMove">
            <text class="title-text" @click="clickbt">{{videoList[index].at}}</text>
        </div>
        <div class="right-div" :style="{ height: height,width: width,right:`${-parseInt(width)}px` }" ref="right"
            @touchstart="ListTouchStart" @touchmove="ListTouchMove">
            <text class="title-text">{{videoList[index].content}}</text>
        </div>
 
    </div>
</template>
 
<script>
    import chunleiVideo from '../../components/chunlei-video/chunlei-video';
    import scrollMixins from './scrollMixins';
    const BindingX = uni.requireNativePlugin('bindingx');
    const animation = weex.requireModule('animation');
    const modal = weex.requireModule('modal');
 
    export default {
        mixins: [scrollMixins],
        components: {
            chunleiVideo
        },
        data() {
            return {
                danmuList: [
                    // {
                    //     text: '发条弹幕0',
                    //     color: '#fff',
                    //     time: 2,
                    //     avatar: '../../static/avatar.png'
                    // },
                    // {
                    //     text: '发条弹幕1',
                    //     color: '#fff',
                    //     time: 3,
                    //     avatar: '../../static/avatar.png'
                    // },
                    // {
                    //     text: '发条弹幕2',
                    //     color: '#fff',
                    //     time: 5,
                    //     avatar: '../../static/avatar.png'
                    // },
                    // {
                    //     text: '发条弹幕3',
                    //     color: '#fff',
                    //     time: 6,
                    //     avatar: '../../static/avatar.png'
                    // },
                ],
                videoList: [{
                        src: 'http://baobab.kaiyanapp.com/api/v1/playUrl?vid=164015&resourceType=video&editionType=default&source=aliyun&playUrlType=url_oss',
                        content: '为什么要选择uni-app?',
                        flag: true,
                        check: false,
                        like: '10w',
                        comment: '1045',
                        avater: '../../static/logo.png',
                        initialTime: 20,
                        at: 'Dcloud',
                        duration: 841,
                        objectFit: 'fill'
                    },
                    {
                        src: 'http://baobab.kaiyanapp.com/api/v1/playUrl?vid=129764&resourceType=video&editionType=default&source=aliyun&playUrlType=url_oss',
                        content: '广告有反转:危机感十足!一辆车都比你靠谱',
                        flag: false,
                        check: true,
                        like: '7w',
                        comment: '1045',
                        avater: 'http://img.kaiyanapp.com/e44ed5fcfa424ba35761ce5f1339bc16.jpeg?imageMogr2/quality/60/format/jpg',
                        initialTime: 0,
                        at: '欧美广告精选',
                        duration: 149
                    },
                    {
                        src: 'http://baobab.kaiyanapp.com/api/v1/playUrl?vid=164111&resourceType=video&editionType=default&source=aliyun&playUrlType=url_oss',
                        content: '无辣不欢,你没见过小龙虾的大场面',
                        flag: false,
                        check: false,
                        like: '7w',
                        comment: '1045',
                        avater: 'http://img.kaiyanapp.com/7af2bb1bc134fb1115d48f05e9d317f0.jpeg?imageMogr2/quality/60/format/jpg',
                        initialTime: 0,
                        at: '世界美食荟萃',
                        duration: 1162
                    },
                ]
            }
        },
        created() {
            this.init()
            //隐藏subnvue
            uni.getSubNVueById('comment').hide()
            uni.getSubNVueById('input-box').hide()
        },
        async mounted() {
            //this.videoPlay(this.index)
            // await this.pushVideoList()
            this.$nextTick(() => {
                this.videoPlay(this.index)
            })
        },
        onLoad(e) {
            var that = this;
            var dataForm = JSON.parse((e.detailData));
            that.videoList = []
            //获取新闻数据
            this.rolename = this.$store.state.UserData.role_name;
            this.userid = this.$store.state.UserData.user_id;
            var url = that.$store.state.piAPI + '/article/article/pageLikes';
            if(dataForm.collectTo){
                url = that.$store.state.piAPI + '/article/article/pageCollect';
            }
            
            uni.request({
                url: url,
                method: 'GET',
                data: {
                    rolename: that.rolename, //帐号角色
                    userid: that.userid,
                    current: 1,
                    size: 99999,
                    articleType: "ksp"
                },
                success: (res) => {
                    if (res.data.code == 200) {
                        var data = res.data.data.records;
                        var x = 0;
                        for (var i = 0; i < data.length; i++) {
                            var flag = false;
                            var check = data[i].islikes == "1"?true:false;
                            var like = data[i].count == null?0:Number(data[i].count);
                            var iscollect = data[i].iscollect == "1"?true:false;
                            var collect = data[i].collectcount == null?0:Number(data[i].collectcount);
                            var comment = data[i].comments == null?0:Number(data[i].comments);
                            if (data[i].id == dataForm.id) {
                                x = 1;
                                flag = true;
                            }
                            if (x == 1) {
                                that.videoList.push({
                                    id: data[i].id,
                                    iscomment:data[i].iscomment,
                                    userid: that.userid,
                                    src: data[i].videoUrl,
                                    content: data[i].title,
                                    flag: flag,
                                    check: check,
                                    like: like,
                                    iscollect: iscollect,
                                    collect: collect,
                                    comment: comment,
                                    avater: '../../static/logo.png',
                                    initialTime: 0,
                                    at: data[i].sourceName,
                                    duration: 5,
                                });
                                flag = false;
                            }
                        }
                    }
                }
            });
        },
        onShow() {
            this.videoPlay(this.index)
        },
        onHide() {
            for (let item of this.videoList) {
                item.flag = false
            }
        },
        methods: {
            clickbt() {
                console.log(11)
            },
            //设置参数
            init() {
                this.typeX = true //开启左右滑动
                this.playCount = 2 //剩余多少视频加载视频列表
                this.startDistance = 5 //判断左右上下拖动的启动距离 px
                this.minTime = 300 //判断快速滑动的时间,该时间内无视回弹距离判断
                this.backDistance = 200 //判断上下滑动的回弹距离 px
            },
            // pushVideoList() {
            //     let promise = new Promise((resolve, reject) => {
            //         uni.request({
            //             url: 'https://api.apiopen.top/videoRecommend?id=127397',
            //             success: (res) => {
            //                 let videoGroup = []
            //                 for (let item of res.data.result) {
            //                     if (item.type == 'videoSmallCard') {
            //                         videoGroup.push({
            //                             src: item.data.playUrl,
            //                             content: item.data.title,
            //                             flag: false,
            //                             check: false,
            //                             like: '7w',
            //                             comment: '1045',
            //                             at: item.data.author.name,
            //                             avater: item.data.author.icon,
            //                             initialTime: 0,
            //                             duration: item.data.duration
            //                         })
            //                     }
            //                 }
            //                 this.videoList = [...this.videoList, ...videoGroup]
 
            //                 resolve()
            //             }
            //         })
            //     })
            //     return promise
            // },
            tapLove(e) {
                var that = this;
                e.stopPropagation();
                if (this.distanceX != 0) return
                if(this.videoList[this.index].check){
                    this.videoList[this.index].like = this.videoList[this.index].like - 1;
                    uni.request({
                        url: that.$store.state.piAPI + 'likes/likes/removelikes',
                        method: 'POST',
                        data: {
                            likesUser: that.userid,
                            likesArticle: that.videoList[that.index].id
                        },
                        success: (res) => {
                            
                        }
                    });
                    
                }else{
                    this.videoList[this.index].like = this.videoList[this.index].like + 1;
                    uni.request({
                        url: that.$store.state.piAPI + 'likes/likes/submit',
                        method: 'POST',
                        data: {
                            likesUser: that.userid,
                            likesArticle: that.videoList[that.index].id
                        },
                        success: (res) => {
                            
                        }
                    });
                }
                
                this.videoList[this.index].check = !this.videoList[this.index].check
                this.videoList = [...this.videoList]
            },
            tapCollect(e) {
                var that = this;
                e.stopPropagation();
                if (this.distanceX != 0) return
                if(this.videoList[this.index].iscollect){
                    this.videoList[this.index].collect = this.videoList[this.index].collect - 1;
                    uni.request({
                        url: that.$store.state.piAPI + 'collect/collect/removecollect',
                        method: 'POST',
                        data: {
                            collectUser: that.userid,
                            collectArticle: that.videoList[that.index].id
                        },
                        success: (res) => {
                            
                        }
                    });
                    
                }else{
                    this.videoList[this.index].collect = this.videoList[this.index].collect + 1;
                    uni.request({
                        url: that.$store.state.piAPI + 'collect/collect/submit',
                        method: 'POST',
                        data: {
                            collectUser: that.userid,
                            collectArticle: that.videoList[that.index].id
                        },
                        success: (res) => {
                            
                        }
                    });
                }
                
                this.videoList[this.index].iscollect = !this.videoList[this.index].iscollect
                this.videoList = [...this.videoList]
            },
            tapAvater(e) {
                e.stopPropagation();
                if (this.distanceX != 0) return
                uni.showToast({
                    icon: 'none',
                    title: `点击索引为${this.index}的头像`
                })
            },
            tapMsg(e) {
                e.stopPropagation();
                if (this.distanceX != 0) return
                console.log(this.videoList[this.index])
                if(this.videoList[this.index].iscomment == "0" || this.videoList[this.index].iscomment == ""){
                    uni.showToast({
                        icon: 'none',
                        title: `当前视频不支持评论`
                    });
                    return;
                }
                uni.getSubNVueById('comment').show('none', 0, () => {
                    uni.$emit('showComment', this.videoList[this.index])
                });
            },
            tapShare(e) {
                e.stopPropagation();
                if (this.distanceX != 0) return
                uni.showToast({
                    icon: 'none',
                    title: `分享索引为${this.index}的视频`
                })
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    .page {
        flex: 1;
        overflow: hidden;
        position: relative;
    }
 
    .swiper {
        position: relative;
        background-color: #000;
    }
 
    .left-div {
        position: absolute;
        top: 0;
        justify-content: center;
        align-items: center;
    }
 
    .right-div {
        position: absolute;
        top: 0;
        justify-content: center;
        align-items: center;
    }
 
    .title-text {
        font-size: 16px;
        color: #000000;
    }
 
    .video-box {
        position: relative;
        background-color: #000;
    }
 
    .cover-view-center {
 
        position: fixed;
        justify-content: center;
        align-items: center;
 
        z-index: 999;
    }
 
    .cover-view-top {
        position: fixed;
        width: 750rpx;
        height: 150px;
        overflow: hidden;
    }
 
    .cover-view-left {
        position: absolute;
        margin-left: 10upx;
        width: 500upx;
        bottom: 200upx;
        z-index: 9999;
        font-size: 16px;
        color: #FFFFFF;
    }
 
    .left-text {
        font-size: 16px;
        color: #FFFFFF;
        margin-bottom: 20upx;
    }
 
    .avater {
        border-radius: 50upx;
        border-color: #fff;
        border-style: solid;
        border-width: 2px;
    }
 
    .cover-view-right {
        position: absolute;
        top: 400upx;
        right: 20upx;
        z-index: 9999;
    }
 
    .right-text-avater {
        position: absolute;
        font-size: 14px;
        top: 50upx;
        left: 17upx;
        height: 40upx;
        width: 40upx;
        background-color: #DD524D;
        color: #FFFFFF;
        border-radius: 50%;
        text-align: center;
        line-height: 40upx;
        z-index: 999;
    }
 
    .avater-icon {
        height: 40upx;
        width: 40upx;
 
        color: #fff;
        background-color: #DD524D;
        border-radius: 50%;
        position: absolute;
        left: 30upx;
        top: -20upx;
    }
 
    .right-text {
        text-align: center;
        font-size: 14px;
        color: #FFFFFF;
        margin-bottom: 50upx;
        height: 20px;
    }
 
    .img {
        height: 74upx;
        width: 74upx;
        opacity: 0.9;
    }
</style>