feat: 添加滚动到底部事件处理,优化聊天内容滚动逻辑及样式调整
This commit is contained in:
parent
cceb6eed43
commit
089ba82ec9
|
@ -84,6 +84,7 @@
|
||||||
scroll-with-animation
|
scroll-with-animation
|
||||||
:scroll-top="scrollTop"
|
:scroll-top="scrollTop"
|
||||||
:show-scrollbar="true"
|
:show-scrollbar="true"
|
||||||
|
@scrolltolower="onScrollToLower"
|
||||||
>
|
>
|
||||||
<!-- 头部卡片 -->
|
<!-- 头部卡片 -->
|
||||||
<!-- 后端让先注释 -->
|
<!-- 后端让先注释 -->
|
||||||
|
@ -359,9 +360,7 @@ export default {
|
||||||
// 确保消息更新后自动滚动到底部
|
// 确保消息更新后自动滚动到底部
|
||||||
messageGroups: {
|
messageGroups: {
|
||||||
handler() {
|
handler() {
|
||||||
this.$nextTick(() => {
|
this.scrollToBottom();
|
||||||
this.scrollToBottom();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
|
@ -378,7 +377,6 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onLoad() {},
|
onLoad() {},
|
||||||
mounted() {},
|
|
||||||
methods: {
|
methods: {
|
||||||
handleLeftClick() {
|
handleLeftClick() {
|
||||||
this.$u.api.GetConversationPage().then((res) => {
|
this.$u.api.GetConversationPage().then((res) => {
|
||||||
|
@ -407,20 +405,31 @@ export default {
|
||||||
scrollToBottom() {
|
scrollToBottom() {
|
||||||
// 使用nextTick确保DOM已更新
|
// 使用nextTick确保DOM已更新
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
// 获取滚动区域的高度
|
// setTimeout(() => {
|
||||||
const query = uni.createSelectorQuery().in(this);
|
const query = uni.createSelectorQuery().in(this);
|
||||||
query
|
query
|
||||||
.select(".chat-content")
|
.select(".chat-content")
|
||||||
.boundingClientRect((data) => {
|
.boundingClientRect((data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
console.log("data", data);
|
console.log("chat-content高度:", data.height);
|
||||||
// 计算滚动到底部的位置
|
// 使用pageScrollTo滚动到底部
|
||||||
const scrollHeight = data.height;
|
// uni.pageScrollTo({
|
||||||
// 设置滚动位置,加100px确保滚动到底部
|
// scrollTop: 99999,
|
||||||
this.scrollTop = scrollHeight + 100;
|
// duration: 100,
|
||||||
}
|
// });
|
||||||
})
|
|
||||||
.exec();
|
// 同时设置scrollTop和scrollToView
|
||||||
|
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) {
|
handleFeatureClick(item) {
|
||||||
|
@ -554,6 +563,11 @@ export default {
|
||||||
this.currentConversationId = "";
|
this.currentConversationId = "";
|
||||||
this.messageGroups = [];
|
this.messageGroups = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 滚动到底部事件处理
|
||||||
|
onScrollToLower() {
|
||||||
|
console.log("已滚动到底部");
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -758,20 +772,23 @@ page {
|
||||||
.chat-container {
|
.chat-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 30rpx;
|
padding: 0 30rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
height: calc(100vh - 88rpx - 146rpx);
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
.chat-scroll {
|
.chat-scroll {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
flex-shrink: 0;
|
height: calc(100vh - 88rpx - 146rpx);
|
||||||
// overflow-y: auto; /* 使用auto而不是scroll */ // 添加这行会导致滚动条不见
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-card {
|
.chat-card {
|
||||||
// background-color: #ffffff;
|
// background-color: #ffffff;
|
||||||
// border-radius: 16rpx;
|
// border-radius: 16rpx;
|
||||||
padding: 30rpx;
|
padding: 32rpx;
|
||||||
margin-bottom: 30rpx;
|
margin-bottom: 32rpx;
|
||||||
|
|
||||||
.chat-card-title {
|
.chat-card-title {
|
||||||
font-family: DouyinSans;
|
font-family: DouyinSans;
|
||||||
|
|
Loading…
Reference in New Issue