From 8d743803c84417d69ddd684fcc0155fb40d89b50 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 29 Nov 2019 00:01:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=BB=9A=E5=8A=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 3 ++ src/renderer/store/modules/download.js | 2 +- src/renderer/utils/index.js | 45 +++++++++++++++++--------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 0469bb54..cbf67e85 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,6 @@ +### 优化 + +- 优化定位歌曲时的列表滚动机制 ### 修复 diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index a75be6d6..d7eb9d14 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -88,7 +88,7 @@ const getUrl = (downloadInfo, isRefresh) => { * 设置歌曲meta信息 * @param {*} downloadInfo * @param {*} filePath - * @param {*} isEmbedPic + * @param {*} isEmbedPic // 是否嵌入图片 */ const saveMeta = (downloadInfo, filePath, isEmbedPic) => { if (downloadInfo.type === 'ape' || downloadInfo.type === 'flac') return diff --git a/src/renderer/utils/index.js b/src/renderer/utils/index.js index 1c90cf50..95b099f8 100644 --- a/src/renderer/utils/index.js +++ b/src/renderer/utils/index.js @@ -42,22 +42,35 @@ export const b64DecodeUnicode = str => { export const decodeName = str => str.replace(/'/g, '\'') -export const scrollTo = (element, to, duration = 300, fn = function() {}) => { +const easeInOutQuad = (t, b, c, d) => { + t /= d / 2 + if (t < 1) return (c / 2) * t * t + b + t-- + return (-c / 2) * (t * (t - 2) - 1) + b +} +/** + * 设置滚动条位置 + * @param {*} element 要设置滚动的容器 dom + * @param {*} to 滚动的目标位置 + * @param {*} duration 滚动完成时间 ms + * @param {*} fn 滚动完成后的回调 + */ +export const scrollTo = (element, to, duration = 300, fn = () => {}) => { if (!element) return const start = element.scrollTop || element.scrollY || 0 + if (to > start) { + let maxScrollTop = element.scrollHeight - element.clientHeight + if (to > maxScrollTop) to = maxScrollTop + } else if (to < start) { + if (to < 0) to = 0 + } else return fn() const change = to - start const increment = 10 - if (!change) { - fn() - return - } - let currentTime = 0; let val - const easeInOutQuad = (t, b, c, d) => { - t /= d / 2 - if (t < 1) return (c / 2) * t * t + b - t-- - return (-c / 2) * (t * (t - 2) - 1) + b - } + if (!change) return fn() + + let currentTime = 0 + let val + const animateScroll = () => { currentTime += increment val = parseInt(easeInOutQuad(currentTime, start, change, duration)) @@ -83,13 +96,13 @@ export const checkPath = path => fs.existsSync(path) /** - * 在资源管理器中打开目录 + * 选择路径 * @param {*} 选项 */ export const selectDir = options => rendererInvoke('selectDir', options) /** - * 在资源管理器中打开目录 + * 打开保存对话框 * @param {*} 选项 */ export const openSaveDir = options => rendererInvoke('showSaveDialog', options) @@ -250,8 +263,8 @@ export const openUrl = url => { * 设置标题 */ let dom_title = document.getElementsByTagName('title')[0] -export const setTitle = title => { - dom_title.innerText = title || '洛雪音乐助手' +export const setTitle = (title = '洛雪音乐助手') => { + dom_title.innerText = title }