Skip to content

Commit 95af222

Browse files
committed
feat: 添加鼠标滚轮调整音量功能,并显示音量百分比
1 parent 9eefe62 commit 95af222

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/renderer/components/player/PlayBar.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@
9696
</div>
9797
</div>
9898
<div class="audio-button">
99-
<div class="audio-volume custom-slider">
99+
<div class="audio-volume custom-slider" @wheel.prevent="handleVolumeWheel">
100100
<div class="volume-icon" @click="mute">
101101
<i class="iconfont" :class="getVolumeIcon"></i>
102102
</div>
103103
<div class="volume-slider">
104+
<div class="volume-percentage">{{ Math.round(volumeSlider) }}%</div>
104105
<n-slider v-model:value="volumeSlider" :step="0.01" :tooltip="false" vertical></n-slider>
105106
</div>
106107
</div>
@@ -276,6 +277,14 @@ const mute = () => {
276277
}
277278
};
278279
280+
// 鼠标滚轮调整音量
281+
const handleVolumeWheel = (e: WheelEvent) => {
282+
// 向上滚动增加音量,向下滚动减少音量
283+
const delta = e.deltaY < 0 ? 5 : -5;
284+
const newValue = Math.min(Math.max(volumeSlider.value + delta, 0), 100);
285+
volumeSlider.value = newValue;
286+
};
287+
279288
// 播放模式
280289
const playMode = computed(() => playerStore.playMode);
281290
const playModeIcon = computed(() => {
@@ -476,6 +485,12 @@ const openPlayListDrawer = () => {
476485
@apply absolute opacity-0 invisible transition-all duration-300 bottom-[30px] left-1/2 -translate-x-1/2 h-[180px] px-2 py-4 rounded-xl;
477486
@apply bg-light dark:bg-gray-800;
478487
@apply border border-gray-200 dark:border-gray-700;
488+
489+
.volume-percentage {
490+
@apply absolute -top-6 left-1/2 -translate-x-1/2 text-xs font-medium bg-light dark:bg-gray-800 px-2 py-1 rounded-md;
491+
@apply border border-gray-200 dark:border-gray-700;
492+
white-space: nowrap;
493+
}
479494
}
480495
}
481496

0 commit comments

Comments
 (0)