fix: refresh feed when switching channels

This commit is contained in:
hajimi
2026-08-04 00:39:34 +08:00
parent a576b09372
commit bdab4f5019
89 changed files with 122 additions and 92 deletions
+17 -9
View File
@@ -196,6 +196,7 @@ let focusMatchRequestId = 0
let fallbackFocusMatchData: any = null
let fallbackFocusMatchLoadedAt = 0
let fallbackFocusMatchPromise: Promise<any> | null = null
let feedRequestId = 0
const primaryChannels = computed(() => {
return allChannels.value
@@ -418,15 +419,17 @@ const reloadFeed = () => {
noMore.value = false
feedList.value = []
featuredImageFailed.value = false
fetchFeedList()
fetchFeedList(true)
}
const fetchFeedList = async () => {
if (loading.value || noMore.value) return
const fetchFeedList = async (force = false) => {
if ((!force && loading.value) || noMore.value) return
const requestId = ++feedRequestId
const requestPage = pageNo.value
loading.value = true
try {
const params: Record<string, any> = {
page_no: pageNo.value,
page_no: requestPage,
page_size: pageSize
}
const currentChannelItem = allChannels.value[currentChannel.value]
@@ -438,8 +441,9 @@ const fetchFeedList = async () => {
params.cid = currentChannelItem.id
}
const { lists, count } = await getArticleList(params)
if (requestId !== feedRequestId) return
const newList = lists || []
if (pageNo.value === 1) {
if (requestPage === 1) {
feedList.value = newList
featuredImageFailed.value = false
} else {
@@ -448,12 +452,16 @@ const fetchFeedList = async () => {
if (feedList.value.length >= count || newList.length < pageSize) {
noMore.value = true
}
pageNo.value++
pageNo.value = requestPage + 1
} catch (error) {
console.log('首页资讯加载失败=>', error)
uni.showToast({ title: '加载失败,请稍后重试', icon: 'none' })
if (requestId === feedRequestId) {
console.log('首页资讯加载失败=>', error)
uni.showToast({ title: '加载失败,请稍后重试', icon: 'none' })
}
} finally {
loading.value = false
if (requestId === feedRequestId) {
loading.value = false
}
}
}