fix: 使消息同时只存在一个

This commit is contained in:
imsyy
2023-06-12 16:40:43 +08:00
parent da2a924c7e
commit bf3675ce45
4 changed files with 33 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
<template>
<Transition mode="out-in" appear>
<Transition mode="out-in" appear v-if="music.getPlaySongLyric">
<div
class="countdown"
:style="{ animationPlayState: music.getPlayState ? 'running' : 'paused' }"
@@ -24,33 +24,35 @@ const music = musicStore();
// 剩余点数
const remainingPoint = ref(0);
// 总时长
const totalDuration = ref(
music.getPlaySongLyric.hasYrc
? music.getPlaySongLyric?.yrc[0].time
: music.getPlaySongLyric?.lrc[0].time
);
const totalDuration = ref(0);
// 监听歌曲时长变化
watch(
() => music.getPlaySongTime.currentTime,
(val) => {
if (music.getPlaySongLyric.lrc[0]) {
const remainingTime = totalDuration.value - val - 0.5;
const progress = 1 - remainingTime / totalDuration.value;
remainingPoint.value = Number(Math.floor(3 * progress));
if (music.getPlaySongLyric) {
const lyric =
music.getPlaySongLyric.lrc[0] || music.getPlaySongLyric.yrc[0];
if (lyric) {
totalDuration.value = lyric.time;
const remainingTime = totalDuration.value - val - 0.5;
const progress = 1 - remainingTime / totalDuration.value;
remainingPoint.value = Number(Math.floor(3 * progress));
}
}
}
);
// 监听歌曲改变
watch(
() => music.getPlaySongLyric?.lrc,
() => music.getPlaySongLyric,
(val) => {
if (music.getPlaySongLyric.lrc[0]) {
totalDuration.value = music.getPlaySongLyric.hasYrc
? music.getPlaySongLyric?.yrc[0].time
: val[0].time;
remainingPoint.value = 0;
if (val) {
const lyric = val.lrc[0] || val.yrc[0];
if (lyric) {
totalDuration.value = lyric.time;
remainingPoint.value = 0;
}
}
}
);
@@ -67,6 +69,7 @@ watch(
opacity: 0;
transform: scale(0);
}
.countdown {
animation: breathe 5s ease-in-out infinite;
.point {
@@ -77,13 +80,16 @@ watch(
}
}
}
@keyframes breathe {
0% {
transform: scale(0.95);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(0.95);
}

View File

@@ -21,7 +21,7 @@
<n-loading-bar-provider>
<n-dialog-provider>
<n-notification-provider>
<n-message-provider>
<n-message-provider :max="1">
<slot></slot>
<NaiveProviderContent />
</n-message-provider>

View File

@@ -49,8 +49,6 @@ const useMusicDataStore = defineStore("musicData", {
},
// 是否正在加载数据
isLoadingSong: false,
// 临时弹窗数据
message: null,
// 持久化数据
persistData: {
// 搜索历史
@@ -369,8 +367,7 @@ const useMusicDataStore = defineStore("musicData", {
break;
}
}
this.message?.destroy();
this.message = $message.info(getLanguageData(value), {
$message.info(getLanguageData(value), {
icon: () =>
h(NIcon, null, {
default: () => h(modeObj[this.persistData.playSongMode]),

View File

@@ -81,12 +81,15 @@ export const createSound = (src, autoPlay = true) => {
music.setPlayState(true);
const songName = music.getPlaySongData.name;
const songArtist = music.getPlaySongData.artist[0].name;
$message.info(songName + " - " + songArtist, {
icon: () =>
h(NIcon, null, {
default: () => h(MusicNoteFilled),
}),
});
// 播放通知
if (typeof $message !== "undefined") {
$message.info(songName + " - " + songArtist, {
icon: () =>
h(NIcon, null, {
default: () => h(MusicNoteFilled),
}),
});
}
console.log("开始播放:" + songName + " - " + songArtist);
// 获取播放器信息
timeupdateInterval = setInterval(() => checkAudioTime(sound, music), 250);