fix(chat): 优化聊天页面加载和滚动逻辑
This commit is contained in:
parent
3afd93a79e
commit
31af22face
|
|
@ -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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 滚动到底部锚点
|
|
||||||
if (this.scrollToView === "bottom-anchor") {
|
|
||||||
this.scrollToView = "";
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.scrollToView = "bottom-anchor";
|
const query = uni.createSelectorQuery().in(this);
|
||||||
});
|
query
|
||||||
return;
|
.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(() => {
|
.finally(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}, 300);
|
}, 100);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue