From b6107b728194be2436a1520b281e56b0ef22a57e Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 21 Feb 2021 16:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/rendererEvents/playList.js | 14 +++++++--- src/renderer/App.vue | 40 +++++++++++++++-------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/main/rendererEvents/playList.js b/src/main/rendererEvents/playList.js index a22c5e4f..86a90d89 100644 --- a/src/main/rendererEvents/playList.js +++ b/src/main/rendererEvents/playList.js @@ -26,12 +26,18 @@ mainHandle(ipcMainWindowNames.get_playlist, async(event, isIgnoredError = false) } }) +const handleSaveList = ({ defaultList, loveList, userList }) => { + if (!electronStore_list) return + let data = {} + if (defaultList != null) data.defaultList = defaultList + if (loveList != null) data.loveList = loveList + if (userList != null) data.userList = userList + electronStore_list.set(data) +} mainOn(ipcMainWindowNames.save_playlist, (event, { type, data }) => { switch (type) { - case 'defaultList': - case 'loveList': - case 'userList': - electronStore_list && electronStore_list.set(type, data) + case 'myList': + handleSaveList(data) break case 'downloadList': electronStore_downloadList && electronStore_downloadList.set('list', data) diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 161531cb..3364102a 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -37,6 +37,20 @@ dnscache({ cachesize: 1000, }) +const listThrottle = (fn, delay = 100) => { + let timer = null + let _data = {} + return function(data) { + Object.assign(_data, data) + if (timer) return + timer = setTimeout(() => { + timer = null + fn.call(this, _data) + _data = {} + }, delay) + } +} + export default { data() { return { @@ -70,24 +84,12 @@ export default { }), }, created() { - this.saveDefaultList = throttle(n => { + this.saveMyList = listThrottle(data => { rendererSend(NAMES.mainWindow.save_playlist, { - type: 'defaultList', - data: n, + type: 'myList', + data, }) - }, 500) - this.saveLoveList = throttle(n => { - rendererSend(NAMES.mainWindow.save_playlist, { - type: 'loveList', - data: n, - }) - }, 500) - this.saveUserList = throttle(n => { - rendererSend(NAMES.mainWindow.save_playlist, { - type: 'userList', - data: n, - }) - }, 500) + }, 300) this.saveDownloadList = throttle(n => { rendererSend(NAMES.mainWindow.save_playlist, { type: 'downloadList', @@ -115,19 +117,19 @@ export default { }, defaultList: { handler(n) { - this.saveDefaultList(n) + this.saveMyList({ defaultList: n }) }, deep: true, }, loveList: { handler(n) { - this.saveLoveList(n) + this.saveMyList({ loveList: n }) }, deep: true, }, userList: { handler(n) { - this.saveUserList(n) + this.saveMyList({ userList: n }) }, deep: true, },