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 @@ - +