From b96a82ad96f070d4e39805c4f57281d697ea7fe5 Mon Sep 17 00:00:00 2001 From: yangzhe Date: Wed, 17 Dec 2025 16:26:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(home):=20=E6=B7=BB=E5=8A=A0currentDMid?= =?UTF-8?q?=E7=A9=BA=E5=80=BC=E6=A3=80=E6=9F=A5=E9=98=B2=E6=AD=A2=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/index/index.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index 783d8c6..144d51c 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -909,6 +909,8 @@ export default { // 刷新当前对话的消息详情 handleGetConversationDetail() { + if (!this.currentDMid) return; + this.$u.api .GetConversationDetail({ "Item1.Id": this.currentDMid, @@ -932,6 +934,8 @@ export default { // 刷新当前页数据;若当前页为空且页码>1,则自动回退上一页 refreshPageWithFallback() { + if (!this.currentDMid) return; + const currentIndex = this.pageQuery.PageIndex || 1; const pageSize = this.pageQuery.PageSize; @@ -983,6 +987,8 @@ export default { onScrollToUpper() { console.log("触发上拉刷新"); + if (!this.currentDMid) return; + // 如果已经没有更多数据或正在切换对话或当前对话为空(新建对话),不再触发上拉刷新 if (this.noMoreData || this.isSwitchingConversation) { return; From 3afd93a79e401821333b5cc0f43b380cdc5e7b31 Mon Sep 17 00:00:00 2001 From: yangzhe Date: Wed, 17 Dec 2025 16:27:08 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(=E8=81=8A=E5=A4=A9=E9=A1=B5=E9=9D=A2):?= =?UTF-8?q?=20=E6=94=B9=E8=BF=9B=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=92=8C=E6=BB=9A=E5=8A=A8=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chat/index.vue | 80 ++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/pages/chat/index.vue b/pages/chat/index.vue index 68235d6..28bf44e 100644 --- a/pages/chat/index.vue +++ b/pages/chat/index.vue @@ -14,7 +14,7 @@ scroll-y :scroll-into-view="scrollToView" :scroll-top="scrollTop" - scroll-with-animation + :scroll-with-animation="!isLoading" :upper-threshold="20" @scroll="handleScroll" @scrolltoupper="handleScrollToUpper" @@ -47,6 +47,19 @@ + + + + + + + + 已经到顶了 + + { this.scrollToBottom(); }); @@ -283,11 +296,22 @@ export default { // 加载对话消息 getMsgList() { - return this.$store.dispatch("fetchChatRecord", { - dialogueManagementId: this.vuex_msgUser.dialogueManagementId, - PageIndex: this.PageIndex, - PageSize: this.PageSize, - }); + return this.$store + .dispatch("fetchChatRecord", { + dialogueManagementId: this.vuex_msgUser.dialogueManagementId, + PageIndex: this.PageIndex, + PageSize: this.PageSize, + }) + .then((list) => { + console.log(list.length, "加载对话消息"); + + const len = Array.isArray(list) ? list.length : 0; + if (len === 0 && len < this.PageSize) { + this.noMoreData = true; + console.log("没有更多数据了", this.noMoreData); + } + return list; + }); }, handleScroll(e) { @@ -298,25 +322,26 @@ export default { // 滚动到顶部,加载下一页历史消息 handleScrollToUpper() { - if (this.isLoadingHistory || this.noMoreHistory) return; + if (this.isLoading || this.noMoreData) return; - this.isLoadingHistory = true; + this.isLoading = true; const beforeTop = this.currentScrollTop || 0; const beforeHeight = this.currentScrollHeight || 0; - this.PageIndex += 1; + const nextPageIndex = this.PageIndex + 1; this.scrollToView = ""; this.$store .dispatch("fetchChatRecordNextPage", { dialogueManagementId: this.vuex_msgUser.dialogueManagementId, - PageIndex: this.PageIndex, + PageIndex: nextPageIndex, PageSize: this.PageSize, }) .then((list) => { if (!list || !list.length) { - this.noMoreHistory = true; + this.noMoreData = true; return; } + this.PageIndex = nextPageIndex; this.$nextTick(() => { const query = uni.createSelectorQuery().in(this); query @@ -331,12 +356,9 @@ export default { .exec(); }); }) - .catch(() => { - this.PageIndex = Math.max(1, this.PageIndex - 1); - }) .finally(() => { setTimeout(() => { - this.isLoadingHistory = false; + this.isLoading = false; }, 50); }); }, @@ -448,18 +470,18 @@ export default { height: 100%; overflow-y: scroll; - // .loading-more { - // text-align: center; - // margin-bottom: 32rpx; - // } + .loading-more { + text-align: center; + margin-bottom: 32rpx; + } - // .no-more-data { - // text-align: center; - // font-size: 24rpx; - // color: #999; - // margin-bottom: 32rpx; - // padding: 10rpx 0; - // } + .no-more-data { + text-align: center; + font-size: 24rpx; + color: #999; + margin-bottom: 32rpx; + padding: 10rpx 0; + } .teacher-info-card { background-color: #ffffff; From 31af22face4ba533556137a7c8114669e5b0327d Mon Sep 17 00:00:00 2001 From: yangzhe Date: Wed, 17 Dec 2025 16:42:52 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(chat):=20=E4=BC=98=E5=8C=96=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E9=A1=B5=E9=9D=A2=E5=8A=A0=E8=BD=BD=E5=92=8C=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chat/index.vue | 58 ++++++++++++++++++-------------------- pages/home/index/index.vue | 2 +- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/pages/chat/index.vue b/pages/chat/index.vue index 28bf44e..f9756c8 100644 --- a/pages/chat/index.vue +++ b/pages/chat/index.vue @@ -303,12 +303,9 @@ export default { PageSize: this.PageSize, }) .then((list) => { - console.log(list.length, "加载对话消息"); - const len = Array.isArray(list) ? list.length : 0; - if (len === 0 && len < this.PageSize) { + if (len === 0 && this.PageIndex === 1) { this.noMoreData = true; - console.log("没有更多数据了", this.noMoreData); } return list; }); @@ -342,43 +339,42 @@ export default { return; } this.PageIndex = nextPageIndex; - this.$nextTick(() => { - const query = uni.createSelectorQuery().in(this); - query - .select(".chat-content") - .boundingClientRect((rect) => { - const afterHeight = Number(rect && rect.height) || 0; - const delta = afterHeight - beforeHeight; - if (delta > 0) { - this.scrollTop = beforeTop + delta; - } - }) - .exec(); - }); + // this.$nextTick(() => { + // const query = uni.createSelectorQuery().in(this); + // query + // .select(".chat-content") + // .boundingClientRect((rect) => { + // const afterHeight = Number(rect && rect.height) || 0; + // const delta = afterHeight - beforeHeight; + // if (delta > 0) { + // this.scrollTop = beforeTop + delta; + // } + // }) + // .exec(); + // }); }) .finally(() => { setTimeout(() => { this.isLoading = false; - }, 50); + }, 100); }); }, // 滚动到底部 scrollToBottom() { - // if (this.vuex_msglist.length > 0) { - // const lastMsg = this.vuex_msglist[this.vuex_msglist.length - 1]; - // this.scrollToView = "msg-" + lastMsg.id; - // } + if (this.isLoading) return; - // 滚动到底部锚点 - if (this.scrollToView === "bottom-anchor") { - this.scrollToView = ""; - this.$nextTick(() => { - this.scrollToView = "bottom-anchor"; - }); - return; - } - this.scrollToView = "bottom-anchor"; + this.$nextTick(() => { + const query = uni.createSelectorQuery().in(this); + query + .select(".chat-content") + .boundingClientRect((data) => { + if (data) { + this.scrollTop = Number(data.height || 0) + 200; + } + }) + .exec(); + }); }, // 格式化时间 diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index 144d51c..0556eab 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -1041,7 +1041,7 @@ export default { .finally(() => { setTimeout(() => { this.isLoading = false; - }, 300); + }, 100); }); }, From 9e10f6788d272fcb19b502ef2a978947eaedb9b5 Mon Sep 17 00:00:00 2001 From: yangzhe Date: Wed, 17 Dec 2025 16:51:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?refactor(chat):=20=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0=E5=88=B0?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将时间格式化、滚动到底部和时间显示判断逻辑提取到 utils/chat.js 提升代码复用性和可维护性,保持与首页实现一致 --- pages/chat/index.vue | 70 ++++-------------------- utils/chat.js | 125 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 59 deletions(-) create mode 100644 utils/chat.js diff --git a/pages/chat/index.vue b/pages/chat/index.vue index f9756c8..1a4ce7c 100644 --- a/pages/chat/index.vue +++ b/pages/chat/index.vue @@ -135,7 +135,11 @@