fix : 优化公告部分的数据加载逻辑
This commit is contained in:
parent
15d42c2df1
commit
b027a8f8ce
@ -112,7 +112,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tips">下拉加载后续10条,共计30条</div>
|
||||
<div class="tips">{{ loadMoreText }}</div>
|
||||
|
||||
<div class="bigAds" v-if="ads1Show">
|
||||
<div class="bigAdsCon">
|
||||
@ -208,6 +208,7 @@ export default {
|
||||
page_size: 10,
|
||||
page_num: 1,
|
||||
flag: false,
|
||||
loadMoreText: "下拉加载后续10条,共计30条",
|
||||
};
|
||||
},
|
||||
async onLoad(options) {
|
||||
@ -248,7 +249,10 @@ export default {
|
||||
onReachBottom() {
|
||||
if (this.flag) {
|
||||
this.page_num++;
|
||||
this.getCategoryList();
|
||||
const currentItem = this.categoryList[this.selectedTab];
|
||||
if (currentItem) {
|
||||
this.selectTab(this.selectedTab, currentItem);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -481,6 +485,12 @@ export default {
|
||||
},
|
||||
|
||||
async selectTab(index, item) {
|
||||
const isTabChange = this.selectedTab !== index;
|
||||
if (isTabChange) {
|
||||
this.page_num = 1;
|
||||
this.infoList = [];
|
||||
this.loadMoreText = "下拉加载后续10条,共计30条";
|
||||
}
|
||||
this.selectedTab = index;
|
||||
console.log("选中的tab:", index);
|
||||
const res = await request(apiArr.infoPage, "POST", {
|
||||
@ -491,20 +501,34 @@ export default {
|
||||
page_num: this.page_num,
|
||||
page_size: this.page_size,
|
||||
});
|
||||
if (res.rows && res.rows.length == this.page_size) {
|
||||
this.flag = true;
|
||||
} else {
|
||||
this.flag = false;
|
||||
}
|
||||
res.rows = res.rows.map((item) => {
|
||||
return {
|
||||
|
||||
// 处理数据
|
||||
const newData = res.rows.map((item) => ({
|
||||
...item,
|
||||
list_image: picUrl + item.list_image,
|
||||
};
|
||||
});
|
||||
this.infoList.splice(0, this.infoList.length);
|
||||
}));
|
||||
|
||||
this.infoList = this.infoList.concat(res.rows);
|
||||
// 判断是否还有更多数据
|
||||
const hasMore = res.rows.length === this.page_size;
|
||||
// 限制最多3页
|
||||
this.flag = hasMore;
|
||||
|
||||
// 更新数据
|
||||
if (isTabChange) {
|
||||
this.infoList = newData;
|
||||
} else {
|
||||
this.infoList = this.infoList.concat(newData);
|
||||
}
|
||||
|
||||
// 更新提示文本
|
||||
if (this.infoList.length > 10 && !hasMore) {
|
||||
uni.showToast({
|
||||
title: "没有更多了",
|
||||
icon: "none",
|
||||
});
|
||||
} else {
|
||||
this.loadMoreText = `下拉加载后续10条`;
|
||||
}
|
||||
},
|
||||
|
||||
detail(e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user