音量大小控制
This commit is contained in:
parent
70cb1b3e06
commit
310cf5efad
@ -95,6 +95,9 @@ const token = pubsub.subscribe("zp", (msg, data) => {
|
|||||||
case "zp.showSearch":
|
case "zp.showSearch":
|
||||||
showSearch.value = true;
|
showSearch.value = true;
|
||||||
break;
|
break;
|
||||||
|
case "zp.hideSearch":
|
||||||
|
showSearch.value = false;
|
||||||
|
break;
|
||||||
case "zp.toggleSearch":
|
case "zp.toggleSearch":
|
||||||
showSearch.value = !showSearch.value;
|
showSearch.value = !showSearch.value;
|
||||||
break;
|
break;
|
||||||
|
@ -10,7 +10,7 @@ export default function useHotkey(){
|
|||||||
"enter,ctrl+enter,⌘+enter",
|
"enter,ctrl+enter,⌘+enter",
|
||||||
].join(","),
|
].join(","),
|
||||||
throttle((e, h) => {
|
throttle((e, h) => {
|
||||||
switch (h.key) {
|
switch (h.key) {
|
||||||
// space,ctrl+p,⌘+p
|
// space,ctrl+p,⌘+p
|
||||||
case "space":
|
case "space":
|
||||||
case "ctrl+p":
|
case "ctrl+p":
|
||||||
@ -26,6 +26,15 @@ export default function useHotkey(){
|
|||||||
case "⌘+right":
|
case "⌘+right":
|
||||||
pubsub.publish("zp.next");
|
pubsub.publish("zp.next");
|
||||||
break;
|
break;
|
||||||
|
// ctrl+up,⌘+up,ctrl+down,⌘+down
|
||||||
|
case "ctrl+up":
|
||||||
|
case "⌘+up":
|
||||||
|
pubsub.publish("zp.setVolume",{step: 5});
|
||||||
|
break;
|
||||||
|
case "ctrl+down":
|
||||||
|
case "⌘+down":
|
||||||
|
pubsub.publish("zp.setVolume",{step: -5});
|
||||||
|
break;
|
||||||
// enter,ctrl+enter,⌘+enter
|
// enter,ctrl+enter,⌘+enter
|
||||||
case "enter":
|
case "enter":
|
||||||
case "ctrl+enter":
|
case "ctrl+enter":
|
||||||
@ -36,4 +45,23 @@ export default function useHotkey(){
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}, 500)
|
}, 500)
|
||||||
);
|
);
|
||||||
|
hotkeys(
|
||||||
|
[
|
||||||
|
"ctrl+up,⌘+up,ctrl+down,⌘+down",
|
||||||
|
].join(","),
|
||||||
|
throttle((e, h) => {
|
||||||
|
switch (h.key) {
|
||||||
|
// ctrl+up,⌘+up,ctrl+down,⌘+down
|
||||||
|
case "ctrl+up":
|
||||||
|
case "⌘+up":
|
||||||
|
pubsub.publish("zp.setVolume",{step: 5});
|
||||||
|
break;
|
||||||
|
case "ctrl+down":
|
||||||
|
case "⌘+down":
|
||||||
|
pubsub.publish("zp.setVolume",{step: -5});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
}, 50)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
@ -14,6 +14,8 @@ export default createStore({
|
|||||||
songId: 0, //歌曲id
|
songId: 0, //歌曲id
|
||||||
playing: false, //是否播放
|
playing: false, //是否播放
|
||||||
playMode: 0, //播放模式:0-3,顺序,循环,单曲,随机。
|
playMode: 0, //播放模式:0-3,顺序,循环,单曲,随机。
|
||||||
|
volume: 100, //音量,最大100
|
||||||
|
muted: false, //静音
|
||||||
lastPlayed: [], //最近播放
|
lastPlayed: [], //最近播放
|
||||||
playingList: [], //当前播放
|
playingList: [], //当前播放
|
||||||
searchHistory: [], //搜索历史
|
searchHistory: [], //搜索历史
|
||||||
|
@ -44,7 +44,8 @@ const result = ref({});
|
|||||||
}
|
}
|
||||||
"
|
"
|
||||||
v-model:value="keywords"
|
v-model:value="keywords"
|
||||||
@keyup.enter="search"
|
@keydown.enter="search"
|
||||||
|
@keyup.esc="pubsub.publish('zp.hideSearch');"
|
||||||
@input="handleInput"
|
@input="handleInput"
|
||||||
style="width: 190px"
|
style="width: 190px"
|
||||||
>
|
>
|
||||||
|
@ -178,6 +178,9 @@ watch(playing, (val, old) => {
|
|||||||
// console.log(audioEl.value.duration);
|
// console.log(audioEl.value.duration);
|
||||||
if (audioEl.value) {
|
if (audioEl.value) {
|
||||||
currentTime = audioEl.value.currentTime;
|
currentTime = audioEl.value.currentTime;
|
||||||
|
audioEl.value.volume = store.state.settings.muted
|
||||||
|
? 0
|
||||||
|
: store.state.settings.volume / 100;
|
||||||
pubsub.publish("zp.progress", {
|
pubsub.publish("zp.progress", {
|
||||||
progress: audioEl.value.currentTime,
|
progress: audioEl.value.currentTime,
|
||||||
total: audioEl.value.duration,
|
total: audioEl.value.duration,
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch, toRaw } from "vue";
|
import { ref, watch, toRaw, h } from "vue";
|
||||||
import {useStore} from 'vuex';
|
import { useStore } from "vuex";
|
||||||
import { NButton, NIcon, NSpace } from "naive-ui";
|
import { NButton, NIcon, NSpace, NDropdown } from "naive-ui";
|
||||||
import PlaylistMusic from "@/assets/svgs/PlaylistMusic.svg";
|
import PlaylistMusic from "@/assets/svgs/PlaylistMusic.svg";
|
||||||
import VolumeOffOutline from "@/assets/svgs/VolumeOffOutline.svg";
|
import VolumeOffOutline from "@/assets/svgs/VolumeOffOutline.svg";
|
||||||
|
import VolumeMediumOutline from "@/assets/svgs/VolumeMediumOutline.svg";
|
||||||
import RepeatOutline from "@/assets/svgs/RepeatOutline.svg";
|
import RepeatOutline from "@/assets/svgs/RepeatOutline.svg";
|
||||||
import RepeatOne from "@/assets/svgs/RepeatOne.svg";
|
import RepeatOne from "@/assets/svgs/RepeatOne.svg";
|
||||||
import Playlist from "@/assets/svgs/Playlist.svg";
|
import Playlist from "@/assets/svgs/Playlist.svg";
|
||||||
import Random from "@/assets/svgs/Random.svg";
|
import Random from "@/assets/svgs/Random.svg";
|
||||||
import pubsub from 'pubsub-js';
|
import pubsub from "pubsub-js";
|
||||||
|
import Vol from "@/views/common/Vol.vue";
|
||||||
|
|
||||||
const store = useStore()
|
const store = useStore();
|
||||||
|
|
||||||
//播放模式:0-3,顺序,循环,单曲,随机。
|
//播放模式:0-3,顺序,循环,单曲,随机。
|
||||||
let playMode = ref(0)
|
const playMode = ref(0);
|
||||||
|
const vol = ref(store.state.settings.volume);
|
||||||
|
const muted = ref(store.state.settings.muted);
|
||||||
|
|
||||||
const chPlayMode = (mode) => {
|
const chPlayMode = (mode) => {
|
||||||
store.commit('saveSettings', {
|
store.commit("saveSettings", {
|
||||||
playMode: mode
|
playMode: mode,
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => store.state.settings.playMode,
|
() => store.state.settings.playMode,
|
||||||
@ -32,6 +36,43 @@ watch(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const options = [
|
||||||
|
{
|
||||||
|
key: "k",
|
||||||
|
type: "render",
|
||||||
|
render: () => h(Vol, {}),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const setVol = (step) => {
|
||||||
|
vol.value += step;
|
||||||
|
if (vol.value > 100) vol.value = 100;
|
||||||
|
if (vol.value < 0) vol.value = 0;
|
||||||
|
muted.value = vol.value <= 0
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [vol.value, muted.value],
|
||||||
|
([v, m], [oldV, oldM]) => {
|
||||||
|
if(v>=0 && v<=100){
|
||||||
|
store.commit('saveSettings',{
|
||||||
|
volume: v,
|
||||||
|
muted: m,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const token = pubsub.subscribe("zp", (msg, data) => {
|
||||||
|
switch (msg) {
|
||||||
|
case "zp.setVolume":
|
||||||
|
setVol(data.step);
|
||||||
|
break;
|
||||||
|
// case "zp.setMuted":
|
||||||
|
// muted.value = !muted.value
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -43,57 +84,68 @@ watch(
|
|||||||
:size="[6]"
|
:size="[6]"
|
||||||
style="padding-top: 2px; padding-right: 8px"
|
style="padding-top: 2px; padding-right: 8px"
|
||||||
>
|
>
|
||||||
<n-button circle v-if="playMode==1" @click="chPlayMode(2)">
|
<n-button circle v-if="playMode == 1" @click="chPlayMode(2)">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon>
|
<n-icon>
|
||||||
<RepeatOutline />
|
<RepeatOutline />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button circle v-if="playMode==2" @click="chPlayMode(3)">
|
<n-button circle v-if="playMode == 2" @click="chPlayMode(3)">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon>
|
<n-icon>
|
||||||
<RepeatOne />
|
<RepeatOne />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button circle v-if="playMode==0" @click="chPlayMode(1)">
|
<n-button circle v-if="playMode == 0" @click="chPlayMode(1)">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon>
|
<n-icon>
|
||||||
<Playlist />
|
<Playlist />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button circle v-if="playMode==3" @click="chPlayMode(0)">
|
<n-button circle v-if="playMode == 3" @click="chPlayMode(0)">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon>
|
<n-icon>
|
||||||
<Random />
|
<Random />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button circle @click="pubsub.publish('zp.togglePlaying',)">
|
<n-button circle @click="pubsub.publish('zp.togglePlaying')">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon>
|
<n-icon>
|
||||||
<PlaylistMusic />
|
<PlaylistMusic />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button circle>
|
<NDropdown :options="options" trigger="hover" :show-arrow="true">
|
||||||
<template #icon>
|
<n-button
|
||||||
<n-icon>
|
circle
|
||||||
<VolumeOffOutline />
|
v-if="store.state.settings.muted"
|
||||||
</n-icon>
|
@click="pubsub.publish('zp.setMuted')"
|
||||||
</template>
|
>
|
||||||
</n-button>
|
<template #icon>
|
||||||
|
<n-icon>
|
||||||
|
<VolumeOffOutline />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
<n-button circle v-else @click="pubsub.publish('zp.setMuted')">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon>
|
||||||
|
<VolumeMediumOutline />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
</NDropdown>
|
||||||
</n-space>
|
</n-space>
|
||||||
|
|
||||||
<!-- </div> -->
|
<!-- </div> -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {};
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
118
src/views/common/Vol.vue
Normal file
118
src/views/common/Vol.vue
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
<script setup>
|
||||||
|
import { NSlider } from "naive-ui";
|
||||||
|
import { ref, watch, onUnmounted } from "vue";
|
||||||
|
import { useStore } from "vuex";
|
||||||
|
import pubsub from 'pubsub-js'
|
||||||
|
|
||||||
|
const store = useStore();
|
||||||
|
const vol = ref(store.state.settings.volume);
|
||||||
|
const muted = ref(store.state.settings.muted);
|
||||||
|
|
||||||
|
const { primaryColor } = store.state.theme.themeOverrides.common;
|
||||||
|
const stySlider = () => {
|
||||||
|
return {
|
||||||
|
backgroundColor: primaryColor,
|
||||||
|
height: (muted.value ? 0: vol.value) + "px",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const styDot = () => {
|
||||||
|
return {
|
||||||
|
backgroundColor: primaryColor,
|
||||||
|
bottom: (muted.value ? 0: vol.value) - 6 + "px",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const setSlider = (e) => {
|
||||||
|
vol.value = 100 - e.offsetY;
|
||||||
|
muted.value = vol.value <= 0
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [vol.value, muted.value],
|
||||||
|
([v, m], [oldV, oldM]) => {
|
||||||
|
// m = v <= 0
|
||||||
|
if(v>=0 && v<=100){
|
||||||
|
store.commit('saveSettings',{
|
||||||
|
volume: v,
|
||||||
|
muted: m,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const setVol = (step) => {
|
||||||
|
vol.value += step;
|
||||||
|
if (vol.value > 100) vol.value = 100;
|
||||||
|
if (vol.value < 0) vol.value = 0;
|
||||||
|
muted.value = vol.value <= 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const token = pubsub.subscribe("zp", (msg, data) => {
|
||||||
|
switch (msg) {
|
||||||
|
case "zp.setVolume":
|
||||||
|
setVol(data.step);
|
||||||
|
break;
|
||||||
|
case "zp.setMuted":
|
||||||
|
muted.value = !muted.value
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//卸载组件
|
||||||
|
onUnmounted(() => {
|
||||||
|
pubsub.unsubscribe(token);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="wp z-slider">
|
||||||
|
<div class="bg">
|
||||||
|
<div class="content" :style="stySlider()"></div>
|
||||||
|
<div class="dot" :style="styDot()"></div>
|
||||||
|
<div class="mask" @click="setSlider"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.z-slider.wp {
|
||||||
|
position: relative;
|
||||||
|
padding: 6px;
|
||||||
|
padding-top: 10px;
|
||||||
|
width: 30px;
|
||||||
|
// height: 100px;
|
||||||
|
// border: 1px #eee solid;
|
||||||
|
.bg {
|
||||||
|
height: 100px;
|
||||||
|
position: relative;
|
||||||
|
.content {
|
||||||
|
position: absolute;
|
||||||
|
border-radius: 2px;
|
||||||
|
bottom: 0px;
|
||||||
|
left: 7px;
|
||||||
|
width: 4px;
|
||||||
|
height: 70px;
|
||||||
|
}
|
||||||
|
.dot {
|
||||||
|
position: absolute;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
bottom: 67px;
|
||||||
|
left: 4px;
|
||||||
|
}
|
||||||
|
.mask {
|
||||||
|
position: absolute;
|
||||||
|
// width: 30px;
|
||||||
|
// height: 100px;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
x
Reference in New Issue
Block a user