修改:首屏未占满时自动再加载一页

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
马丁 2026-07-23 23:22:33 +08:00
parent 4c77d3080c
commit d6f1cd956e

View File

@ -450,9 +450,12 @@ async function loadEvents(page: number, append: boolean, keyword?: string) {
pageSize: eventPageSize.value, pageSize: eventPageSize.value,
}) })
nextTick(() => { // /
if (!append) {
}) nextTick(() => {
fillViewportIfNeeded()
})
}
} catch (e) { } catch (e) {
console.log(e) console.log(e)
if (!append) eventList.value = [] if (!append) eventList.value = []
@ -480,6 +483,21 @@ function getMainScrollEl(): Element | null {
return document.querySelector('[data-main-scroll]') return document.querySelector('[data-main-scroll]')
} }
/** 内容未撑满滚动容器可视高度时返回 true */
function isContentShorterThanViewport(): boolean {
const el = getMainScrollEl()
if (el) {
return el.scrollHeight <= el.clientHeight + SCROLL_LOAD_THRESHOLD
}
return document.documentElement.scrollHeight <= window.innerHeight + SCROLL_LOAD_THRESHOLD
}
/** 首屏加载后若未占满屏幕且还有更多数据,再触发一次 loadMore */
function fillViewportIfNeeded() {
if (loadingMore.value || eventList.value.length === 0 || noMoreEvents.value) return
if (isContentShorterThanViewport()) loadMore()
}
function checkScrollLoad() { function checkScrollLoad() {
if (loadingMore.value || eventList.value.length === 0 || noMoreEvents.value) return if (loadingMore.value || eventList.value.length === 0 || noMoreEvents.value) return
const el = getMainScrollEl() const el = getMainScrollEl()