From a4a9a6c56666a859d248a619833204a14968f1e2 Mon Sep 17 00:00:00 2001 From: yangzhe Date: Fri, 11 Jul 2025 16:38:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E7=BB=84=E4=BB=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=88=B0=E6=BF=80=E6=B4=BB=E9=A1=B9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E8=83=8C=E6=99=AF=E5=9B=BE?= =?UTF-8?q?=E9=A2=84=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ChatHistory.vue | 52 ++++++++++++++++++++++++++++++++++--- pages/home/index/index.vue | 29 +++++++++++++-------- pages/login/login/index.vue | 1 + 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/components/ChatHistory.vue b/components/ChatHistory.vue index 218be47..2934566 100644 --- a/components/ChatHistory.vue +++ b/components/ChatHistory.vue @@ -12,7 +12,13 @@ 新建对话 - + {{ item.title }} - + @@ -85,6 +92,8 @@ export default { showPopup: false, currentActiveGroup: -1, currentActiveIndex: -1, + activeItemId: "", // 存储当前激活项的ID + scrollToView: "", // 用于scroll-into-view属性 }; }, watch: { @@ -99,8 +108,43 @@ export default { this.$emit("update:show", val); } }, + // 监听聊天历史数据变化,找到激活项并滚动 + chatHistoryList3: { + handler() { + this.$nextTick(() => { + this.scrollToActiveItem(); + }); + }, + deep: true, + immediate: true, + }, }, methods: { + // 滚动到激活的聊天项 + scrollToActiveItem() { + // 查找激活的聊天项 + let activeItemFound = false; + + for ( + let groupIndex = 0; + groupIndex < this.chatHistoryList3.length; + groupIndex++ + ) { + const group = this.chatHistoryList3[groupIndex]; + for (let index = 0; index < group.conversation.length; index++) { + const item = group.conversation[index]; + if (item.isActiveChat) { + activeItemFound = true; + this.activeItemId = `chat-item-${item.id}`; + // 设置scrollToView的值,使scroll-view自动滚动到该元素 + this.scrollToView = this.activeItemId; + break; + } + } + if (activeItemFound) break; + } + }, + selectChatItem(groupIndex, index, conversationId) { // this.currentActiveGroup = groupIndex; // this.currentActiveIndex = index; @@ -183,7 +227,7 @@ export default { } } } - + .bottom-space { height: 30rpx; width: 100%; @@ -204,7 +248,7 @@ export default { align-items: center; .user-avatar { - width: 56rpx; + width: 56rpx; height: 56rpx; border-radius: 50%; margin-right: 30rpx; diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index 87a24e9..a0a9f14 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -376,7 +376,18 @@ export default { deep: true, }, }, - onLoad() {}, + onLoad() { + // 预加载背景图 + // uni.getImageInfo({ + // src: '/static/common/images/images_bg.png', + // success: () => { + // console.log('背景图预加载成功'); + // }, + // fail: (err) => { + // console.error('背景图预加载失败', err); + // } + // }); + }, methods: { handleLeftClick() { this.$u.api.GetConversationPage().then((res) => { @@ -573,16 +584,6 @@ export default {