From f59b43cbbe3bc8f3fdec76c8a6f311285ad5859c Mon Sep 17 00:00:00 2001 From: zilong Date: Sat, 6 Nov 2021 17:45:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE,=E9=98=B2=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/App.vue | 56 +++++++++++++++++------------------ src/lib/useBackSnaps.js | 2 +- src/lib/useHotkey.js | 39 ++++++++++++++++++++++++ src/views/common/SongCtrl.vue | 11 ++++++- yarn.lock | 5 ++++ 6 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 src/lib/useHotkey.js diff --git a/package.json b/package.json index 155cb15..eef8a26 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "core-js": "^3.6.5", "dayjs": "^1.10.7", "element-plus": "^1.1.0-beta.19", + "hotkeys-js": "^3.8.7", "lodash": "^4.17.21", "pubsub-js": "^1.9.3", "unplugin-vue-components": "^0.15.6", diff --git a/src/App.vue b/src/App.vue index 7d09e41..eba3185 100644 --- a/src/App.vue +++ b/src/App.vue @@ -22,9 +22,9 @@ import { NMessageProvider, } from "naive-ui"; import router from "./router"; +import useHotkey from '@/lib/useHotkey.js' -// import { CloudCircleSharp } from "@vicons/ionicons5"; - +useHotkey() //快捷键 const store = useStore(); /** @@ -62,15 +62,14 @@ const showSongDetail = ref(false); //是否显示歌曲详细信息 const showSearch = ref(false); //是否显示搜索 watch( - ()=> store.state.showSongDetail, - ()=>{ - showSongDetail.value = toRaw(store.state.showSongDetail) + () => store.state.showSongDetail, + () => { + showSongDetail.value = toRaw(store.state.showSongDetail); }, { immediate: true, } -) - +); //处理route消息 const routeToken = pubsub.subscribe("router", (msg, data) => { @@ -90,42 +89,44 @@ const token = pubsub.subscribe("zp", (msg, data) => { showPlaying.value = !showPlaying.value; break; case "zp.toggleSongDetail": - showSongDetail.value = store.state.showSongDetail = !showSongDetail.value; + showSongDetail.value = store.state.showSongDetail = + !showSongDetail.value; break; case "zp.showSearch": showSearch.value = true; break; case "zp.toggleSearch": - showSearch.value = !showSearch.value ; + showSearch.value = !showSearch.value; break; } }); //卸载组件 -onUnmounted(() => { +onUnmounted(() => { pubsub.unsubscribe(routeToken); pubsub.unsubscribe(token); }); - -const wpEl = ref('') +const wpEl = ref(""); const hideWins = (e) => { // console.log(e.clientX > 0,e, wpEl.value.clientWidth); //显示当前播放 - if (showPlaying.value - && e.clientX > 0 - && e.clientX < wpEl.value.clientWidth - 500 - && e.clientY > 40 - && e.clientY < wpEl.value.clientHeight - 64 + if ( + showPlaying.value && + e.clientX > 0 && + e.clientX < wpEl.value.clientWidth - 500 && + e.clientY > 40 && + e.clientY < wpEl.value.clientHeight - 64 ) { showPlaying.value = false; } //显示搜索 - if (showSearch.value - && e.clientX > 0 - && e.clientX < wpEl.value.clientWidth - 360 - && e.clientY > 40 - && e.clientY < wpEl.value.clientHeight - 64 + if ( + showSearch.value && + e.clientX > 0 && + e.clientX < wpEl.value.clientWidth - 360 && + e.clientY > 40 && + e.clientY < wpEl.value.clientHeight - 64 ) { showSearch.value = false; } @@ -133,8 +134,7 @@ const hideWins = (e) => { const keyup = (e) => { console.log(e); - -} +};