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