diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java index 897cc16..51fc9d6 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java @@ -87,6 +87,7 @@ public class UserServiceImpl extends ServiceImpl implements Us @Override public LoginVO login(LoginDTO dto) { + log.info("【测试】前端传的IP:{}", dto.getIp()); // 生成游客唯一标识UUID String guestUuid = UUID.randomUUID().toString(); @@ -96,21 +97,26 @@ public class UserServiceImpl extends ServiceImpl implements Us // 创建游客用户记录 User guestUser = new User(); guestUser.setUserName(guestUserName); - guestUser.setNickName(guestUserName); // 默认昵称为“游客” - guestUser.setPassword(""); // 游客无需密码,可为空 - guestUser.setUuid(guestUuid); // 保存唯一标识 -// guestUser.setCreateTime(LocalDateTime.now()); + guestUser.setNickName(guestUserName); + guestUser.setPassword(""); + guestUser.setUuid(guestUuid); + // ========== 先设置IP ========== + guestUser.setLastLoginIp(dto.getIp()); + // 保存到数据库 this.save(guestUser); - Long customerServiceId = this.getRandomCustomerServiceId(); + // ========== 正确更新 IP 和地址 ========== +// if(StrUtil.isNotBlank(dto.getIp())){ +// this.updateIpAndAddress(guestUser); +// } + + Long customerServiceId = this.getRandomCustomerServiceId(); - // 创建会话信息 UserSession guestSession = new UserSession(); guestSession.setUserId(guestUser.getId()); guestSession.setUserName(guestUser.getUserName()); guestSession.setTerminal(dto.getTerminal()); -// guestSession.setUuid(guestUuid); // 生成Token String guestJson = JSON.toJSONString(guestSession); @@ -134,12 +140,13 @@ public class UserServiceImpl extends ServiceImpl implements Us vo.setRefreshToken(refreshToken); vo.setRefreshTokenExpiresIn(jwtProperties.getRefreshTokenExpireIn()); vo.setCustomerServiceId(customerServiceId == null ? -1 : customerServiceId); - // 设置当前登录的游客用户信息 vo.setUser(guestUser); - log.info("游客登录成功,userId:{}, uuid:{}", guestUser.getId(), guestUuid); + log.info("游客登录成功,userId:{}, uuid:{}, ip:{}", guestUser.getId(), guestUuid, dto.getIp()); return vo; } + + public Long getRandomCustomerServiceId() { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); // 条件:is_customer = 2 表示客服 @@ -154,6 +161,7 @@ public class UserServiceImpl extends ServiceImpl implements Us return customerService == null ? null : customerService.getId(); } + @Override public LoginVO loginCustom(LoginDTO dto) { User user = this.findUserByUserName(dto.getUserName()); diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 4b9d4a4..6c61782 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -471,12 +471,13 @@ export default { // uni.switchTab({ // url: "/pages/chat/chat" // }) - uni.navigateTo({ - url: "/pages/chat/chat-box?chatIdx=0" - }) + // #endif // 初始化 this.init(); + uni.navigateTo({ + url: "/pages/chat/chat-box?chatIdx=0" + }) this.closeSplashscreen(0); }).catch(() => { // 跳转到登录页 @@ -484,6 +485,21 @@ export default { url: "/pages/login/login" }) }) + this.$nextTick(() => { + const btn = document.querySelector('.btn-send'); + if (btn) { + console.log('按钮找到:', btn); + // 获取所有事件监听器(需要浏览器支持) + const listeners = getEventListeners?.(btn); + console.log('按钮事件监听器:', listeners); + + // 手动绑定一个测试事件 + btn.addEventListener('click', (e) => { + console.log('原生点击事件触发'); + this.sendTextMessage(); + }); + } + }); } } diff --git a/im-uniapp/pages.json b/im-uniapp/pages.json index e4df795..539084b 100644 --- a/im-uniapp/pages.json +++ b/im-uniapp/pages.json @@ -79,36 +79,36 @@ "navigationBarBackgroundColor": "#f7f7f7", "backgroundColor": "#f7f7f7" }, - "tabBar": { - "color": "#000000", - "selectedColor": "#587ff0", - "borderStyle": "black", - "backgroundColor": "#ffffff", - "list": [{ - "pagePath": "pages/chat/chat", - "iconPath": "static/tab/chat.png", - "selectedIconPath": "static/tab/chat_active.png", - "text": "消息" - }, - { - "pagePath": "pages/friend/friend", - "iconPath": "static/tab/friend.png", - "selectedIconPath": "static/tab/friend_active.png", - "text": "好友" - }, - { - "pagePath": "pages/group/group", - "iconPath": "static/tab/group.png", - "selectedIconPath": "static/tab/group_active.png", - "text": "群聊" - }, - { - "pagePath": "pages/mine/mine", - "iconPath": "static/tab/mine.png", - "selectedIconPath": "static/tab/mine_active.png", - "text": "我的" - } - ] - }, + // "tabBar": { + // "color": "#000000", + // "selectedColor": "#587ff0", + // "borderStyle": "black", + // "backgroundColor": "#ffffff", + // "list": [{ + // "pagePath": "pages/chat/chat", + // "iconPath": "static/tab/chat.png", + // "selectedIconPath": "static/tab/chat_active.png", + // "text": "消息" + // }, + // { + // "pagePath": "pages/friend/friend", + // "iconPath": "static/tab/friend.png", + // "selectedIconPath": "static/tab/friend_active.png", + // "text": "好友" + // }, + // { + // "pagePath": "pages/group/group", + // "iconPath": "static/tab/group.png", + // "selectedIconPath": "static/tab/group_active.png", + // "text": "群聊" + // }, + // { + // "pagePath": "pages/mine/mine", + // "iconPath": "static/tab/mine.png", + // "selectedIconPath": "static/tab/mine_active.png", + // "text": "我的" + // } + // ] + // }, "uniIdRouter": {} } \ No newline at end of file diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 8a9ac3d..6c57486 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -1,6 +1,6 @@