Browse Source

修改userid上传方式、提示条样式

master
[yxf] 1 month ago
parent
commit
a7654255cc
  1. 4
      im-platform/src/main/java/com/bx/implatform/controller/AutoReplyController.java
  2. 7
      im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java
  3. 2
      im-platform/src/main/java/com/bx/implatform/service/AutoReplyService.java
  4. 2
      im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java
  5. 9
      im-platform/src/main/java/com/bx/implatform/service/impl/AutoReplyServiceImpl.java
  6. 9
      im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java
  7. 87
      im-uniapp/pages/chat/chat-box.vue
  8. 26
      im-uniapp/store/chatStore.js
  9. 6
      im-web/src/components/chat/ChatBox.vue

4
im-platform/src/main/java/com/bx/implatform/controller/AutoReplyController.java

@ -23,7 +23,7 @@ public class AutoReplyController {
@GetMapping("/list") @GetMapping("/list")
@Operation(summary = "获取常见问题列表", description = "前端聊天页调用") @Operation(summary = "获取常见问题列表", description = "前端聊天页调用")
public Result<List<AutoReplyVO>> getList(@RequestParam Long userId) { public Result<List<AutoReplyVO>> getList() {
return ResultUtils.success(AutoReplyService.getList(userId)); return ResultUtils.success(AutoReplyService.getList());
} }
} }

7
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 lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@ -20,11 +19,11 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class QuickReplyController { public class QuickReplyController {
private final QuickReplyService quickReplyService; private final QuickReplyService QuickReplyService;
@GetMapping("/list") @GetMapping("/list")
@Operation(summary = "获取快捷回复列表", description = "前端聊天页调用") @Operation(summary = "获取快捷回复列表", description = "前端聊天页调用")
public Result<List<QuickReplyVO>> getList(@RequestParam Long userId) { public Result<List<QuickReplyVO>> getList() {
return ResultUtils.success(quickReplyService.getList(userId)); return ResultUtils.success(QuickReplyService.getList());
} }
} }

2
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; import java.util.List;
public interface AutoReplyService { public interface AutoReplyService {
List<AutoReplyVO> getList(Long userId); List<AutoReplyVO> getList();
} }

2
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; import java.util.List;
public interface QuickReplyService { public interface QuickReplyService {
List<QuickReplyVO> getList(Long userId); List<QuickReplyVO> getList();
} }

