From a7654255cc1ed6d763f4af2658810787a2f34106 Mon Sep 17 00:00:00 2001 From: "[yxf]" <[1524240689@qq.com]> Date: Wed, 15 Apr 2026 15:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9userid=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E3=80=81=E6=8F=90=E7=A4=BA=E6=9D=A1=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AutoReplyController.java | 4 +- .../controller/QuickReplyController.java | 7 +- .../implatform/service/AutoReplyService.java | 2 +- .../implatform/service/QuickReplyService.java | 2 +- .../service/impl/AutoReplyServiceImpl.java | 9 +- .../service/impl/QuickReplyServiceImpl.java | 9 +- im-uniapp/pages/chat/chat-box.vue | 87 +++++++++++-------- im-uniapp/store/chatStore.js | 26 ++++-- im-web/src/components/chat/ChatBox.vue | 6 +- 9 files changed, 85 insertions(+), 67 deletions(-) diff --git a/im-platform/src/main/java/com/bx/implatform/controller/AutoReplyController.java b/im-platform/src/main/java/com/bx/implatform/controller/AutoReplyController.java index daf73ad..6c2c598 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/AutoReplyController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/AutoReplyController.java @@ -23,7 +23,7 @@ public class AutoReplyController { @GetMapping("/list") @Operation(summary = "获取常见问题列表", description = "前端聊天页调用") - public Result> getList(@RequestParam Long userId) { - return ResultUtils.success(AutoReplyService.getList(userId)); + public Result> getList() { + return ResultUtils.success(AutoReplyService.getList()); } } diff --git a/im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java b/im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java index e61fdbf..e7939d8 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java @@ -9,7 +9,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -20,11 +19,11 @@ import java.util.List; @RequiredArgsConstructor public class QuickReplyController { - private final QuickReplyService quickReplyService; + private final QuickReplyService QuickReplyService; @GetMapping("/list") @Operation(summary = "获取快捷回复列表", description = "前端聊天页调用") - public Result> getList(@RequestParam Long userId) { - return ResultUtils.success(quickReplyService.getList(userId)); + public Result> getList() { + return ResultUtils.success(QuickReplyService.getList()); } } \ No newline at end of file diff --git a/im-platform/src/main/java/com/bx/implatform/service/AutoReplyService.java b/im-platform/src/main/java/com/bx/implatform/service/AutoReplyService.java index f295023..5905c4b 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/AutoReplyService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/AutoReplyService.java @@ -4,5 +4,5 @@ import com.bx.implatform.vo.AutoReplyVO; import java.util.List; public interface AutoReplyService { - List getList(Long userId); + List getList(); } \ No newline at end of file diff --git a/im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java b/im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java index a9a7d7e..575256e 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java @@ -4,5 +4,5 @@ import com.bx.implatform.vo.QuickReplyVO; import java.util.List; public interface QuickReplyService { - List getList(Long userId); + List getList(); } \ No newline at end of file diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/AutoReplyServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/AutoReplyServiceImpl.java index acf72a6..0938ffb 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/AutoReplyServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/AutoReplyServiceImpl.java @@ -7,6 +7,7 @@ import com.bx.implatform.entity.User; import com.bx.implatform.mapper.AutoReplyMapper; import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.service.AutoReplyService; +import com.bx.implatform.session.SessionContext; import com.bx.implatform.vo.AutoReplyVO; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; @@ -22,24 +23,22 @@ public class AutoReplyServiceImpl extends ServiceImpl getList(Long userId) { - // 1. 根据前端传的 userId 查询用户 + public List getList() { + Long userId = SessionContext.getSession().getUserId(); + User user = userMapper.selectById(userId); if (user == null) { return List.of(); } - // 2. 拿到用户的 uniqueToken String uniqueToken = user.getUniqueToken(); - // 3. 匹配常见问题 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(AutoReply::getUniqueToken, uniqueToken); wrapper.orderByAsc(AutoReply::getCreatedTime); List list = this.list(wrapper); - // 4. 转VO返回 return list.stream().map(item -> { AutoReplyVO vo = new AutoReplyVO(); BeanUtils.copyProperties(item, vo); diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java index a6ce5f0..c8ae365 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java @@ -7,6 +7,7 @@ import com.bx.implatform.entity.User; import com.bx.implatform.mapper.QuickReplyMapper; import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.service.QuickReplyService; +import com.bx.implatform.session.SessionContext; import com.bx.implatform.vo.QuickReplyVO; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; @@ -22,24 +23,22 @@ public class QuickReplyServiceImpl extends ServiceImpl getList(Long userId) { - // 1. 根据前端传的 userId 查询用户 + public List getList() { + Long userId = SessionContext.getSession().getUserId(); + User user = userMapper.selectById(userId); if (user == null) { return List.of(); } - // 2. 拿到用户的 uniqueToken String uniqueToken = user.getUniqueToken(); - // 3. 匹配快捷回复 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(QuickReply::getUniqueToken, uniqueToken); wrapper.orderByAsc(QuickReply::getCreatedTime); List list = this.list(wrapper); - // 4. 转VO返回 return list.stream().map(item -> { QuickReplyVO vo = new QuickReplyVO(); BeanUtils.copyProperties(item, vo); diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 9c05767..9cdc6f5 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -3,13 +3,14 @@ {{ title }} - - - 请选择您想咨询的问题: - - + + 猜你想问 + + - {{ q }} + * + {{ q }} @@ -174,15 +175,13 @@ export default { methods: { loadCommonQuestions(userId) { this.$http({ - url: "/auto/reply/list?userId=" + userId, - method: 'get', + url: "/auto/reply/list" , + method: 'get' }).then(res => { - // 你的接口是 res.data 才是列表 let list = res || []; this.autoReplyList = list; this.commonQuestions = list.map(item => item.replyTitle); }).catch(() => { - // this.commonQuestions = ["什么时候发货?", "如何申请退款?", "订单怎么取消?", "可以开发票吗?", "商品是否包邮?"]; }); }, @@ -201,7 +200,6 @@ export default { receipt: this.isReceipt }; - // ============== 区分类型 ============== if (autoReply.replyType === 0) { // 文本 msgInfo.type = this.$enums.MESSAGE_TYPE.TEXT; @@ -1373,42 +1371,55 @@ export default { .scroll-box { height: 100%; - padding-top: 120rpx; /* 给常见问题条留出空间 */ + padding-top: 180rpx; /* 给常见问题条留出空间 */ box-sizing: border-box; } - // 固定在聊天顶部的常见问题提示条(不会滚动) - .question-tip-fixed { + // 猜你想问 样式(完全匹配参考图) + .guess-question-box { position: absolute; top: 0; - left: 0; - right: 0; + left: 0; + right: 0; z-index: 10; - background-color: #ffffff; - padding: 12rpx 20rpx; - // border-bottom: 1rpx solid #f0f0f0; - .tip-title { - font-size: 26rpx; - color: #999; - text-align: center; - margin-bottom: 8rpx; + background-color: #F6F6F6; + padding: 20rpx 30rpx; + border-radius: 12rpx; + margin: 10rpx 20rpx; + box-sizing: border-box; + + .guess-title { + font-size: 32rpx; + color: #333333; + font-weight: 500; + margin-bottom: 20rpx; } - .question-list { + + .guess-list { display: flex; - flex-wrap: wrap; - gap: 10rpx; - justify-content: center; + flex-direction: column; + gap: 16rpx; } - .question-item { - background-color: #f5f7fa; - border-radius: 30rpx; - padding: 8rpx 16rpx; - font-size: 26rpx; - color: #333; - border: 1rpx solid #eaeaea; - } - .question-item:active { - background-color: #e6e6e6; + + .guess-item { + display: flex; + align-items: center; + gap: 10rpx; + font-size: 30rpx; + color: #009E5F; // 参考图的绿色 + cursor: pointer; + + .item-bullet { + line-height: 1; + } + + .item-text { + line-height: 1.4; + } + + &:active { + opacity: 0.7; + } } } diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js index ac47518..bad8dee 100644 --- a/im-uniapp/store/chatStore.js +++ b/im-uniapp/store/chatStore.js @@ -165,12 +165,26 @@ export default defineStore('chatStore', { let chat = this.findChat(chatInfo); let message = this.findMessage(chat, msgInfo); if (message) { - console.log("message:", message) - Object.assign(message, msgInfo); - chat.stored = false; - this.saveToStorage(); - return; - } + console.log("message:", message) + + // ✅ 方式1:使用 Vue.set 或 $set 确保响应式更新 + // 先删除旧消息 + const msgIndex = chat.messages.findIndex(m => + (m.id && m.id === msgInfo.id) || + (m.tmpId && m.tmpId === msgInfo.tmpId) + ); + + if (msgIndex !== -1) { + // 创建新对象而不是修改原对象 + const updatedMessage = { ...message, ...msgInfo }; + // 使用 splice 替换,确保响应式 + chat.messages.splice(msgIndex, 1, updatedMessage); + } + + chat.stored = false; + this.saveToStorage(); + return; + } // 会话列表内容 if (msgInfo.type == MESSAGE_TYPE.IMAGE) { chat.lastContent = "[图片]"; diff --git a/im-web/src/components/chat/ChatBox.vue b/im-web/src/components/chat/ChatBox.vue index 47886c7..c9cb325 100644 --- a/im-web/src/components/chat/ChatBox.vue +++ b/im-web/src/components/chat/ChatBox.vue @@ -985,11 +985,7 @@ export default { loadQuickReplyList() { this.quickLoading = true; // 传当前登录用户的 ID 给后端 - this.$http.get("/quick/reply/list", { - params: { - userId: this.mine.id - } - }) + this.$http.get("/quick/reply/list") .then(res => { if (res && Array.isArray(res)) { console.log('快捷回复数据:', res);