hookehuyr

音频页面新增列表测试

1 <!-- 1 <!--
2 * @Date: 2024-04-10 15:08:08 2 * @Date: 2024-04-10 15:08:08
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-04-11 16:56:42 4 + * @LastEditTime: 2024-04-12 13:13:50
5 * @FilePath: /fxPark/src/views/fxPark/audio.vue 5 * @FilePath: /fxPark/src/views/fxPark/audio.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 <div class="audio-page"> 9 <div class="audio-page">
10 - <div class="audio-player"> 10 + <div style="position: absolute; top: 5rem;">
11 - <van-row justify="center" align="center"> 11 + <div class="audio-player">
12 - <van-col span="8"> 12 + <van-row align="center">
13 - <div> 13 + <van-col span="8">
14 - <div style="width: 5rem; height: 5rem; border-radius: 50%;"> 14 + <div>
15 - <img :class="[audioStatus === 'play' ? 'play' : 'pause']" src="https://picsum.photos/50/50" style="width: 5rem; height: 5rem; border-radius: 50%;"> 15 + <div style="width: 5rem; height: 5rem; border-radius: 50%;">
16 + <img :class="[audioStatus === 'play' ? 'play' : 'pause']" src="https://picsum.photos/50/50" style="width: 5rem; height: 5rem; border-radius: 50%;">
17 + </div>
16 </div> 18 </div>
17 - </div> 19 + </van-col>
18 - </van-col> 20 + <van-col span="16">
19 - <van-col span="16"> 21 + <div>
20 - <div> 22 + <div class="van-ellipsis" style="margin-bottom: 1rem; color: #fff;">{{ audio_list[audioIndex]?.audio_name }}</div>
21 - <div class="van-ellipsis" style="margin-bottom: 1rem; color: #fff;">{{ audio_list[audioIndex]['audio_name'] }}</div> 23 + <div style="display: flex; justify-content: space-between;">
22 - <div style="display: flex; justify-content: space-between;"> 24 + <van-icon @click="audioPrev" name="arrow-left" size="1.5rem" />
23 - <van-icon @click="audioPrev" name="arrow-left" size="1.5rem" /> 25 + <van-icon v-if="audioStatus === 'pause'" name="play" size="1.5rem" @click="handelPlay" />
24 - <van-icon v-if="audioStatus === 'pause'" name="play" size="1.5rem" @click="handelPlay" /> 26 + <van-icon v-if="audioStatus === 'play'" name="pause" size="1.5rem" @click="handlePause" />
25 - <van-icon v-if="audioStatus === 'play'" name="pause" size="1.5rem" @click="handlePause" /> 27 + <van-icon @click="audioNext" name="arrow" size="1.5rem" />
26 - <van-icon @click="audioNext" name="arrow" size="1.5rem" /> 28 + </div>
27 </div> 29 </div>
30 + </van-col>
31 + </van-row>
32 + <!-- <div style="margin-right: 1rem; flex: 1;">
33 + <div style="width: 5rem; height: 5rem; border-radius: 50%;">
34 + <img :class="[audioStatus === 'play' ? 'play' : 'pause']" src="https://picsum.photos/50/50" style="width: 5rem; height: 5rem; border-radius: 50%;">
28 </div> 35 </div>
29 - </van-col>
30 - </van-row>
31 - <!-- <div style="margin-right: 1rem; flex: 1;">
32 - <div style="width: 5rem; height: 5rem; border-radius: 50%;">
33 - <img :class="[audioStatus === 'play' ? 'play' : 'pause']" src="https://picsum.photos/50/50" style="width: 5rem; height: 5rem; border-radius: 50%;">
34 </div> 36 </div>
35 - </div> 37 + <div style="flex: 3;">
36 - <div style="flex: 3;"> 38 + <div class="van-ellipsis" style="margin-bottom: 1rem; color: #fff;">{{ audio_list[audioIndex]['audio_name'] }}</div>
37 - <div class="van-ellipsis" style="margin-bottom: 1rem; color: #fff;">{{ audio_list[audioIndex]['audio_name'] }}</div> 39 + <div style="display: flex; justify-content: space-between;">
38 - <div style="display: flex; justify-content: space-between;"> 40 + <van-icon @click="audioPrev" name="arrow-left" size="1.5rem" />
39 - <van-icon @click="audioPrev" name="arrow-left" size="1.5rem" /> 41 + <van-icon v-if="audioStatus === 'pause'" name="play" size="1.5rem" @click="handelPlay" />
40 - <van-icon v-if="audioStatus === 'pause'" name="play" size="1.5rem" @click="handelPlay" /> 42 + <van-icon v-if="audioStatus === 'play'" name="pause" size="1.5rem" @click="handlePause" />
41 - <van-icon v-if="audioStatus === 'play'" name="pause" size="1.5rem" @click="handlePause" /> 43 + <van-icon @click="audioNext" name="arrow" size="1.5rem" />
42 - <van-icon @click="audioNext" name="arrow" size="1.5rem" /> 44 + </div>
45 + </div> -->
46 + <div>
47 + <audio ref="audioPlayer" loop="loop" id="audios" :src="audio_list[audioIndex]?.audio_url" preoload></audio>
43 </div> 48 </div>
44 - </div> --> 49 + </div>
45 - <div> 50 + <div style="width: 75vw; height: 15rem; border: 1px solid #fff;">
46 - <audio ref="audioPlayer" loop="loop" id="audios" :src="audio_list[audioIndex]['audio_url']" preoload></audio> 51 + <div @click="audioPlay(index)" v-for="(item, index) in audio_list" :key="index">{{ item.audio_name }}</div>
47 </div> 52 </div>
48 </div> 53 </div>
49 </div> 54 </div>
...@@ -57,10 +62,36 @@ import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@ ...@@ -57,10 +62,36 @@ import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@
57 //import { } from '@/utils/generateModules.js' 62 //import { } from '@/utils/generateModules.js'
58 //import { } from '@/utils/generateIcons.js' 63 //import { } from '@/utils/generateIcons.js'
59 //import { } from '@/composables' 64 //import { } from '@/composables'
65 +import { getTreeAPI } from '@/api/carbon.js';
66 +
60 const $route = useRoute(); 67 const $route = useRoute();
61 const $router = useRouter(); 68 const $router = useRouter();
62 useTitle($route.meta.title); 69 useTitle($route.meta.title);
63 70
71 +const audio_list = ref([]);
72 +
73 +onMounted(async () => {
74 + const { code, data } = await getTreeAPI();
75 + if (code) {
76 + data.forEach(item => {
77 + if (item.is_tree === 1) {
78 + // audio_list.value.push({
79 + // audio_url: item.audio_url,
80 + // audio_cover: item.audio_cover,
81 + // audio_name: item.audio_name,
82 + // audio_note: item.audio_note,
83 + // });
84 + audio_list.value.push({
85 + audio_url: 'http://downsc.chinaz.net/files/download/sound1/201206/1638.mp3',
86 + audio_cover: 'https://picsum.photos/50/50',
87 + audio_name: item.name + '123456789',
88 + audio_note: item.audio_note,
89 + });
90 + }
91 + })
92 + }
93 +});
94 +
64 const audioPlayer = ref(null); 95 const audioPlayer = ref(null);
65 const audioStatus = ref('pause'); 96 const audioStatus = ref('pause');
66 const audioIndex = ref(0); 97 const audioIndex = ref(0);
...@@ -75,24 +106,19 @@ const handlePause = () => { ...@@ -75,24 +106,19 @@ const handlePause = () => {
75 audioStatus.value = 'pause'; 106 audioStatus.value = 'pause';
76 }; 107 };
77 108
78 -const audio_list = ref([{
79 - audio_url: 'http://downsc.chinaz.net/files/download/sound1/201206/1638.mp3',
80 - audio_cover: '',
81 - audio_name: '微风轻轻吹树叶的声音123467890',
82 - audio_note: '',
83 -}, {
84 - audio_url: 'http://downsc.chinaz.net/Files/DownLoad/sound1/201906/11582.mp3',
85 - audio_cover: '',
86 - audio_name: '微风轻轻吹树叶的声音',
87 - audio_note: '',
88 -}]);
89 -
90 const replay = () => { 109 const replay = () => {
91 audioPlayer.value.currentTime = 0; 110 audioPlayer.value.currentTime = 0;
92 audioPlayer.value.play(); 111 audioPlayer.value.play();
93 audioStatus.value = 'play'; 112 audioStatus.value = 'play';
94 } 113 }
95 114
115 +const audioPlay = (index) => {
116 + audioIndex.value = index;
117 + nextTick(() => {
118 + replay()
119 + });
120 +}
121 +
96 const audioPrev = () => { 122 const audioPrev = () => {
97 if (audioIndex.value > 0) { 123 if (audioIndex.value > 0) {
98 audioIndex.value--; 124 audioIndex.value--;
...@@ -126,16 +152,15 @@ const audioNext = () => { ...@@ -126,16 +152,15 @@ const audioNext = () => {
126 background-color: #47A3E4; 152 background-color: #47A3E4;
127 display: flex; 153 display: flex;
128 justify-content: center; 154 justify-content: center;
155 + align-items: center;
129 .audio-player { 156 .audio-player {
130 width: 75vw; 157 width: 75vw;
131 border: 1px solid #fff; 158 border: 1px solid #fff;
132 border-radius: 10px; 159 border-radius: 10px;
133 padding: 1rem 1rem 1rem 1rem; 160 padding: 1rem 1rem 1rem 1rem;
134 - position: absolute; 161 + // display: flex;
135 - top: 5rem; 162 + // justify-content: center;
136 - display: flex; 163 + // align-items: center;
137 - justify-content: center;
138 - align-items: center;
139 .play { 164 .play {
140 animation: rotate 8s linear infinite; 165 animation: rotate 8s linear infinite;
141 } 166 }
......