fix(歌曲请求站): 修复歌曲切换逻辑并优化音频管理

修复fastForward函数逻辑,改为按标签切换歌曲而非时间跳转
调整clickSongs函数,传递标签信息用于后续歌曲管理
移除调试用的console.log语句
统一代码格式,如引号风格和分号使用
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-10-11 12:03:39 +08:00
parent 478e1c357c
commit bccccacad8
3 changed files with 19 additions and 25 deletions

View File

@@ -211,6 +211,8 @@ createApp({
const src = playData.value?.playurl || "";
const area = playData.value?.area || "";
console.log(audioPlayer.value.src, src);
if (audioPlayer.value.src != src) {
manageAudio(src, area);
return;
@@ -524,12 +526,11 @@ createApp({
else getPlayUrl(index, area);
};
// 监听 previewState 如果为 true body.style.overflow = 'hidden'
watch(previewState, (newVal) => {
if (newVal) document.body.style.overflow = 'hidden';
else document.body.style.overflow = 'auto';
})
if (newVal) document.body.style.overflow = "hidden";
else document.body.style.overflow = "auto";
});
return { judgmentPlayUrl, cutSong, getPlayUrl, handleBarDragBottomClick, startBarDragBottom, volumeShow, handleVolumeHide, handleVolumeShow, zeroOrderStudents, rePlay, playData, awardAudioList, changeInterval, awardMVList, bannerList, albumBoxRef, volume, handleVolumeClick, handleVolumeDrag, startDrag, stopDrag, volume, cutStudent, studentList, studentIndex, scrollToPrevious, scrollToNext, changePointer, pointerIndex, visibleRef, studentRef, customRef, formatTime, currentTimeFormatted, durationFormatted, worksRef, introduceRef, customList, closeAll, manageAudio, progress, closePreview, openPreview, previewState, audioPlayer, trait, fastForward };
},

View File

@@ -391,9 +391,9 @@ createApp({
const audioPlayer = ref(null);
const clickSongs = (songs) => {
const clickSongs = (tag, songs) => {
const randomIndex = Math.floor(Math.random() * songs.length);
const item = songs[randomIndex];
const item = { ...songs[randomIndex], tag };
manageAudio(item);
};
@@ -402,10 +402,7 @@ createApp({
const audio = audioPlayer.value;
closeAll();
setTimeout(() => {
console.log("item", item);
if (audio?.src != item.path) audio.src = `./static/mp3/station/${item.path}`;
// audio.src = "https://app.gter.net/image/miniApp/mp3/1.mp3";
// audio.src = "/static/mp3/1.MP3";
audio.play().then(() => (playData.value = { ...item, state: true }));
}, 500);
};
@@ -517,25 +514,21 @@ createApp({
durationFormatted.value = formatTime(duration);
};
// 快进 和 后退 10秒
// 切换下一首 或 上一首
const fastForward = (type = "fast") => {
if (!audioPlayer.value) return;
console.log("playData.value", playData.value);
const src = playData.value?.path || "";
tags.value.forEach((item) => {
if (item.tag == playData.value.tag) {
const songs = item.songs || [];
const index = songs.findIndex((song) => song.name == playData.value.name);
// 通过下标 type = "fast" 为下一首 否则为上一首 并且需要轮回播放
const newIndex = type == "fast" ? (index + 1) % songs.length : (index - 1 + songs.length) % songs.length;
if (audioPlayer.value.src != src) {
manageAudio(playData.value);
return;
}
let currentTime = audioPlayer.value.currentTime || 0;
const duration = audioPlayer.value.duration || 0;
let newTime = 0;
if (type == "fast") newTime = Math.min(currentTime + 10, duration);
else newTime = Math.max(currentTime - 10, 0);
audioPlayer.value.currentTime = newTime;
getProgress();
const data = { ...songs[newIndex], tag: item.tag };
manageAudio(data);
}
});
};
// 关闭所有播放