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

View File

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