From a2ced17f6307582a465d2bafae870b19640b6ddc Mon Sep 17 00:00:00 2001 From: yangzhe Date: Thu, 24 Jul 2025 14:42:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A9=BA=E6=A0=BC?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=8D=A2=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/index/index.vue | 58 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index 00ef9c8..3525b2a 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -21,7 +21,7 @@ > Hi~ 我是源小新,你们的AI校园助手,非常高兴认识您,我可以为你答疑解惑。Hi~ 我是源小新,你们的AI校园助手,非常高兴认识您,我可以为你答疑解惑。 @@ -117,7 +117,7 @@ - + 已经到顶了 @@ -283,7 +283,7 @@ export default { isLoadingMore: false, // 是否正在加载更多的标志位 noMoreData: false, // 是否已加载全部历史消息 isSwitchingConversation: false, // 是否正在切换对话的标志位 - + pageQuery: { PageIndex: 1, PageSize: 20, @@ -502,7 +502,7 @@ export default { // 添加到消息列表 this.messageGroups.push(userMessage); this.messageValue = ""; - + // 立即添加一个AI回复的加载状态消息 const loadingMessage = { id: "loading_" + Math.random().toString(36).substring(2, 15), @@ -514,9 +514,9 @@ export default { messageType: 0, timeLabel: 0, displayTime: "", - isLoading: true // 标记为加载状态 + isLoading: true, // 标记为加载状态 }; - + // 添加加载状态消息到列表 this.messageGroups.push(loadingMessage); @@ -532,7 +532,9 @@ export default { this.currentConversationId = data.conversationId; // 从消息列表中移除加载状态消息 - this.messageGroups = this.messageGroups.filter(msg => !msg.isLoading); + this.messageGroups = this.messageGroups.filter( + (msg) => !msg.isLoading + ); // 创建AI回复消息对象 const aiMessage = { @@ -554,10 +556,12 @@ export default { }) .catch((error) => { console.error("API请求失败:", error); - + // 从消息列表中移除加载状态消息 - this.messageGroups = this.messageGroups.filter(msg => !msg.isLoading); - + this.messageGroups = this.messageGroups.filter( + (msg) => !msg.isLoading + ); + // 添加错误消息 const errorMessage = { id: "error_" + Math.random().toString(36).substring(2, 15), @@ -570,7 +574,7 @@ export default { timeLabel: 0, displayTime: "", }; - + this.messageGroups.push(errorMessage); }); }, @@ -638,18 +642,18 @@ export default { // 关闭弹窗 this.popupShow = false; this.isChat = true; - + // 设置切换对话标志位,防止触发上拉刷新 this.isSwitchingConversation = true; - + this.currentConversationId = ""; this.messageGroups = []; - + // 重置分页和加载状态 this.pageQuery.PageIndex = 1; this.isLoadingMore = false; this.noMoreData = false; - + // 延迟重置切换对话标志位 setTimeout(() => { this.isSwitchingConversation = false; @@ -659,18 +663,18 @@ export default { // 开始新对话 handleStartChat() { this.isChat = true; - + // 设置切换对话标志位,防止触发上拉刷新 this.isSwitchingConversation = true; - + this.currentConversationId = ""; this.messageGroups = []; - + // 重置分页和加载状态 this.pageQuery.PageIndex = 1; this.isLoadingMore = false; this.noMoreData = false; - + // 延迟重置切换对话标志位 setTimeout(() => { this.isSwitchingConversation = false; @@ -685,7 +689,7 @@ export default { // 滚动到顶部事件处理 onScrollToUpper() { console.log("触发上拉刷新"); - + // 如果已经没有更多数据或正在切换对话,不再触发上拉刷新 if (this.noMoreData || this.isSwitchingConversation) { return; @@ -711,7 +715,7 @@ export default { this.$refs.uToast.show({ title: "已经到顶了", type: "warning", - duration: 1500 + duration: 1500, }); return; } @@ -1002,7 +1006,7 @@ export default { text-align: center; margin-bottom: 32rpx; } - + .no-more-data { text-align: center; font-size: 24rpx; @@ -1050,7 +1054,7 @@ export default { display: flex; align-items: center; justify-content: flex-start; - + .dot { display: inline-block; width: 12rpx; @@ -1060,20 +1064,20 @@ export default { margin: 0 6rpx; opacity: 0.6; animation: dot-flashing 1.5s infinite linear alternate; - + &:nth-child(1) { animation-delay: 0s; } - + &:nth-child(2) { animation-delay: 0.5s; } - + &:nth-child(3) { animation-delay: 1s; } } - + @keyframes dot-flashing { 0% { opacity: 0.6;