From 06073f3982a75de18653ee24625f4540a035227f Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 3 Jan 2021 00:46:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BC=A0=E6=A0=87=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/plugins/Tips/Tips.js | 21 ++++++++++++++++++++- src/renderer/plugins/Tips/Tips.vue | 1 + src/renderer/plugins/Tips/index.js | 10 +++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 0fa6d79a..a3637cb7 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -2,6 +2,7 @@ - 我的列表右键菜单新增列表排序功能,可调整单曲、多选后的歌曲的顺序。注意:多选排序还将会按照选中歌曲时的顺序排序 - 添加鼠标指向歌曲封面的提示(对于进度条左边的歌曲封面,你可能不知道的操作->右击在“我的列表”定位当前播放的歌曲) +- 添加鼠标提示的自动关闭功能,鼠标长时间(目前是10秒)不动时鼠标提示将会自动关闭 ### 修复 diff --git a/src/renderer/plugins/Tips/Tips.js b/src/renderer/plugins/Tips/Tips.js index 7b522b4f..9b5c8360 100644 --- a/src/renderer/plugins/Tips/Tips.js +++ b/src/renderer/plugins/Tips/Tips.js @@ -2,7 +2,21 @@ import Tips from './Tips.vue' import Vue from 'vue' const TipsConstructor = Vue.extend(Tips) -export default ({ position, message } = {}) => { + +const addAutoCloseTimer = (instance, time) => { + if (!time) return + if (instance.autoCloseTimer) clearTimeout(instance.autoCloseTimer) + instance.autoCloseTimer = setTimeout(() => { + instance.cancel() + }, time) +} +const clearAutoCloseTimer = instance => { + if (!instance.autoCloseTimer) return + clearTimeout(instance.autoCloseTimer) + instance.autoCloseTimer = null +} + +export default ({ position, message, autoCloseTime } = {}) => { if (!position) return let instance = new TipsConstructor().$mount(document.createElement('div')) @@ -17,14 +31,19 @@ export default ({ position, message } = {}) => { document.body.appendChild(instance.$el) instance.cancel = () => { + instance.$emit('beforeClose', instance) + clearAutoCloseTimer(instance) instance.visible = false instance = null } instance.setTips = tips => { + addAutoCloseTimer(instance, autoCloseTime) instance.message = tips } + addAutoCloseTimer(instance, autoCloseTime) + return instance } diff --git a/src/renderer/plugins/Tips/Tips.vue b/src/renderer/plugins/Tips/Tips.vue index b46408df..b07fad95 100644 --- a/src/renderer/plugins/Tips/Tips.vue +++ b/src/renderer/plugins/Tips/Tips.vue @@ -17,6 +17,7 @@ export default { transform: 'translate(0, 0)', cancel: null, setTips: null, + aotoCloseTimer: null, } }, watch: { diff --git a/src/renderer/plugins/Tips/index.js b/src/renderer/plugins/Tips/index.js index eede83c9..203f5794 100644 --- a/src/renderer/plugins/Tips/index.js +++ b/src/renderer/plugins/Tips/index.js @@ -19,18 +19,22 @@ const showTips = debounce(event => { prevTips = msg instance = tips({ message: msg, + autoCloseTime: 10000, position: { top: event.y + 12, left: event.x + 8, }, }) + instance.$on('beforeClose', closeInstance => { + if (instance !== closeInstance) return + prevTips = null + instance = null + }) }, 400) const hideTips = () => { if (!instance) return instance.cancel() - prevTips = null - instance = null } const setTips = tips => { @@ -39,7 +43,7 @@ const setTips = tips => { } const updateTips = event => { - if (!instance) return + if (!instance) return showTips(event) setTimeout(() => { let msg = getTips(event.target) if (!msg || prevTips === msg) return