fix(chat): 优化聊天页面加载和滚动逻辑

This commit is contained in:
yangzhe 2025-12-17 16:42:52 +08:00
parent 3afd93a79e
commit 31af22face
2 changed files with 28 additions and 32 deletions

View File

@ -303,12 +303,9 @@ export default {
PageSize: this.PageSize,
})
.then((list) => {
console.log(list.length, "加载对话消息");
const len = Array.isArray(list) ? list.length : 0;
if (len === 0 && len < this.PageSize) {
if (len === 0 && this.PageIndex === 1) {
this.noMoreData = true;
console.log("没有更多数据了", this.noMoreData);
}
return list;
});
@ -342,43 +339,42 @@ export default {
return;
}
this.PageIndex = nextPageIndex;
this.$nextTick(() => {
const query = uni.createSelectorQuery().in(this);
query
.select(".chat-content")
.boundingClientRect((rect) => {
const afterHeight = Number(rect && rect.height) || 0;
const delta = afterHeight - beforeHeight;
if (delta > 0) {
this.scrollTop = beforeTop + delta;
}
})
.exec();
});
// this.$nextTick(() => {
// const query = uni.createSelectorQuery().in(this);
// query
// .select(".chat-content")
// .boundingClientRect((rect) => {
// const afterHeight = Number(rect && rect.height) || 0;
// const delta = afterHeight - beforeHeight;
// if (delta > 0) {
// this.scrollTop = beforeTop + delta;
// }
// })
// .exec();
// });
})
.finally(() => {
setTimeout(() => {
this.isLoading = false;
}, 50);
}, 100);
});
},
//
scrollToBottom() {
// if (this.vuex_msglist.length > 0) {
// const lastMsg = this.vuex_msglist[this.vuex_msglist.length - 1];
// this.scrollToView = "msg-" + lastMsg.id;
// }
if (this.isLoading) return;
//
if (this.scrollToView === "bottom-anchor") {
this.scrollToView = "";
this.$nextTick(() => {
this.scrollToView = "bottom-anchor";
});
return;
const query = uni.createSelectorQuery().in(this);
query
.select(".chat-content")
.boundingClientRect((data) => {
if (data) {
this.scrollTop = Number(data.height || 0) + 200;
}
this.scrollToView = "bottom-anchor";
})
.exec();
});
},
//

View File

@ -1041,7 +1041,7 @@ export default {
.finally(() => {
setTimeout(() => {
this.isLoading = false;
}, 300);
}, 100);
});
},