| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | <template> | 
					
						
							|  |  |  |  |   <u-popup v-model="showPopup" width="550rpx"> | 
					
						
							|  |  |  |  |     <view class="drawer-container"> | 
					
						
							|  |  |  |  |       <view class="drawer-header"> | 
					
						
							|  |  |  |  |         <text class="drawer-title" @click="handleCreateConversation"> | 
					
						
							|  |  |  |  |           <u-icon | 
					
						
							|  |  |  |  |             class="drawer-title-icon" | 
					
						
							|  |  |  |  |             name="plus" | 
					
						
							|  |  |  |  |             size="32rpx" | 
					
						
							|  |  |  |  |             color="#666666" | 
					
						
							|  |  |  |  |           ></u-icon> | 
					
						
							|  |  |  |  |           新建对话 | 
					
						
							|  |  |  |  |         </text> | 
					
						
							|  |  |  |  |       </view> | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  |       <scroll-view | 
					
						
							|  |  |  |  |         scroll-y | 
					
						
							|  |  |  |  |         class="chat-history-list" | 
					
						
							|  |  |  |  |         :scroll-into-view="scrollToView" | 
					
						
							|  |  |  |  |         :show-scrollbar="false" | 
					
						
							|  |  |  |  |         scroll-with-animation="true" | 
					
						
							|  |  |  |  |       > | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |         <!-- 使用新的数据结构渲染聊天历史 --> | 
					
						
							|  |  |  |  |         <view | 
					
						
							|  |  |  |  |           v-for="(group, groupIndex) in chatHistoryList3" | 
					
						
							|  |  |  |  |           :key="'group-' + group.id + groupIndex" | 
					
						
							|  |  |  |  |         > | 
					
						
							|  |  |  |  |           <!-- 日期标题 --> | 
					
						
							|  |  |  |  |           <view class="chat-day"> | 
					
						
							|  |  |  |  |             <text class="day-text">{{ group.id }}</text> | 
					
						
							|  |  |  |  |           </view> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           <!-- 该日期下的对话列表 --> | 
					
						
							|  |  |  |  |           <view | 
					
						
							|  |  |  |  |             class="chat-item" | 
					
						
							|  |  |  |  |             v-for="(item, index) in group.conversation" | 
					
						
							|  |  |  |  |             :key="'conv-' + groupIndex + '-' + index" | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  |             :id="'chat-item-' + item.id" | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |             :class="{ | 
					
						
							| 
									
										
										
										
											2025-07-11 13:43:04 +08:00
										 |  |  |  |               'chat-item-active': item.isActiveChat, | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |             }" | 
					
						
							|  |  |  |  |             @click="selectChatItem(groupIndex, index, item.id)" | 
					
						
							|  |  |  |  |           > | 
					
						
							| 
									
										
										
										
											2025-07-11 13:43:04 +08:00
										 |  |  |  |             <!-- currentActiveGroup === groupIndex && | 
					
						
							|  |  |  |  |                 currentActiveIndex === index, --> | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |             <text class="chat-text">{{ item.title }}</text> | 
					
						
							|  |  |  |  |           </view> | 
					
						
							|  |  |  |  |         </view> | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-11 16:04:45 +08:00
										 |  |  |  |         <!-- 添加底部空白区域 --> | 
					
						
							|  |  |  |  |         <view class="bottom-space"></view> | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |       </scroll-view> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       <view class="drawer-footer"> | 
					
						
							|  |  |  |  |         <view class="user-info"> | 
					
						
							|  |  |  |  |           <image | 
					
						
							|  |  |  |  |             class="user-avatar" | 
					
						
							|  |  |  |  |             src="/static/common/images/avatar.png" | 
					
						
							|  |  |  |  |           ></image> | 
					
						
							|  |  |  |  |           <text class="user-name">{{ userName || "晓德塔," }}</text> | 
					
						
							|  |  |  |  |         </view> | 
					
						
							|  |  |  |  |         <view class="settings"> | 
					
						
							|  |  |  |  |           <u-icon name="setting" size="40rpx" color="#999"></u-icon> | 
					
						
							|  |  |  |  |         </view> | 
					
						
							|  |  |  |  |       </view> | 
					
						
							|  |  |  |  |     </view> | 
					
						
							|  |  |  |  |   </u-popup> | 
					
						
							|  |  |  |  | </template> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | <script> | 
					
						
							|  |  |  |  | export default { | 
					
						
							|  |  |  |  |   name: "ChatHistory", | 
					
						
							|  |  |  |  |   props: { | 
					
						
							|  |  |  |  |     show: { | 
					
						
							|  |  |  |  |       type: Boolean, | 
					
						
							|  |  |  |  |       default: false, | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     chatHistoryList3: { | 
					
						
							|  |  |  |  |       type: Array, | 
					
						
							|  |  |  |  |       default: () => [], | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     activeIndex: { | 
					
						
							|  |  |  |  |       type: Number, | 
					
						
							|  |  |  |  |       default: 0, | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     userName: { | 
					
						
							|  |  |  |  |       type: String, | 
					
						
							|  |  |  |  |       default: "", | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |   }, | 
					
						
							|  |  |  |  |   data() { | 
					
						
							|  |  |  |  |     return { | 
					
						
							|  |  |  |  |       showPopup: false, | 
					
						
							|  |  |  |  |       currentActiveGroup: -1, | 
					
						
							|  |  |  |  |       currentActiveIndex: -1, | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  |       activeItemId: "", // 存储当前激活项的ID
 | 
					
						
							|  |  |  |  |       scrollToView: "", // 用于scroll-into-view属性
 | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |     }; | 
					
						
							|  |  |  |  |   }, | 
					
						
							|  |  |  |  |   watch: { | 
					
						
							|  |  |  |  |     show: { | 
					
						
							|  |  |  |  |       handler(newVal) { | 
					
						
							|  |  |  |  |         this.showPopup = newVal; | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |       immediate: true, | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     showPopup(val) { | 
					
						
							|  |  |  |  |       if (val !== this.show) { | 
					
						
							|  |  |  |  |         this.$emit("update:show", val); | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  |     // 监听聊天历史数据变化,找到激活项并滚动
 | 
					
						
							|  |  |  |  |     chatHistoryList3: { | 
					
						
							|  |  |  |  |       handler() { | 
					
						
							|  |  |  |  |         this.$nextTick(() => { | 
					
						
							|  |  |  |  |           this.scrollToActiveItem(); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |       deep: true, | 
					
						
							|  |  |  |  |       immediate: true, | 
					
						
							|  |  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |   }, | 
					
						
							|  |  |  |  |   methods: { | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  |     // 滚动到激活的聊天项
 | 
					
						
							|  |  |  |  |     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; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |     selectChatItem(groupIndex, index, conversationId) { | 
					
						
							| 
									
										
										
										
											2025-07-11 13:43:04 +08:00
										 |  |  |  |       //   this.currentActiveGroup = groupIndex;
 | 
					
						
							|  |  |  |  |       //   this.currentActiveIndex = index;
 | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       // 向父组件发送选中的对话信息
 | 
					
						
							|  |  |  |  |       this.$emit("select-conversation", { | 
					
						
							|  |  |  |  |         conversationId, | 
					
						
							|  |  |  |  |       }); | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     handleCreateConversation() { | 
					
						
							|  |  |  |  |       this.$emit("create-conversation"); | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |   }, | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | </script> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | <style lang="scss" scoped> | 
					
						
							|  |  |  |  | .drawer-container { | 
					
						
							|  |  |  |  |   padding: 32rpx; | 
					
						
							|  |  |  |  |   display: flex; | 
					
						
							|  |  |  |  |   flex-direction: column; | 
					
						
							|  |  |  |  |   height: 100vh; | 
					
						
							|  |  |  |  |   background-color: #ffffff; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   .drawer-header { | 
					
						
							| 
									
										
										
										
											2025-07-10 17:52:04 +08:00
										 |  |  |  |     padding: 0 32rpx; | 
					
						
							|  |  |  |  |     height: 140rpx; | 
					
						
							|  |  |  |  |     line-height: 120rpx; | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     .drawer-title { | 
					
						
							|  |  |  |  |       font-family: DouyinSans; | 
					
						
							|  |  |  |  |       font-weight: bold; | 
					
						
							|  |  |  |  |       font-size: 32rpx; | 
					
						
							|  |  |  |  |       color: #666666; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       .drawer-title-icon { | 
					
						
							|  |  |  |  |         margin-right: 10rpx; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   .chat-history-list { | 
					
						
							|  |  |  |  |     flex: 1; | 
					
						
							| 
									
										
										
										
											2025-07-10 17:52:04 +08:00
										 |  |  |  |     height: calc(100vh - 360rpx); | 
					
						
							| 
									
										
										
										
											2025-07-11 16:04:45 +08:00
										 |  |  |  |     padding-bottom: 20rpx; | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     .chat-day { | 
					
						
							|  |  |  |  |       display: flex; | 
					
						
							|  |  |  |  |       margin: 20rpx 0 20rpx 30rpx; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       .day-text { | 
					
						
							|  |  |  |  |         font-size: 24rpx; | 
					
						
							|  |  |  |  |         color: #999999; | 
					
						
							|  |  |  |  |         font-family: PingFang SC; | 
					
						
							|  |  |  |  |         margin-bottom: 10rpx; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     .chat-item { | 
					
						
							|  |  |  |  |       padding: 24rpx 30rpx; | 
					
						
							|  |  |  |  |       border-radius: 16rpx; | 
					
						
							| 
									
										
										
										
											2025-07-11 16:04:45 +08:00
										 |  |  |  |       margin-bottom: 4rpx; | 
					
						
							|  |  |  |  |       position: relative; | 
					
						
							|  |  |  |  |       overflow: hidden; | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       .chat-text { | 
					
						
							|  |  |  |  |         font-size: 28rpx; | 
					
						
							|  |  |  |  |         color: #303030; | 
					
						
							|  |  |  |  |         font-family: PingFang SC; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       &-active { | 
					
						
							|  |  |  |  |         background-color: #4f6aff; | 
					
						
							| 
									
										
										
										
											2025-07-11 16:04:45 +08:00
										 |  |  |  |         box-shadow: 0 2rpx 8rpx rgba(79, 106, 255, 0.3); | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         .chat-text { | 
					
						
							|  |  |  |  |           color: #fff; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-11 16:04:45 +08:00
										 |  |  |  |   .bottom-space { | 
					
						
							|  |  |  |  |     height: 30rpx; | 
					
						
							|  |  |  |  |     width: 100%; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   .drawer-footer { | 
					
						
							| 
									
										
										
										
											2025-07-10 17:52:04 +08:00
										 |  |  |  |     margin-top: 20rpx; | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |     height: 130rpx; | 
					
						
							|  |  |  |  |     border: 1rpx solid #eeeeee; | 
					
						
							|  |  |  |  |     border-radius: 12rpx; | 
					
						
							|  |  |  |  |     padding: 0 30rpx; | 
					
						
							|  |  |  |  |     display: flex; | 
					
						
							|  |  |  |  |     justify-content: space-between; | 
					
						
							|  |  |  |  |     align-items: center; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     .user-info { | 
					
						
							|  |  |  |  |       display: flex; | 
					
						
							|  |  |  |  |       align-items: center; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       .user-avatar { | 
					
						
							| 
									
										
										
										
											2025-07-11 16:38:12 +08:00
										 |  |  |  |         width: 56rpx; | 
					
						
							| 
									
										
										
										
											2025-07-10 16:41:28 +08:00
										 |  |  |  |         height: 56rpx; | 
					
						
							|  |  |  |  |         border-radius: 50%; | 
					
						
							|  |  |  |  |         margin-right: 30rpx; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       .user-name { | 
					
						
							|  |  |  |  |         font-size: 28rpx; | 
					
						
							|  |  |  |  |         font-weight: bold; | 
					
						
							|  |  |  |  |         font-family: DouyinSans; | 
					
						
							|  |  |  |  |         color: #333; | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     .settings { | 
					
						
							|  |  |  |  |       padding: 10rpx; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | </style> |