index.vue
3.75 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
<template>
<div class="video-wrapper">
<div class="video-div" :id="'mui-player-' + item.id"></div>
<div class="video-bar">
<van-row style="text-align: center;">
<van-col span="7">
<span style="color: #777777;">
{{ item.play_num }}次播放
</span>
</van-col>
<van-col span="1" style="color: #EEEDED;">
|
</van-col>
<van-col span="8">
<span @click="handleAction('favor', detail.id)">
<van-icon v-if="!detail.is_favor" :name="icon_shoucang1" size="1.2rem" style="vertical-align: bottom;" />
<van-icon v-else :name="icon_shoucang2" size="1.2rem" style="vertical-align: bottom;" />
{{ detail.favor_num }}
</span>
</van-col>
<van-col span="1" style="color: #EEEDED;">
|
</van-col>
<van-col span="7">
<span @click="handleAction('like', detail.id)">
<van-icon v-if="!detail.is_like" :name="icon_dianzan1" size="1.2rem" style="vertical-align: bottom;" />
<van-icon v-else :name="icon_dianzan2" size="1.2rem" style="vertical-align: bottom;" />
{{ detail.like_num }}
</span>
</van-col>
</van-row>
</div>
</div>
</template>
<script setup>
/**
* 该组件是放在作品详情页头部
*/
import icon_dianzan1 from '@images/icon-dianzan01@2x.png'
import icon_dianzan2 from '@images/icon-dianzan02@2x.png'
import icon_shoucang1 from '@images/icon-shoucang01@2x.png'
import icon_shoucang2 from '@images/icon-shoucang02@2x.png'
import 'mui-player/dist/mui-player.min.css'
import MuiPlayer from 'mui-player'
import _ from 'lodash';
import { DEFAULT_COVER } from '@/constant'
</script>
<script>
// FIXME: VUE2写法
import mixin from 'common/mixin';
export default {
mixins: [mixin.likeFn],
props: ['item'],
data() {
return {
detail: {
mp: ''
},
initTimer: null,
mp: null
}
},
created() {
},
mounted() {
this.initPlayer();
// 配置16:9高度比
const width = document.getElementById('mui-player-' + this.item.id).clientWidth;
const height = (width * 9) / 16;
document.getElementById('mui-player-' + this.item.id).height = height;
},
beforeUnmount() {
if (this.initTimer) {
clearTimeout(this.initTimer);
this.initTimer = null;
}
if (this.mp && typeof this.mp.destroy === 'function') {
this.mp.destroy();
}
},
methods: {
initPlayer() {
if (!this.item || !this.item.id || !this.item.video) return;
this.initTimer = setTimeout(() => {
var mp = new MuiPlayer({
container: '#mui-player-' + this.item.id,
title: this.item.title,
src: this.item.video,
poster: this.item.cover ? this.item.cover : DEFAULT_COVER,
// poster: DEFAULT_COVER,
autoFit: false,
videoAttribute: [ // 声明启用同层播放, 不让会自动全屏播放
{attrKey:'webkit-playsinline',attrValue:'webkit-playsinline'},
{attrKey:'playsinline',attrValue:'playsinline'},
{attrKey:'x5-video-player-type',attrValue:'h5-page'},
]
})
this.detail = _.cloneDeep(this.item);
// 传回数据
this.$emit('on-click', this.detail);
this.mp = mp;
var video = mp.video();
// 监听原生video事件
var _this = this;
video && video.addEventListener('play', function () {
_this.handleAction('play', _this.item.id)
});
}, 0)
}
}
}
</script>
<style lang="less" scoped>
.video-wrapper {
.video-div {
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.video-bar {
color: #713610;
padding: 1rem;
padding-bottom: 0.5rem;
}
}
</style>