fix(player): 静音保留原音量,解除后可恢复

- playerCore 新增持久化 isMuted 状态及 setMuted/toggleMute,静音时音频输出置 0 但 volume 保持不变
- 音量 > 0 时自动解除静音
- useVolumeControl 移除原 0↔30 切换;滑块/百分比展示真实音量,图标反映静音态
- 三个播放栏的音量滑块在静音时 disabled;PlayBar 百分比文字同步置灰(仅文字颜色)
This commit is contained in:
chengww
2026-04-26 21:47:11 +08:00
parent 97220761cf
commit 2b1024ca24
6 changed files with 84 additions and 16 deletions
+9 -9
View File
@@ -9,7 +9,10 @@ import { usePlayerStore } from '@/store/modules/player';
export function useVolumeControl() {
const playerStore = usePlayerStore();
/** 音量滑块值 (0-100) */
/** 是否静音 */
const isMuted = computed(() => playerStore.isMuted);
/** 音量滑块值 (0-100),静音时仍展示原始音量 */
const volumeSlider = computed({
get: () => playerStore.volume * 100,
set: (value: number) => {
@@ -19,21 +22,17 @@ export function useVolumeControl() {
/** 音量图标 class */
const volumeIcon = computed(() => {
if (playerStore.volume === 0) return 'ri-volume-mute-line';
if (playerStore.isMuted || playerStore.volume === 0) return 'ri-volume-mute-line';
if (playerStore.volume <= 0.5) return 'ri-volume-down-line';
return 'ri-volume-up-line';
});
/** 静音切换 (0 ↔ 30%) */
/** 切换静音(保留静音前的音量) */
const mute = () => {
if (volumeSlider.value === 0) {
volumeSlider.value = 30;
} else {
volumeSlider.value = 0;
}
playerStore.toggleMute();
};
/** 鼠标滚轮调整音量 ±5% */
/** 鼠标滚轮调整音量 ±5%;静音时向上滚轮会自动解除静音 */
const handleVolumeWheel = (e: WheelEvent) => {
const delta = e.deltaY < 0 ? 5 : -5;
const newValue = Math.min(Math.max(volumeSlider.value + delta, 0), 100);
@@ -41,6 +40,7 @@ export function useVolumeControl() {
};
return {
isMuted,
volumeSlider,
volumeIcon,
mute,