Files
Melo/src/renderer/components/common/VolumeBtn.vue
T
lyswhut a546b75986
Build / Windows (push) Waiting to run
Build / Windows_7 (push) Waiting to run
Build / Mac (push) Waiting to run
Build / Linux (push) Waiting to run
修复音量条在调整音量时实际音量与显示的数值不一致的问题(#2606)
2025-12-07 14:07:12 +08:00

117 lines
2.9 KiB
Vue

<template>
<material-popup-btn :class="$style.btnContent">
<button :class="$style.btn" :aria-label="isMute ? $t('player__volume_muted') : `${$t('player__volume')}${parseInt(volume * 100)}%`" @wheel="handleWheel">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="100%" viewBox="0 0 24 24" space="preserve">
<use :xlink:href="icon" />
</svg>
</button>
<template #content>
<div :class="$style.setting">
<div :class="$style.info">
<span>{{ Math.trunc(volume * 100) }}%</span>
<base-checkbox
id="player__volume_mute"
:model-value="isMute"
:label="$t('player__volume_mute_label')"
@update:model-value="saveVolumeIsMute($event)"
/>
</div>
<base-slider-bar :class="$style.slider" :value="volume" :min="0" :max="1" :step="0.01" @change="handleUpdateVolume" />
</div>
</template>
</material-popup-btn>
</template>
<script setup>
import { computed } from '@common/utils/vueTools'
// import useNextTogglePlay from '@renderer/utils/compositions/useNextTogglePlay'
// import useToggleDesktopLyric from '@renderer/utils/compositions/useToggleDesktopLyric'
// import { musicInfo, playMusicInfo } from '@renderer/store/player/state'
import { saveVolumeIsMute } from '@renderer/store/setting'
import { volume, isMute } from '@renderer/store/player/volume'
const handleWheel = (event) => {
window.app_event.setVolume(Math.round(volume.value * 100 + (-event.deltaY / 100 * 2)) / 100)
}
const handleUpdateVolume = (val) => {
window.app_event.setVolume(val)
}
const icon = computed(() => {
return isMute.value
? '#icon-volume-mute-outline'
: volume.value == 0
? '#icon-volume-off-outline'
: volume.value < 0.3
? '#icon-volume-low-outline'
: volume.value < 0.7
? '#icon-volume-medium-outline'
: '#icon-volume-high-outline'
})
</script>
<style lang="less" module>
@import '@renderer/assets/styles/layout.less';
.btnContent {
flex: none;
height: 100%;
}
.btn {
position: relative;
// color: var(--color-button-font);
justify-content: center;
align-items: center;
transition: color @transition-normal;
cursor: pointer;
background-color: transparent;
border: none;
width: 24px;
display: flex;
flex-flow: column nowrap;
padding: 0;
svg {
transition: opacity @transition-fast;
opacity: .6;
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.2));
}
&:hover {
svg {
opacity: .9;
}
}
&:active {
svg {
opacity: 1;
}
}
}
.setting {
display: flex;
flex-flow: column nowrap;
padding: 2px 3px;
gap: 8px;
width: 140px;
}
.info {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
font-size: 13px;
span {
line-height: 1.2;
}
}
.slider {
width: 100%;
}
</style>