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")
@Operation(summary = "获取常见问题列表", description = "前端聊天页调用")
public Result<List<AutoReplyVO>> getList(@RequestParam Long userId) {
return ResultUtils.success(AutoReplyService.getList(userId));
public Result<List<AutoReplyVO>> getList() {
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 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<List<QuickReplyVO>> getList(@RequestParam Long userId) {
return ResultUtils.success(quickReplyService.getList(userId));
public Result<List<QuickReplyVO>> getList() {
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;
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;
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.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<AutoReplyMapper, AutoReply
private final UserMapper userMapper;
@Override
public List<AutoReplyVO> getList(Long userId) {
// 1. 根据前端传的 userId 查询用户
public List<AutoReplyVO> 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<AutoReply> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AutoReply::getUniqueToken, uniqueToken);
wrapper.orderByAsc(AutoReply::getCreatedTime);
List<AutoReply> list = this.list(wrapper);
// 4. 转VO返回
return list.stream().map(item -> {
AutoReplyVO vo = new AutoReplyVO();
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.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<QuickReplyMapper, QuickRe
private final UserMapper userMapper;
@Override
public List<QuickReplyVO> getList(Long userId) {
// 1. 根据前端传的 userId 查询用户
public List<QuickReplyVO> 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<QuickReply> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(QuickReply::getUniqueToken, uniqueToken);
wrapper.orderByAsc(QuickReply::getCreatedTime);
List<QuickReply> list = this.list(wrapper);
// 4. 转VO返回
return list.stream().map(item -> {
QuickReplyVO vo = new QuickReplyVO();
BeanUtils.copyProperties(item, vo);

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

@ -3,13 +3,14 @@
<nav-bar>{{ title }}</nav-bar>
<view class="chat-main-box" :style="{height: chatMainHeight+'px'}">
<view class="chat-message" @click="switchChatTabBox('none')">
<!-- 固定在聊天区顶部的常见问题提示条 -->
<view v-if="showAutoQuestionTip" class="question-tip-fixed">
<view class="tip-title">请选择您想咨询的问题</view>
<view class="question-list">
<view class="question-item" v-for="(q, i) in commonQuestions" :key="i"
<!-- 猜你想问 提示条 -->
<view v-if="showAutoQuestionTip" class="guess-question-box">
<view class="guess-title">猜你想问</view>
<view class="guess-list">
<view class="guess-item" v-for="(q, i) in commonQuestions" :key="i"
@click="sendQuestionMessage(q)">
{{ q }}
<text class="item-bullet">*</text>
<text class="item-text">{{ q }}</text>
</view>
</view>
</view>
@ -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;
}
.question-item {
background-color: #f5f7fa;
border-radius: 30rpx;
padding: 8rpx 16rpx;
font-size: 26rpx;
color: #333;
border: 1rpx solid #eaeaea;
flex-direction: column;
gap: 16rpx;
}
.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;
}
}
}

26
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 = "[图片]";

6
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);

Loading…
Cancel
Save