hookehuyr

植被介绍页新增音乐播放功能

1 <!-- 1 <!--
2 * @Date: 2024-04-10 16:08:09 2 * @Date: 2024-04-10 16:08:09
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-04-14 17:29:50 4 + * @LastEditTime: 2024-04-14 21:42:38
5 * @FilePath: /fxPark/src/views/fxPark/intro.vue 5 * @FilePath: /fxPark/src/views/fxPark/intro.vue
6 * @Description: 植被介绍页 6 * @Description: 植被介绍页
7 --> 7 -->
8 <template> 8 <template>
9 <div class="intro-page"> 9 <div class="intro-page">
10 + <div @click="handleAudio" style="width: 3rem; height: 3rem; border-radius: 50%; position: absolute; right: 10px; top: 10px;">
11 + <img :class="[audioStatus === 'play' ? 'play' : 'pause']" src="https://picsum.photos/50/50" style="width: 3rem; height: 3rem; border-radius: 50%;">
12 + </div>
13 + <audio ref="audioPlayer" loop="loop" id="audios" :src="audio_list[audioIndex]?.audio_url" preload></audio>
10 <div> 14 <div>
11 <img :src="INTRO_IMG[revision]" style="width: 100%; pointer-events:none;"> 15 <img :src="INTRO_IMG[revision]" style="width: 100%; pointer-events:none;">
12 </div> 16 </div>
17 + <div style="margin: 1rem 1rem 2rem 1rem; color: white; text-align: center; position: absolute;bottom: 1rem; left: 0; right: 0;">
18 + <div @click="goToPoster" style="background-color: #F68015; display: inline-block; padding: 0.7rem 2rem; border-radius: 1.5rem;">完成“碳寻”任务</div>
19 + </div>
13 <!-- <div style="margin: 1rem;"> 20 <!-- <div style="margin: 1rem;">
14 <div style="margin-bottom: 1rem;"> 21 <div style="margin-bottom: 1rem;">
15 <span style="font-size: 1.25rem;">{{ tree_data?.name }}</span> 22 <span style="font-size: 1.25rem;">{{ tree_data?.name }}</span>
...@@ -67,9 +74,32 @@ const INTRO_IMG = { // 植被介绍七牛图片地址映射 ...@@ -67,9 +74,32 @@ const INTRO_IMG = { // 植被介绍七牛图片地址映射
67 '6': 'https://cdn.ipadbiz.cn/xfPark/intro/intro-1.1713086546.jpg', 74 '6': 'https://cdn.ipadbiz.cn/xfPark/intro/intro-1.1713086546.jpg',
68 } 75 }
69 76
77 +const audioPlayer = ref(null);
78 +const audioStatus = ref('play');
79 +const audio_list = ref([]);
80 +const audioIndex = ref(+revision);
81 +
82 +const handelPlay = () => {
83 + audioPlayer.value.play();
84 + audioStatus.value = 'play';
85 +};
86 +
87 +const handlePause = () => {
88 + audioPlayer.value.pause();
89 + audioStatus.value = 'pause';
90 +};
91 +
92 +const handleAudio = () => {
93 + if (audioStatus.value === 'play') {
94 + handlePause();
95 + } else {
96 + handelPlay();
97 + }
98 +};
99 +
70 onMounted(async () => { 100 onMounted(async () => {
71 - // const { code, data } = await getTreeAPI(); 101 + const { code, data } = await getTreeAPI();
72 - // if (code) { 102 + if (code) {
73 // let index = data.findIndex(item => item.revision == revision); // 植被信息index 103 // let index = data.findIndex(item => item.revision == revision); // 植被信息index
74 // tree_data.value = data[index]; // 当前植被信息 104 // tree_data.value = data[index]; // 当前植被信息
75 // // 植被介绍样式 105 // // 植被介绍样式
...@@ -79,7 +109,26 @@ onMounted(async () => { ...@@ -79,7 +109,26 @@ onMounted(async () => {
79 // 'marginBottom': '0.5rem' 109 // 'marginBottom': '0.5rem'
80 // }); 110 // });
81 // }) 111 // })
82 - // } 112 + data.forEach(item => {
113 + if (item.is_tree === 1) {
114 + // audio_list.value.push({
115 + // audio_url: item.audio_url,
116 + // audio_cover: item.audio_cover,
117 + // audio_name: item.audio_name,
118 + // audio_note: item.audio_note,
119 + // });
120 + audio_list.value.push({
121 + audio_url: 'http://downsc.chinaz.net/files/download/sound1/201206/1638.mp3',
122 + audio_cover: 'https://picsum.photos/50/50',
123 + audio_name: item.name + '123456789',
124 + audio_note: item.audio_note,
125 + });
126 + }
127 + });
128 + nextTick(() => {
129 + handelPlay();
130 + })
131 + }
83 // 进入页面激活 132 // 进入页面激活
84 const activeTree = await activeTreeAPI({ tree_revision: revision }); 133 const activeTree = await activeTreeAPI({ tree_revision: revision });
85 // 埋点 134 // 埋点
...@@ -103,10 +152,12 @@ const goToPoster = () => { // 去海报页 ...@@ -103,10 +152,12 @@ const goToPoster = () => { // 去海报页
103 }); 152 });
104 }; 153 };
105 154
155 +
106 </script> 156 </script>
107 157
108 <style lang="less" scoped> 158 <style lang="less" scoped>
109 .intro-page { 159 .intro-page {
160 + position: relative;
110 display: flex; 161 display: flex;
111 flex-direction: column; 162 flex-direction: column;
112 .task-tips { 163 .task-tips {
...@@ -148,5 +199,20 @@ const goToPoster = () => { // 去海报页 ...@@ -148,5 +199,20 @@ const goToPoster = () => { // 去海报页
148 1px 1px 0 #000; 199 1px 1px 0 #000;
149 margin: 1rem 0; 200 margin: 1rem 0;
150 } 201 }
202 +
203 + .play {
204 + animation: rotate 8s linear infinite;
205 + }
206 + .pause {
207 + }
208 +
209 + @keyframes rotate {
210 + 0% {
211 + transform: rotate(0deg);
212 + }
213 + 100% {
214 + transform: rotate(360deg);
215 + }
216 + }
151 } 217 }
152 </style> 218 </style>
......