lbp-bg-music.js
1.66 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
/*
* @Author: ly525
* @Date: 2020-01-03 23:43:34
* @LastEditors : ly525
* @LastEditTime : 2020-01-04 13:27:58
* @FilePath: /luban-h5/front-end/h5/src/components/plugins/lbp-bg-music.js
* @Github: https://github.com/ly525/luban-h5
* @Description: Do not edit
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
*/
import './styles/bg-music.scss'
export default {
name: 'lbp-bg-music',
props: {
disabled: {
type: Boolean,
default: true
},
autoplay: {
type: Boolean,
default: true,
editor: {
type: 'a-switch',
label: '自动播放'
}
},
src: {
type: String,
default: 'http://go.163.com/2018/0209/mengniu/audio/bgm.mp3',
editor: {
type: 'a-input',
label: '音乐URL',
prop: {
type: 'textarea'
}
}
}
},
data: () => ({
isPlaying: true
}),
methods: {
toggle () {
let bgAudio = this.$refs.bgAudio
if (!bgAudio) return
this.isPlaying ? bgAudio.pause() : bgAudio.play()
this.isPlaying = !this.isPlaying
}
},
render () {
const btnStyle = {
'animation-play-state': this.isPlaying ? 'running' : 'paused'
}
return (
<div class="bg-music-wrapper" style="display: block;">
<div class="bg-music-btn rotate" style={btnStyle} onClick={this.toggle} disabled={this.disabled}>
<audio src={this.src} autoplay={this.autoplay} preload loop ref='bgAudio'></audio>
</div>
</div>
)
},
created () {
// 在初始化的时候,autoplay 控制是否播放
// 后面是否播放,由用户的点击行为决定
this.isPlaying = this.autoplay
}
}