9
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.AutoReplyMapper;
import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.mapper.UserMapper;
import com.bx.implatform.service.AutoReplyService; import com.bx.implatform.service.AutoReplyService;
import com.bx.implatform.session.SessionContext;
import com.bx.implatform.vo.AutoReplyVO; import com.bx.implatform.vo.AutoReplyVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -22,24 +23,22 @@ public class AutoReplyServiceImpl extends ServiceImpl<AutoReplyMapper, AutoReply
private final UserMapper userMapper; private final UserMapper userMapper;
@Override @Override
public List<AutoReplyVO> getList(Long userId) { public List<AutoReplyVO> getList() {
// 1. 根据前端传的 userId 查询用户 Long userId = SessionContext.getSession().getUserId();
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if (user == null) { if (user == null) {
return List.of(); return List.of();
} }
// 2. 拿到用户的 uniqueToken
String uniqueToken = user.getUniqueToken(); String uniqueToken = user.getUniqueToken();
// 3. 匹配常见问题
LambdaQueryWrapper<AutoReply> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AutoReply> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AutoReply::getUniqueToken, uniqueToken); wrapper.eq(AutoReply::getUniqueToken, uniqueToken);
wrapper.orderByAsc(AutoReply::getCreatedTime); wrapper.orderByAsc(AutoReply::getCreatedTime);
List<AutoReply> list = this.list(wrapper); List<AutoReply> list = this.list(wrapper);
// 4. 转VO返回
return list.stream().map(item -> { return list.stream().map(item -> {
AutoReplyVO vo = new AutoReplyVO(); AutoReplyVO vo = new AutoReplyVO();
BeanUtils.copyProperties(item, vo); BeanUtils.copyProperties(item, vo);

9
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.QuickReplyMapper;
import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.mapper.UserMapper;
import com.bx.implatform.service.QuickReplyService; import com.bx.implatform.service.QuickReplyService;
import com.bx.implatform.session.SessionContext;
import com.bx.implatform.vo.QuickReplyVO; import com.bx.implatform.vo.QuickReplyVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -22,24 +23,22 @@ public class QuickReplyServiceImpl extends ServiceImpl<QuickReplyMapper, QuickRe
private final UserMapper userMapper; private final UserMapper userMapper;
@Override @Override
public List<QuickReplyVO> getList(Long userId) { public List<QuickReplyVO> getList() {
// 1. 根据前端传的 userId 查询用户 Long userId = SessionContext.getSession().getUserId();
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
if (user == null) { if (user == null) {
return List.of(); return List.of();
} }
// 2. 拿到用户的 uniqueToken
String uniqueToken = user.getUniqueToken(); String uniqueToken = user.getUniqueToken();
// 3. 匹配快捷回复
LambdaQueryWrapper<QuickReply> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<QuickReply> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(QuickReply::getUniqueToken, uniqueToken); wrapper.eq(QuickReply::getUniqueToken, uniqueToken);
wrapper.orderByAsc(QuickReply::getCreatedTime); wrapper.orderByAsc(QuickReply::getCreatedTime);
List<QuickReply> list = this.list(wrapper); List<QuickReply> list = this.list(wrapper);
// 4. 转VO返回
return list.stream().map(item -> { return list.stream().map(item -> {
QuickReplyVO vo = new QuickReplyVO(); QuickReplyVO vo = new QuickReplyVO();
BeanUtils.copyProperties(item, vo); BeanUtils.copyProperties(item, vo);

87
im-uniapp/pages/chat/chat-box.vue

@ -3,13 +3,14 @@
<nav-bar>{{ title }}</nav-bar> <nav-bar>{{ title }}</nav-bar>
<view class="chat-main-box" :style="{height: chatMainHeight+'px'}"> <view class="chat-main-box" :style="{height: chatMainHeight+'px'}">
<view class="chat-message" @click="switchChatTabBox('none')"> <view class="chat-message" @click="switchChatTabBox('none')">
<!-- 固定在聊天区顶部的常见问题提示条 --> <!-- 猜你想问 提示条 -->
<view v-if="showAutoQuestionTip" class="question-tip-fixed"> <view v-if="showAutoQuestionTip" class="guess-question-box">
<view class="tip-title">请选择您想咨询的问题</view> <view class="guess-title">猜你想问</view>
<view class="question-list"> <view class="guess-list">
<view class="question-item" v-for="(q, i) in commonQuestions" :key="i" <view class="guess-item" v-for="(q, i) in commonQuestions" :key="i"
@click="sendQuestionMessage(q)"> @click="sendQuestionMessage(q)">
{{ q }} <text class="item-bullet">*</text>
<text class="item-text">{{ q }}</text>
</view> </view>
</view> </view>
</view> </view>
@ -174,15 +175,13 @@ export default {
methods: { methods: {
loadCommonQuestions(userId) { loadCommonQuestions(userId) {
this.$http({ this.$http({
url: "/auto/reply/list?userId=" + userId, url: "/auto/reply/list" ,
method: 'get', method: 'get'
}).then(res => { }).then(res => {
// res.data
let list = res || []; let list = res || [];
this.autoReplyList = list; this.autoReplyList = list;
this.commonQuestions = list.map(item => item.replyTitle); this.commonQuestions = list.map(item => item.replyTitle);
}).catch(() => { }).catch(() => {
// this.commonQuestions = ["", "退", "", "", ""];
}); });
}, },
@ -201,7 +200,6 @@ export default {
receipt: this.isReceipt receipt: this.isReceipt
}; };
// ============== ==============
if (autoReply.replyType === 0) { if (autoReply.replyType === 0) {
// //
msgInfo.type = this.$enums.MESSAGE_TYPE.TEXT; msgInfo.type = this.$enums.MESSAGE_TYPE.TEXT;
@ -1373,42 +1371,55 @@ export default {
.scroll-box { .scroll-box {
height: 100%; height: 100%;
padding-top: 120rpx; /* 给常见问题条留出空间 */ padding-top: 180rpx; /* 给常见问题条留出空间 */
box-sizing: border-box; box-sizing: border-box;
} }
// //
.question-tip-fixed { .guess-question-box {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
z-index: 10; z-index: 10;
background-color: #ffffff; background-color: #F6F6F6;
padding: 12rpx 20rpx; padding: 20rpx 30rpx;
// border-bottom: 1rpx solid #f0f0f0; border-radius: 12rpx;
.tip-title { margin: 10rpx 20rpx;
font-size: 26rpx; box-sizing: border-box;
color: #999;
text-align: center; .guess-title {
margin-bottom: 8rpx; font-size: 32rpx;
color: #333333;
font-weight: 500;
margin-bottom: 20rpx;
} }
.question-list {
.guess-list {
display: flex; display: flex;
flex-wrap: wrap; flex-direction: column;
gap: 10rpx; gap: 16rpx;
justify-content: center;
} }
.question-item {
background-color: #f5f7fa; .guess-item {
border-radius: 30rpx; display: flex;
padding: 8rpx 16rpx; align-items: center;
font-size: 26rpx; gap: 10rpx;
color: #333; font-size: 30rpx;
border: 1rpx solid #eaeaea; color: #009E5F; // 绿
} cursor: pointer;
.question-item:active {
background-color: #e6e6e6; .item-bullet {
line-height: 1;
}
.item-text {
line-height: 1.4;
}
&:active {
opacity: 0.7;
}
} }
} }

26
im-uniapp/store/chatStore.js

@ -165,12 +165,26 @@ export default defineStore('chatStore', {
let chat = this.findChat(chatInfo); let chat = this.findChat(chatInfo);
let message = this.findMessage(chat, msgInfo); let message = this.findMessage(chat, msgInfo);
if (message) { if (message) {
console.log("message:", message) console.log("message:", message)
Object.assign(message, msgInfo);
chat.stored = false; // ✅ 方式1:使用 Vue.set 或 $set 确保响应式更新
this.saveToStorage(); // 先删除旧消息
return; 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) { if (msgInfo.type == MESSAGE_TYPE.IMAGE) {
chat.lastContent = "[图片]"; chat.lastContent = "[图片]";

6
im-web/src/components/chat/ChatBox.vue

@ -985,11 +985,7 @@ export default {
loadQuickReplyList() { loadQuickReplyList() {
this.quickLoading = true; this.quickLoading = true;
// ID // ID
this.$http.get("/quick/reply/list", { this.$http.get("/quick/reply/list")
params: {
userId: this.mine.id
}
})
.then(res => { .then(res => {
if (res && Array.isArray(res)) { if (res && Array.isArray(res)) {
console.log('快捷回复数据:', res); console.log('快捷回复数据:', res);

Loading…
Cancel
Save