|
@@ -1,42 +1,55 @@
|
1
|
1
|
<template>
|
2
|
|
- <div class="musicbox">
|
3
|
|
- <!-- 播放 -->
|
4
|
|
- <div class="play" v-if="audioPlayShow" @click="audioState">
|
5
|
|
- <img src="https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yttj_icon_music_open.png">
|
6
|
|
- </div>
|
7
|
|
- <!-- 暂停-->
|
8
|
|
- <div class="play" v-else @click="audioState">
|
9
|
|
- <img src="https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yttj_icon_music_close.png" >
|
10
|
|
- </div>
|
11
|
|
- <audio ref="player" :src="url" autoplay preload loop="loop"></audio>
|
|
2
|
+ <div class="musicbox" @click="troggle">
|
|
3
|
+ <img :class="playing" :src="icons[theme][playing]" alt="">
|
|
4
|
+ <audio ref="player" :src="url" preload loop="loop"></audio>
|
12
|
5
|
</div>
|
13
|
6
|
</template>
|
14
|
7
|
<script>
|
15
|
|
-// import { createNamespacedHelpers } from 'vuex'
|
16
|
|
-// const {
|
17
|
|
-// mapState: mapactivityState,
|
18
|
|
-// } = createNamespacedHelpers("vote");
|
19
|
8
|
export default {
|
20
|
9
|
name:'music',
|
21
|
|
- props:['url'],
|
|
10
|
+ props: {
|
|
11
|
+ url: String,
|
|
12
|
+ theme: String
|
|
13
|
+ },
|
22
|
14
|
data() {
|
23
|
15
|
return {
|
24
|
|
- yttjmusicopen:'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yttj_icon_music_open.png',
|
25
|
|
- yjsmusicopen:'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yinyueon.png',
|
26
|
|
- yttjmusicoff:'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yttj_icon_music_close.png',
|
27
|
|
- yjsmusicoff:'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yinyueoff.png',
|
28
|
|
- audioPlayShow: true,
|
|
16
|
+ playing: 'off',
|
|
17
|
+
|
|
18
|
+ icons: {
|
|
19
|
+ '1': {
|
|
20
|
+ 'on': 'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yttj_icon_music_open.png',
|
|
21
|
+ 'off': 'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yttj_icon_music_close.png',
|
|
22
|
+ },
|
|
23
|
+ '2': {
|
|
24
|
+ 'on': 'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yinyueon.png',
|
|
25
|
+ 'off': 'https://spaceofcheng.oss-cn-beijing.aliyuncs.com/voting/yinyueoff.png',
|
|
26
|
+ },
|
|
27
|
+ }
|
29
|
28
|
};
|
30
|
29
|
},
|
|
30
|
+ watch: {
|
|
31
|
+ url: function(n) {
|
|
32
|
+ if (this.playing === 'off' && n) {
|
|
33
|
+ window.setTimeout(this.play, 1000)
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+ },
|
31
|
37
|
methods: {
|
32
|
|
- // 点击播放暂停按钮时间
|
33
|
|
- audioState() {
|
34
|
|
- this.audioPlayShow = !this.audioPlayShow; // 更改播放暂停按钮状态
|
35
|
|
- const music = this.$refs.player; // 音频所在对象
|
36
|
|
- if (this.audioPlayShow) {
|
37
|
|
- music.play(); // 播放音乐
|
|
38
|
+ play() {
|
|
39
|
+ if (this.url) {
|
|
40
|
+ this.$refs.player.play()
|
|
41
|
+ this.playing = 'on'
|
|
42
|
+ }
|
|
43
|
+ },
|
|
44
|
+ stop() {
|
|
45
|
+ this.$refs.player.pause()
|
|
46
|
+ this.playing = 'off'
|
|
47
|
+ },
|
|
48
|
+ troggle() {
|
|
49
|
+ if (this.playing === 'on') {
|
|
50
|
+ this.stop()
|
38
|
51
|
} else {
|
39
|
|
- music.pause(); // 暂停音乐
|
|
52
|
+ this.play()
|
40
|
53
|
}
|
41
|
54
|
}
|
42
|
55
|
}
|
|
@@ -44,33 +57,35 @@ export default {
|
44
|
57
|
</script>
|
45
|
58
|
|
46
|
59
|
<style lang="scss" scoped>
|
47
|
|
-// @keyframes changDeg{
|
48
|
|
-// 0%{
|
49
|
|
-// transform: rotate(0deg);
|
50
|
|
-// }
|
51
|
|
-// 100%{
|
52
|
|
-// transform: rotate(360deg);
|
53
|
|
-// }
|
54
|
|
-// }
|
|
60
|
+ @keyframes rotate{
|
|
61
|
+ 0%{
|
|
62
|
+ transform: rotate(0deg);
|
|
63
|
+ }
|
|
64
|
+ 100%{
|
|
65
|
+ transform: rotate(360deg);
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+
|
55
|
69
|
.musicbox {
|
56
|
70
|
position: fixed;
|
57
|
71
|
top: 0.09rem;
|
58
|
72
|
right: 0.09rem;
|
59
|
|
- width: 0.5rem;
|
60
|
|
- height: 0.5rem;
|
|
73
|
+ width: 0.35rem;
|
|
74
|
+ height: 0.35rem;
|
61
|
75
|
border-radius: 50%;
|
62
|
76
|
z-index: 10;
|
63
|
77
|
|
64
|
|
- .play {
|
|
78
|
+ .on {
|
|
79
|
+ animation: rotate 3s linear infinite;
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ img {
|
65
|
83
|
width: 100%;
|
66
|
84
|
height: 100%;
|
67
|
|
-
|
68
|
|
- img {
|
69
|
|
- width: 100%;
|
70
|
|
- height: 100%;
|
71
|
|
- }
|
72
|
85
|
}
|
73
|
86
|
}
|
|
87
|
+
|
|
88
|
+
|
74
|
89
|
</style>
|
75
|
90
|
|
76
|
91
|
|