fix(chat): 优化聊天页面加载和滚动逻辑
This commit is contained in:
parent
3afd93a79e
commit
31af22face
|
|
@ -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();
|
||||
});
|
||||
},
|
||||
|
||||
// 格式化时间
|
||||
|
|
|
|||
|
|
@ -1041,7 +1041,7 @@ export default {
|
|||
.finally(() => {
|
||||
setTimeout(() => {
|
||||
this.isLoading = false;
|
||||
}, 300);
|
||||
}, 100);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue