From 36d69da3b78597f1991217da31f5999f45ed1915 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 19 Oct 2019 11:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=AD=8C=E5=8D=95=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=88=97=E8=A1=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/store/modules/songList.js | 42 ++++++++++++++++++++++--- src/renderer/utils/music/bd/songList.js | 2 +- src/renderer/utils/music/kw/songList.js | 2 +- src/renderer/utils/music/mg/songList.js | 2 +- src/renderer/views/SongList.vue | 15 +++++++++ 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 564e40be..85e09599 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -9,6 +9,7 @@ - 优化搜索框搜索体验 - 优化音量条交互视觉效果 +- 缓存歌单详情列表数据 #### 修复 diff --git a/src/renderer/store/modules/songList.js b/src/renderer/store/modules/songList.js index f493fb5b..36ee4058 100644 --- a/src/renderer/store/modules/songList.js +++ b/src/renderer/store/modules/songList.js @@ -1,6 +1,7 @@ import music from '../../utils/music' const sortList = {} const sources = [] +const cache = new Map() for (const source of music.sources) { const songList = music[source.id].songList if (!songList) continue @@ -61,16 +62,45 @@ const actions = { let tabId = rootState.setting.songList.tagInfo.id let sortId = rootState.setting.songList.sortId // console.log(sortId) - let key = `${source}${sortId}${tabId}${page}` - if (state.list.list.length && state.list.key == key) return true - return music[source].songList.getList(sortId, tabId, page).then(result => commit('setList', { result, key, page })) + let key = `slist__${source}__${sortId}__${tabId}__${page}` + if (state.list.list.length && state.list.key == key) return + return (cache.has(key) ? Promise.resolve(cache.get(key)) : music[source].songList.getList(sortId, tabId, page)).then(result => commit('setList', { result, key, page })) }, getListDetail({ state, rootState, commit }, { id, page }) { let source = rootState.setting.songList.source - let key = `${source}${id}${page}` + let key = `sdetail__${source}__${id}__${page}` if (state.listDetail.list.length && state.listDetail.key == key) return true - return music[source].songList.getListDetail(id, page).then(result => commit('setListDetail', { result, key, page })) + return (cache.has(key) ? Promise.resolve(cache.get(key)) : music[source].songList.getListDetail(id, page)).then(result => commit('setListDetail', { result, key, page })) }, +/* getListDetailAll({ state, rootState }, id) { + let source = rootState.setting.songList.source + let key = `sdetail__${source}__${id}__all` + if (cache.has(key)) return Promise.resolve(cache.get(key)) + music[source].songList.getListDetail(id, 1).then(result => { + let data = { list: result.list, id } + if (result.total <= result.limit) { + data = { list: result.list, id } + cache.set(key, data) + return data + } + + let maxPage = Math.ceil(result.total / result.limit) + const loadDetail = (loadPage = 1) => { + let task = [] + let loadNum = 0 + while (loadPage <= maxPage && loadNum < 3) { + task.push(music[source].songList.getListDetail(id, ++loadPage)) + loadNum++ + } + return loadPage == maxPage + ? Promise.all(task) + : Promise.all(task).then(result => loadDetail(loadPage).then(result2 => [...result, ...result2])) + } + return loadDetail().then(result2 => { + console.log(result2) + }) + }) + }, */ } // mitations @@ -84,6 +114,7 @@ const mutations = { state.list.limit = result.limit state.list.page = page state.list.key = key + cache.set(key, result) }, setListDetail(state, { result, key, page }) { state.listDetail.list = result.list @@ -92,6 +123,7 @@ const mutations = { state.listDetail.page = page state.listDetail.key = key state.listDetail.info = result.info || {} + cache.set(key, result) }, setVisibleListDetail(state, bool) { if (!bool) state.listDetail.list = [] diff --git a/src/renderer/utils/music/bd/songList.js b/src/renderer/utils/music/bd/songList.js index 04d8d1a0..eb12a88d 100644 --- a/src/renderer/utils/music/bd/songList.js +++ b/src/renderer/utils/music/bd/songList.js @@ -8,7 +8,7 @@ export default { _requestObj_listRecommend: null, _requestObj_listDetail: null, limit_list: 20, - limit_song: 25, + limit_song: 1000, successCode: 22000, sortList: [ { diff --git a/src/renderer/utils/music/kw/songList.js b/src/renderer/utils/music/kw/songList.js index 94d1dd77..3c682e9b 100644 --- a/src/renderer/utils/music/kw/songList.js +++ b/src/renderer/utils/music/kw/songList.js @@ -8,7 +8,7 @@ export default { _requestObj_list: null, _requestObj_listDetail: null, limit_list: 25, - limit_song: 100, + limit_song: 1000, successCode: 200, sortList: [ { diff --git a/src/renderer/utils/music/mg/songList.js b/src/renderer/utils/music/mg/songList.js index b4744d09..be47d553 100644 --- a/src/renderer/utils/music/mg/songList.js +++ b/src/renderer/utils/music/mg/songList.js @@ -6,7 +6,7 @@ export default { _requestObj_list: null, _requestObj_listDetail: null, limit_list: 10, - limit_song: 100, + limit_song: 1000, successCode: '000000', sortList: [ { diff --git a/src/renderer/views/SongList.vue b/src/renderer/views/SongList.vue index 94589418..e5699324 100644 --- a/src/renderer/views/SongList.vue +++ b/src/renderer/views/SongList.vue @@ -10,6 +10,10 @@ h3(:title="listDetail.info.name || selectListInfo.name") {{listDetail.info.name || selectListInfo.name}} p(:title="listDetail.info.desc || selectListInfo.desc") {{listDetail.info.desc || selectListInfo.desc}} div(:class="$style.songListHeaderRight") + //- material-btn(:class="$style.closeDetailButton" :disabled="detailLoading" @click="addSongListDetail") 添加 + //- |   + //- material-btn(:class="$style.closeDetailButton" :disabled="detailLoading" @click="playSongListDetail") 播放 + //- |   material-btn(:class="$style.closeDetailButton" @click="hideListDetail") 返回 material-song-list(v-model="selectdData" @action="handleSongListAction" :source="source" :page="listDetail.page" :limit="listDetail.limit" :total="listDetail.total" :list="listDetail.list") transition(enter-active-class="animated-fast fadeIn" leave-active-class="animated-fast fadeOut") @@ -64,6 +68,7 @@ export default { isShowListAdd: false, isShowListAddMultiple: false, importSongListText: '', + // detailLoading: true, } }, computed: { @@ -234,6 +239,7 @@ export default { this.isShowDownloadMultiple = false }, handleItemClick(index) { + // this.detailLoading = true this.setSelectListInfo(this.listData.list[index]) this.setVisibleListDetail(true) this.clearListDetail() @@ -339,6 +345,15 @@ export default { } this.importSongListText = text.replace(regx, '$1') }, + /* addSongListDetail() { + // this.detailLoading = true + // this.getListDetailAll(this.selectListInfo.id).then(() => { + // this.detailLoading = false + // }) + }, + playSongListDetail() { + + }, */ }, }