fix: 中奖名单公示页搜索修复——输入关键字时自动按大页拉全当期名单再本地过滤,修复未翻页的中奖者(如王球莲)搜索无结果的问题;接口无姓名参数,pageSize=500×N 循环实测 4 请求 2000 条,拉全失败静默降级

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jacobxu666
2026-09-29 16:58:42 +08:00
co-authored by Claude Fable 5
parent 2a6b86977c
commit 748c4563fd
2 changed files with 105 additions and 1 deletions
+53 -1
View File
@@ -81,7 +81,11 @@ export default {
// xuchao: 页码改为按期维护(原单一 pageNo 在切期后会被沿用,导致同一页重复追加/跳页)
pageNos: {},
pageSize: 10,
// xuchao: 搜索触发的全量拉取用大页尺寸(列表接口仅支持分页参数,无姓名检索)
pageSizeFull: 500,
totals: {},
fullLoaded: {},
loadingAll: {},
totalWinners: 0,
inFlight: 0,
loadStatusMap: {},
@@ -104,6 +108,15 @@ export default {
return this.loadStatusMap[this.currentTab] || 'nomore'
}
},
watch: {
// xuchao: 输入关键字即后台拉全当期名单,修复"没翻到的人物搜索无结果"
keyword(val) {
clearTimeout(this._kwTimer)
if (val && val.trim() && !this.fullLoaded[this.currentTab]) {
this._kwTimer = setTimeout(() => this.loadAll(this.currentTab), 400)
}
}
},
onLoad() {
this.loadDates()
},
@@ -155,6 +168,8 @@ export default {
pageSize: this.pageSize,
drawDate: drawDate
}).then(res => {
// xuchao: 全量拉取已就绪/进行中时,旧的10条分页响应直接丢弃,避免覆盖全量列表
if (this.fullLoaded[tabIndex] || this.loadingAll[tabIndex]) return
if (res.errcode === 0 && res.data) {
const list = res.data.list || []
const prev = this.winnerData[tabIndex] || []
@@ -177,12 +192,48 @@ export default {
},
loadMore() {
const tab = this.currentTab
if (this.loadingAll[tab]) return
const total = this.totals[tab] || 0
const len = (this.winnerData[tab] || []).length
if (len < total && this.inFlight === 0) {
this.loadWinnerList(tab, (this.pageNos[tab] || 1) + 1)
}
},
// xuchao: 按大页把当期名单一次拉全,搜索即可命中未翻到的人;完成后整期替换并标记 fullLoaded
loadAll(tabIndex) {
const tab = this.tabs[tabIndex]
if (!tab || this.fullLoaded[tabIndex] || this.loadingAll[tabIndex]) return
this.$set(this.loadingAll, tabIndex, true)
this.$set(this.loadStatusMap, tabIndex, 'loading')
const acc = []
const pull = (pageNo) => this.$u.api.getWinnerList({
pageNo: pageNo,
pageSize: this.pageSizeFull,
drawDate: tab.date
}).then(res => {
if (res.errcode !== 0 || !res.data) return
const list = res.data.list || []
const total = res.data.total || 0
acc.push(...list)
this.$set(this.totals, tabIndex, total)
if (list.length > 0 && acc.length < total && pageNo < 50) return pull(pageNo + 1)
})
pull(1).then(() => {
if (acc.length > 0) {
this.$set(this.winnerData, tabIndex, acc)
this.$set(this.fullLoaded, tabIndex, true)
this.$set(this.pageNos, tabIndex, Math.ceil(acc.length / this.pageSizeFull))
}
this.totalWinners = Object.values(this.totals).reduce((s, n) => s + n, 0)
}).catch(() => {
// 拉全失败静默降级为已加载部分可搜
}).finally(() => {
this.$set(this.loadingAll, tabIndex, false)
const len = (this.winnerData[tabIndex] || []).length
const total = this.totals[tabIndex] || 0
this.$set(this.loadStatusMap, tabIndex, len === 0 || len >= total ? 'nomore' : 'loadmore')
})
},
switchTab(index) {
this.currentTab = index
// xuchao: 不再重置全局 pageNo(各期游标自带);空列表补拉首页时允许并发,
@@ -204,7 +255,8 @@ export default {
}
},
onSearch() {
// 前端过滤,无需重新请求
// xuchao: 点搜索立即确保当期全量已拉取(过滤仍在前端本地完成)
if (!this.fullLoaded[this.currentTab]) this.loadAll(this.currentTab)
}
}
}