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-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() {
// 使nextTickDOM // 使nextTickDOM
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,
// });
// 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(); .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; /* 使autoscroll */ // 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;