From 97f551719e6504e288688bf3d588b7e47c6a3e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Thu, 12 May 2022 20:51:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E5=B7=B2=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/chat/chat.js | 49 +++++++++++++++++++++++--------- src/views/chat/index.vue | 52 ++++++++++++++++++++-------------- src/views/chat/message.vue | 8 +++--- 3 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/store/modules/chat/chat.js b/src/store/modules/chat/chat.js index f0a06d6..9f9529c 100644 --- a/src/store/modules/chat/chat.js +++ b/src/store/modules/chat/chat.js @@ -36,11 +36,15 @@ const getters = { }, parseContent: () => { return (payload) => { - payload = JSON.parse(payload); - if ('text' in payload) { - payload = payload.text; - } else { - payload = '[未知消息]'; + try { + payload = JSON.parse(payload); + if ('text' in payload) { + payload = payload.text; + } else { + payload = '[未知消息]'; + } + } catch (e) { + payload = '[解析异常]'; } return payload; }; @@ -102,7 +106,7 @@ const actions = { traceType: 26, content: { storeId: 1 }, }); - console.info('[chat] heart'); + // console.info('[chat] heart'); state.task.forEach((item) => { dispatch('send', item); }); @@ -151,24 +155,23 @@ const actions = { handle: ({ state, commit, dispatch }, { code, traceType, content, session }) => { if (code === 200) { switch (traceType) { - // 收到消息 - case 25: + case 25: // 收到消息 if (session.id === state.currentSession) { commit('setMessageList', [...state.messageList, content.content]); } else { dispatch('querySession'); } break; - // 会话列表 - case 27: + case 32: // 发送消息 + commit('setMessageList', [...state.messageList, content]); + break; + case 27: // 会话列表 commit('setSessionData', content); break; - // 消息列表 - case 28: + case 28: // 消息列表 commit('setMessageList', content); break; - // 客服列表 - case 29: + case 29: // 客服列表 commit('setCustomerServiceList', content); break; default: @@ -212,6 +215,24 @@ const actions = { content: { storeId: 1, ...data }, }); }, + /** + * 提交已读消息 + */ + submitRead: ({ state, dispatch }) => { + dispatch('invoke', { + traceType: 31, + content: { sessionId: state.currentSession }, + }); + }, + /** + * 提交发送消息 + */ + submitMessage: ({ state, dispatch }, payload) => { + dispatch('invoke', { + traceType: 32, + content: { payload, toSessionId: state.currentSession, type: 1 }, + }); + }, }; export default { state, diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 7159bea..31badb4 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -120,6 +120,7 @@ :config="transferConfig" :data="customerServiceList" :operation="[]" + style="height: 500px" /> @@ -127,7 +128,8 @@