Fix:5953 【商城小程序】使用指南页面切换分类类型时页面刷新,短暂展示“暂无数据”,需优化页面切换刷新效果

This commit is contained in:
linxi
2026-09-04 11:27:06 +08:00
parent ed5792b860
commit 6e14b8dd69
+26 -4
View File
@@ -41,7 +41,9 @@
</view> </view>
</view> </view>
<view class="v4-nodata" v-show="!hasList"> <view class="loading-more" v-show="isWait">加载中...</view>
<view class="v4-nodata" v-show="showEmpty">
<image src="@/static/images/img_nodata.png" mode="scaleToFill"/> <image src="@/static/images/img_nodata.png" mode="scaleToFill"/>
<view class="text">暂无数据</view> <view class="text">暂无数据</view>
</view> </view>
@@ -73,12 +75,16 @@ export default {
leftHeight: 0, leftHeight: 0,
rightHeight: 0, rightHeight: 0,
isWait: false, isWait: false,
requestId: 0,
pageKeyId: Object.freeze('findVideoList') pageKeyId: Object.freeze('findVideoList')
} }
}, },
computed: { computed: {
hasList() { hasList() {
return this.leftList.length + this.rightList.length > 0 return this.leftList.length + this.rightList.length > 0
},
showEmpty() {
return !this.isWait && !this.hasList
} }
}, },
onLoad(options) { onLoad(options) {
@@ -106,7 +112,9 @@ export default {
changeType(item) { changeType(item) {
this.type = item.value this.type = item.value
this.page = 1 this.page = 1
this.resetList() // 使进行中的请求失效并解锁,避免切换时被上一次请求阻塞
this.requestId++
this.isWait = false
this.fetchList() this.fetchList()
}, },
resetList() { resetList() {
@@ -117,6 +125,7 @@ export default {
}, },
async fetchList() { async fetchList() {
if (this.isWait) return if (this.isWait) return
const requestId = ++this.requestId
this.isWait = true this.isWait = true
const params = { const params = {
type: this.type, type: this.type,
@@ -125,13 +134,17 @@ export default {
} }
try { try {
const res = await getVideoList(params) const res = await getVideoList(params)
// 请求已被更新的请求(如切换分类)取代,丢弃本次结果
if (requestId !== this.requestId) return
if (res.status === 200) { if (res.status === 200) {
const items = res.data const items = res.data
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
items[i].hide = true items[i].hide = true
} }
// 并行获取所有封面高度 // 并行获取所有封面高度,完成后一次性替换列表,避免闪现空列表
const heights = await Promise.all(items.map(item => this.getImageHeight(item.cover))) const heights = await Promise.all(items.map(item => this.getImageHeight(item.cover)))
if (requestId !== this.requestId) return
if (this.page === 1) this.resetList()
items.forEach((item, i) => { items.forEach((item, i) => {
this.pushToColumn(item, heights[i] + TEXT_HEIGHT) this.pushToColumn(item, heights[i] + TEXT_HEIGHT)
}) })
@@ -139,7 +152,9 @@ export default {
} catch (e) { } catch (e) {
// 忽略请求或图片尺寸获取失败 // 忽略请求或图片尺寸获取失败
} finally { } finally {
this.isWait = false if (requestId === this.requestId) {
this.isWait = false
}
} }
}, },
getImageHeight(src) { getImageHeight(src) {
@@ -252,4 +267,11 @@ export default {
} }
} }
} }
.loading-more {
padding: 24rpx 0;
text-align: center;
font-size: 24rpx;
color: #999;
}
</style> </style>