From 4f6cc776468ce43c9732c08053a8d1fa62746f1f Mon Sep 17 00:00:00 2001 From: PQZ Date: Tue, 5 Aug 2025 16:38:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/webSocket/WebSocketServer.java | 2 +- .../mapper/busi/BusiChatMainMapper.xml | 1 + dl_vue/src/App.vue | 1 + dl_vue/src/api/busi/chatMain.js | 8 +++ dl_vue/src/store/modules/websocket.js | 10 +++- dl_vue/src/views/busi/chatMain/chatForm.vue | 49 +++++++++++-------- dl_vue/src/views/busi/chatMain/index.vue | 45 ++++++++++------- 7 files changed, 77 insertions(+), 39 deletions(-) diff --git a/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/webSocket/WebSocketServer.java b/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/webSocket/WebSocketServer.java index 464da3a..a8b3505 100644 --- a/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/webSocket/WebSocketServer.java +++ b/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/webSocket/WebSocketServer.java @@ -95,7 +95,7 @@ public class WebSocketServer { public void CountPerson(String count){ for (String name : webSocketSet.keySet()){ try { - webSocketSet.get(name).session.getBasicRemote().sendText(count); + webSocketSet.get(name).session.getBasicRemote().sendText("close,"+name+"退出聊天"); }catch (Exception e){ e.printStackTrace(); } diff --git a/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiChatMainMapper.xml b/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiChatMainMapper.xml index 3f11fc8..21c52ee 100644 --- a/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiChatMainMapper.xml +++ b/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiChatMainMapper.xml @@ -24,6 +24,7 @@ + diff --git a/dl_vue/src/App.vue b/dl_vue/src/App.vue index 135df7d..5555206 100644 --- a/dl_vue/src/App.vue +++ b/dl_vue/src/App.vue @@ -28,6 +28,7 @@ export default { this.$store.dispatch('websocket_init', process.env.VUE_APP_WEBSOCKET+username) }, mounted(){ + //事件总线调起聊天记录弹窗 EventBus.$on('newMessage', (message) => { this.$refs.chatFrom.openForm() }); diff --git a/dl_vue/src/api/busi/chatMain.js b/dl_vue/src/api/busi/chatMain.js index f2f048e..c679475 100644 --- a/dl_vue/src/api/busi/chatMain.js +++ b/dl_vue/src/api/busi/chatMain.js @@ -26,6 +26,14 @@ export function addChatMain(data) { }) } +export function saveMessage(data) { + return request({ + url: '/web/saveMessage', + method: 'post', + data: data + }) +} + // 修改在线聊天 export function updateChatMain(data) { return request({ diff --git a/dl_vue/src/store/modules/websocket.js b/dl_vue/src/store/modules/websocket.js index 4b78f3a..e577995 100644 --- a/dl_vue/src/store/modules/websocket.js +++ b/dl_vue/src/store/modules/websocket.js @@ -19,7 +19,9 @@ const websocket = { } else if (e.data.startsWith("系统通知")){ state.notice.push(e.data); console.log(state.notice); - } else { + } else if (e.data.startsWith("close")){ + console.log(e.data) + }else { console.log(e.data,'消息内容') //这里捕获消息 const messageData = JSON.parse(e.data) @@ -42,6 +44,9 @@ const websocket = { }, WEBSOCKET_CLOSE(state){ state.socket.close(); + }, + SET_MESSAGE(state,msg){ + state.message = msg } }, @@ -54,6 +59,9 @@ const websocket = { }, websocket_close({commit}){ commit('WEBSOCKET_CLOSE') + }, + set_message({commit},msg){ + commit('SET_MESSAGE',msg) } } } diff --git a/dl_vue/src/views/busi/chatMain/chatForm.vue b/dl_vue/src/views/busi/chatMain/chatForm.vue index f4c2cd6..9499443 100644 --- a/dl_vue/src/views/busi/chatMain/chatForm.vue +++ b/dl_vue/src/views/busi/chatMain/chatForm.vue @@ -1,6 +1,6 @@ diff --git a/dl_vue/src/views/busi/chatMain/index.vue b/dl_vue/src/views/busi/chatMain/index.vue index 6d39c74..3c14ccb 100644 --- a/dl_vue/src/views/busi/chatMain/index.vue +++ b/dl_vue/src/views/busi/chatMain/index.vue @@ -96,7 +96,7 @@ - +