修复聚合搜索跳转到最后一页后由于列表是空的导致翻页组件隐藏的问题(#1217)

pull/1295/head
lyswhut 2023-03-26 12:00:20 +08:00
parent b8fca59cbb
commit 1e53508d67
5 changed files with 32 additions and 22 deletions

View File

@ -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 = []

View File

@ -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)

View File

@ -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
}

View File

@ -36,22 +36,24 @@ let maxTotals: Partial<Record<LX.OnlineSource, number>> = {
}
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
}

View File

@ -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) => {