feat: 添加滚动到底部事件处理,优化聊天内容滚动逻辑及样式调整

This commit is contained in:
yangzhe 2025-07-11 15:21:23 +08:00
parent cceb6eed43
commit 089ba82ec9
1 changed files with 40 additions and 23 deletions

View File

@ -84,6 +84,7 @@
scroll-with-animation
:scroll-top="scrollTop"
:show-scrollbar="true"
@scrolltolower="onScrollToLower"
>
<!-- 头部卡片 -->
<!-- 后端让先注释 -->
@ -359,9 +360,7 @@ export default {
//
messageGroups: {
handler() {
this.$nextTick(() => {
this.scrollToBottom();
});
this.scrollToBottom();
},
deep: true,
},
@ -378,7 +377,6 @@ export default {
},
},
onLoad() {},
mounted() {},
methods: {
handleLeftClick() {
this.$u.api.GetConversationPage().then((res) => {
@ -407,20 +405,31 @@ export default {
scrollToBottom() {
// 使nextTickDOM
this.$nextTick(() => {
//
const query = uni.createSelectorQuery().in(this);
query
.select(".chat-content")
.boundingClientRect((data) => {
if (data) {
console.log("data", data);
//
const scrollHeight = data.height;
// 100px
this.scrollTop = scrollHeight + 100;
}
})
.exec();
// setTimeout(() => {
const query = uni.createSelectorQuery().in(this);
query
.select(".chat-content")
.boundingClientRect((data) => {
if (data) {
console.log("chat-content高度:", data.height);
// 使pageScrollTo
// uni.pageScrollTo({
// scrollTop: 99999,
// duration: 100,
// });
// scrollTopscrollToView
this.scrollTop = data.height + 200;
// if (this.messageGroups.length > 0) {
// const lastMessage =
// this.messageGroups[this.messageGroups.length - 1];
// this.scrollToView = "msg-" + lastMessage.id;
// console.log("scrollToView:", this.scrollToView);
// }
}
})
.exec();
// }, 300);
});
},
handleFeatureClick(item) {
@ -554,6 +563,11 @@ export default {
this.currentConversationId = "";
this.messageGroups = [];
},
//
onScrollToLower() {
console.log("已滚动到底部");
},
},
};
</script>
@ -758,20 +772,23 @@ page {
.chat-container {
display: flex;
flex-direction: column;
padding: 30rpx;
padding: 0 30rpx;
box-sizing: border-box;
height: calc(100vh - 88rpx - 146rpx);
position: relative;
overflow: hidden;
.chat-scroll {
flex: 1;
flex-shrink: 0;
// overflow-y: auto; /* 使autoscroll */ //
height: calc(100vh - 88rpx - 146rpx);
overflow-y: scroll;
}
.chat-card {
// background-color: #ffffff;
// border-radius: 16rpx;
padding: 30rpx;
margin-bottom: 30rpx;
padding: 32rpx;
margin-bottom: 32rpx;
.chat-card-title {
font-family: DouyinSans;