From 1e53508d67512c58c60e04ab20445ff7ab6afcc9 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 26 Mar 2023 12:00:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=81=9A=E5=90=88=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=B7=B3=E8=BD=AC=E5=88=B0=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E9=A1=B5=E5=90=8E=E7=94=B1=E4=BA=8E=E5=88=97=E8=A1=A8=E6=98=AF?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E5=AF=BC=E8=87=B4=E7=BF=BB=E9=A1=B5=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E9=9A=90=E8=97=8F=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88?= =?UTF-8?q?#1217=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/store/leaderboard/action.ts | 5 +++-- src/renderer/store/search/action.ts | 3 ++- src/renderer/store/search/music/action.ts | 21 +++++++++++--------- src/renderer/store/search/songlist/action.ts | 15 ++++++++------ src/renderer/store/songList/action.ts | 10 ++++++---- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/renderer/store/leaderboard/action.ts b/src/renderer/store/leaderboard/action.ts index 832ff324..bc0e9343 100644 --- a/src/renderer/store/leaderboard/action.ts +++ b/src/renderer/store/leaderboard/action.ts @@ -14,12 +14,13 @@ export const setListDetail = (result: ListDetailInfo, id: string, page: number) listDetailInfo.list = markRaw([...result.list]) listDetailInfo.id = id listDetailInfo.source = result.source - listDetailInfo.total = result.total + if (page == 1 || (result.total && result.list.length)) listDetailInfo.total = result.total + else listDetailInfo.total = result.limit * page listDetailInfo.limit = result.limit listDetailInfo.page = page if (result.list.length) listDetailInfo.noItemLabel = '' - else listDetailInfo.noItemLabel = window.i18n.t('no_item') + else if (page == 1) listDetailInfo.noItemLabel = window.i18n.t('no_item') } export const clearListDetail = () => { listDetailInfo.list = [] diff --git a/src/renderer/store/search/action.ts b/src/renderer/store/search/action.ts index 5855754e..f6ff4539 100644 --- a/src/renderer/store/search/action.ts +++ b/src/renderer/store/search/action.ts @@ -20,7 +20,7 @@ const saveSearchHistoryListThrottle = throttle((list: LX.List.SearchHistoryList) export const getHistoryList = async() => { - if (isInitedSearchHistory) return + if (isInitedSearchHistory || historyList.length) return historyList.push(...(await getSearchHistoryList() ?? [])) isInitedSearchHistory = true } @@ -28,6 +28,7 @@ export const addHistoryWord = async(word: string) => { if (!appSetting['search.isShowHistorySearch']) return if (!isInitedSearchHistory) await getHistoryList() let index = historyList.indexOf(word) + if (index == 0) return if (index > -1) historyList.splice(index, 1) if (historyList.length >= 15) historyList.splice(14, historyList.length - 14) historyList.unshift(word) diff --git a/src/renderer/store/search/music/action.ts b/src/renderer/store/search/music/action.ts index 6472a10e..5537a2b8 100644 --- a/src/renderer/store/search/music/action.ts +++ b/src/renderer/store/search/music/action.ts @@ -34,25 +34,27 @@ const handleSortList = (list: LX.Music.MusicInfo[], keyword: string) => { const setLists = (results: SearchResult[], page: number, text: string): LX.Music.MusicInfo[] => { let pages = [] - let total = 0 - // let limit = 0 + let totals = [] + let limit = 0 let list = [] for (const source of results) { maxPages[source.source] = source.allPage + limit = Math.max(source.limit, limit) if (source.allPage < page) continue list.push(...source.list) pages.push(source.allPage) - total += source.total - // limit = Math.max(source.limit, limit) + totals.push(source.total) } list = deduplicationList(list.map(s => markRaw(toNewMusicInfo(s)))) let listInfo = listInfos.all - listInfo.maxPage = Math.max(...pages) - listInfo.total = total + listInfo.maxPage = Math.max(0, ...pages) + const total = Math.max(0, ...totals) + if (page == 1 || (total && list.length)) listInfo.total = total + else listInfo.total = limit * page // listInfo.limit = limit listInfo.page = page listInfo.list = handleSortList(list, text) - if (text && !list.length) listInfo.noItemLabel = window.i18n.t('no_item') + if (text && !list.length && page == 1) listInfo.noItemLabel = window.i18n.t('no_item') else listInfo.noItemLabel = '' return listInfo.list } @@ -61,11 +63,12 @@ const setList = (datas: SearchResult, page: number, text: string): LX.Music.Musi // console.log(datas.source, datas.list) let listInfo = listInfos[datas.source] as ListInfo listInfo.list = deduplicationList(datas.list.map(s => markRaw(toNewMusicInfo(s)))) - listInfo.total = datas.total + if (page == 1 || (datas.total && datas.list.length)) listInfo.total = datas.total + else listInfo.total = datas.limit * page listInfo.maxPage = datas.allPage listInfo.page = page listInfo.limit = datas.limit - if (text && !datas.list.length) listInfo.noItemLabel = window.i18n.t('no_item') + if (text && !datas.list.length && page == 1) listInfo.noItemLabel = window.i18n.t('no_item') else listInfo.noItemLabel = '' return listInfo.list } diff --git a/src/renderer/store/search/songlist/action.ts b/src/renderer/store/search/songlist/action.ts index 4a84b062..d00ca72f 100644 --- a/src/renderer/store/search/songlist/action.ts +++ b/src/renderer/store/search/songlist/action.ts @@ -36,22 +36,24 @@ let maxTotals: Partial> = { } const setLists = (results: SearchResult[], page: number, text: string): ListInfoItem[] => { let totals = [] - // let limit = 0 + let limit = 0 let list = [] for (const source of results) { list.push(...source.list) totals.push(source.total) maxTotals[source.source] = source.total maxPages[source.source] = Math.ceil(source.total / source.limit) - // limit = Math.max(source.limit, limit) + limit = Math.max(source.limit, limit) } markRawList(list) let listInfo = listInfos.all - listInfo.total = Math.max(...totals) + const total = Math.max(0, ...totals) + if (page == 1 || (total && list.length)) listInfo.total = total + else listInfo.total = limit * page listInfo.page = page listInfo.list = handleSortList(list, text) - if (text && !list.length) listInfo.noItemLabel = window.i18n.t('no_item') + if (text && !list.length && page == 1) listInfo.noItemLabel = window.i18n.t('no_item') else listInfo.noItemLabel = '' return listInfo.list } @@ -60,10 +62,11 @@ const setList = (datas: SearchResult, page: number, text: string): ListInfoItem[ // console.log(datas.source, datas.list) let listInfo = listInfos[datas.source] as SearchListInfo listInfo.list = markRawList(datas.list) - listInfo.total = datas.total + if (page == 1 || (datas.total && datas.list.length)) listInfo.total = datas.total + else listInfo.total = datas.limit * page listInfo.page = page listInfo.limit = datas.limit - if (text && !datas.list.length) listInfo.noItemLabel = window.i18n.t('no_item') + if (text && !datas.list.length && page == 1) listInfo.noItemLabel = window.i18n.t('no_item') else listInfo.noItemLabel = '' return listInfo.list } diff --git a/src/renderer/store/songList/action.ts b/src/renderer/store/songList/action.ts index 2638d042..b218a9d7 100644 --- a/src/renderer/store/songList/action.ts +++ b/src/renderer/store/songList/action.ts @@ -33,25 +33,27 @@ export const clearList = () => { export const setList = (result: ListInfo, tagId: string, sortId: string, page: number) => { listInfo.list = markRaw([...result.list]) - listInfo.total = result.total + if (page == 1 || (result.total && result.list.length)) listInfo.total = result.total + else listInfo.total = result.limit * page listInfo.limit = result.limit listInfo.page = page listInfo.source = result.source listInfo.tagId = tagId listInfo.sortId = sortId if (result.list.length) listInfo.noItemLabel = '' - else listInfo.noItemLabel = window.i18n.t('no_item') + else if (page == 1) listInfo.noItemLabel = window.i18n.t('no_item') } export const setListDetail = (result: ListDetailInfo, id: string, page: number) => { listDetailInfo.list = markRaw([...result.list]) listDetailInfo.id = id listDetailInfo.source = result.source - listDetailInfo.total = result.total + if (page == 1 || (result.total && result.list.length)) listDetailInfo.total = result.total + else listDetailInfo.total = result.limit * page listDetailInfo.limit = result.limit listDetailInfo.page = page listDetailInfo.info = markRaw({ ...result.info }) if (result.list.length) listDetailInfo.noItemLabel = '' - else listDetailInfo.noItemLabel = window.i18n.t('no_item') + else if (page == 1) listDetailInfo.noItemLabel = window.i18n.t('no_item') } export const setSelectListInfo = (info: ListInfoItem) => {