From 4d7d92759fc273b935c3de7eda52c9608ad98ed5 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 19 Mar 2022 16:25:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=BB=A4id=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E6=AD=8C=E6=9B=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/store/modules/leaderboard.js | 6 +++++- src/renderer/store/modules/search.js | 5 ++++- src/renderer/store/modules/songList.js | 7 +++++-- src/renderer/utils/index.js | 10 ++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/renderer/store/modules/leaderboard.js b/src/renderer/store/modules/leaderboard.js index 39573341..ef25b2d8 100644 --- a/src/renderer/store/modules/leaderboard.js +++ b/src/renderer/store/modules/leaderboard.js @@ -1,5 +1,7 @@ import music from '../../utils/music' import { markRawList } from '@renderer/utils/vueTools' +import { deduplicationList } from '@renderer/utils' + const sourceList = {} const sources = [] const cache = new Map() @@ -57,6 +59,7 @@ const actions = { // : music[source].leaderboard.getList(bangId, page) // ).then(result => commit('setList', { result, key })) return music[source].leaderboard.getList(bangId, page).then(result => { + result.list = deduplicationList(result.list) cache.set(key, result) listInfo.list = markRawList(result.list) listInfo.total = result.total @@ -75,6 +78,7 @@ const actions = { return cache.has(key) ? Promise.resolve(cache.get(key)) : music[source].leaderboard.getList(bangId, page).then(result => { + result.list = markRawList(deduplicationList(result.list)) cache.set(key, result) return result }) @@ -89,7 +93,7 @@ const actions = { : loadData(id, loadPage).then(result1 => load(++loadPage).then(result2 => [...result1.list, ...result2])) } return load().then(result2 => [...result.list, ...result2]) - }) + }).then(list => deduplicationList(list)) }, } diff --git a/src/renderer/store/modules/search.js b/src/renderer/store/modules/search.js index ddc81abd..509c9d3d 100644 --- a/src/renderer/store/modules/search.js +++ b/src/renderer/store/modules/search.js @@ -1,5 +1,6 @@ import music from '../../utils/music' import { markRawList } from '@renderer/utils/vueTools' +import { deduplicationList } from '@renderer/utils' const sources = [] const sourceList = {} @@ -85,7 +86,7 @@ sources.push({ }) // state -const state = { +const state = window.state = { sourceList, list: [], text: '', @@ -151,6 +152,7 @@ const mutations = { }, setList(state, datas) { let source = state.sourceList[datas.source] + datas.list = deduplicationList(datas.list) source.list = markRawList(datas.list) source.total = datas.total source.allPage = datas.allPage @@ -170,6 +172,7 @@ const mutations = { total += source.total // limit = Math.max(source.limit, limit) } + list = deduplicationList(list) state.allPage = Math.max(...pages) state.total = total state.limit = limit diff --git a/src/renderer/store/modules/songList.js b/src/renderer/store/modules/songList.js index 2ebb11d5..a86e043b 100644 --- a/src/renderer/store/modules/songList.js +++ b/src/renderer/store/modules/songList.js @@ -1,5 +1,6 @@ import music from '../../utils/music' import { markRawList } from '@renderer/utils/vueTools' +import { deduplicationList } from '@renderer/utils' const sortList = {} const sources = [] @@ -91,6 +92,7 @@ const actions = { ? Promise.resolve(cache.get(key)) : music[source]?.songList.getListDetail(id, page).then(result => ({ ...result, list: filterList(result.list) })) ).then(result => { + result.list = markRawList(deduplicationList(result.list)) commit('setListDetail', { result, key, source, id, page }) return result.list }) @@ -103,6 +105,7 @@ const actions = { return cache.has(key) ? Promise.resolve(cache.get(key)) : music[source]?.songList.getListDetail(id, page).then(result => { + result.list = markRawList(deduplicationList(result.list)) cache.set(key, result) return result }) ?? Promise.reject(new Error('source not found')) @@ -117,7 +120,7 @@ const actions = { : loadData(id, loadPage).then(result1 => loadDetail(++loadPage).then(result2 => [...result1.list, ...result2])) } return loadDetail().then(result2 => [...result.list, ...result2]).then(list => filterList(list)) - }) + }).then(list => deduplicationList(list)) }, } @@ -139,7 +142,7 @@ const mutations = { cache.set(key, result) }, setListDetail(state, { result, key, source, id, page }) { - state.listDetail.list = markRawList(result.list) + state.listDetail.list = result.list state.listDetail.id = id state.listDetail.source = source state.listDetail.total = result.total diff --git a/src/renderer/utils/index.js b/src/renderer/utils/index.js index bcc16e18..659af08d 100644 --- a/src/renderer/utils/index.js +++ b/src/renderer/utils/index.js @@ -571,3 +571,13 @@ export const getFontSizeWithScreen = (screenWidth = window.innerWidth) => { ? 20 : screenWidth <= 2560 ? 20 : 22 } + + +export const deduplicationList = list => { + const ids = new Set() + return list.filter(s => { + if (ids.has(s.songmid)) return false + ids.add(s.songmid) + return true + }) +}