Date: Fri, 10 Jun 2022 19:31:19 +0800
Subject: [PATCH 06/26] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=8D?=
=?UTF-8?q?=E8=83=BD=E5=B1=95=E7=A4=BA=E5=95=86=E5=93=81=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/msb-im.js | 9 +++++----
src/views/chat/message.vue | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/utils/msb-im.js b/src/utils/msb-im.js
index d72e5fe..2bec60b 100644
--- a/src/utils/msb-im.js
+++ b/src/utils/msb-im.js
@@ -2,12 +2,13 @@
* @Author: ch
* @Date: 2022-05-18 14:54:47
* @LastEditors: ch
- * @LastEditTime: 2022-06-10 10:10:21
+ * @LastEditTime: 2022-06-10 19:15:46
* @Description: file content
*/
import '@/utils/poto-req';
import '@/utils/proto-rsp';
import { CreateUUID, ToAsyncAwait } from '@/utils/utils';
+
const connect = Symbol('connect');
const send = Symbol('send');
const onMessage = Symbol('onMessage');
@@ -363,6 +364,9 @@ class MsbIm {
createTimeStamp: new Date().getTime(),
sendStatus: 'loading',
};
+ if (typeof msgCtx.payload === 'string') {
+ msgCtx.payload = JSON.parse(msgCtx.payload);
+ }
// 点发送,立即把消息加入消息列表,标记为发送中状态
curSession.messageList.push(msgCtx);
// 超过时间未返回视为发送失败
@@ -453,6 +457,3 @@ class MsbIm {
}
}
export default MsbIm;
-// export default (app) => {
-// app.config.globalProperties.$im = MsbIm;
-// };
diff --git a/src/views/chat/message.vue b/src/views/chat/message.vue
index 56e80d3..1d38efd 100644
--- a/src/views/chat/message.vue
+++ b/src/views/chat/message.vue
@@ -111,7 +111,7 @@
},
});
const messageType = computed(() => store.state.chat.messageType);
- const content = computed(() => store.getters['im/parseContent'](props.message.payload));
+ const content = computed(() => store.getters['im/parseContent']({ ...props.message.payload }));
const handleProduct = (id) => {
router.push({
name: 'UpdateProduct',
From 1f51e0ab063e6754efc41e907877aa66e1519210 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com>
Date: Sat, 11 Jun 2022 18:43:15 +0800
Subject: [PATCH 07/26] =?UTF-8?q?style:=20=E6=A0=B7=E5=BC=8F=E4=BC=98?=
=?UTF-8?q?=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/chat/index.vue | 1 +
src/views/chat/message.vue | 7 ++++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index 01a6c3f..d52d724 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -362,6 +362,7 @@
display: flex;
border: 1px solid #ebeef5;
.aside {
+ width: 240px;
border-right: 1px solid #ebeef5;
.aside-header {
height: 60px;
diff --git a/src/views/chat/message.vue b/src/views/chat/message.vue
index 1d38efd..b648613 100644
--- a/src/views/chat/message.vue
+++ b/src/views/chat/message.vue
@@ -22,7 +22,7 @@
商品编号:{{ content.id }}
-
复制
+
复制
@@ -228,5 +228,10 @@
}
}
}
+ &.--custom {
+ .message-body {
+ width: 300px;
+ }
+ }
}
From 19c29050dd0d09acc5bb31c8c5a29c5e45ccc292 Mon Sep 17 00:00:00 2001
From: ch
Date: Mon, 13 Jun 2022 14:20:23 +0800
Subject: [PATCH 08/26] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9im?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/chat/index.js | 12 +++++++++++-
src/store/modules/im/im.js | 14 ++++++++++++--
src/utils/im.js | 21 +++++----------------
src/views/chat/index.vue | 24 ++++++++++++++++++++----
4 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/src/api/chat/index.js b/src/api/chat/index.js
index ff501e6..47484c2 100644
--- a/src/api/chat/index.js
+++ b/src/api/chat/index.js
@@ -2,7 +2,7 @@
* @Author: xwk
* @Date: 2022-05-24 17:00:26
* @LastEditors: ch
- * @LastEditTime: 2022-06-09 10:10:47
+ * @LastEditTime: 2022-06-11 18:41:23
* @Description: file content
*/
import request from '@/utils/request.js';
@@ -52,6 +52,16 @@ export const getCustomeServiceTicket = () => {
},
});
};
+
+/**
+ * 获取当前客服
+ */
+export const getCustomerService = () => {
+ return request({
+ url: '/mall/im/admin/waiterUser/getWaiterByUserId',
+ method: 'get',
+ });
+};
/**
* 获取可转移客服列表
* @param {*} params
diff --git a/src/store/modules/im/im.js b/src/store/modules/im/im.js
index 10c64aa..760fe51 100644
--- a/src/store/modules/im/im.js
+++ b/src/store/modules/im/im.js
@@ -2,12 +2,13 @@
* @Author: ch
* @Date: 2022-06-07 15:41:05
* @LastEditors: ch
- * @LastEditTime: 2022-06-09 10:25:49
+ * @LastEditTime: 2022-06-13 14:03:18
* @Description: file content
*/
import * as api from '@/api/chat';
import dayjs from 'dayjs';
const state = {
+ curCustomerService: {},
sessionData: [],
customerServiceList: [],
messageType: { 1: 'text', 2: 'audio', 3: 'image', 4: 'video', 5: 'revoke', 6: 'custom', 7: 'notify' },
@@ -105,6 +106,9 @@ const getters = {
},
};
const mutations = {
+ SET_CUR_SERVICE(state, data) {
+ state.curCustomerService = data;
+ },
SET_SESSION_DATA(state, data) {
state.sessionData = data;
},
@@ -113,6 +117,12 @@ const mutations = {
},
};
const actions = {
+ queryCurCustomerService: ({ commit }) => {
+ api.getCustomerService().then((res) => {
+ commit('SET_CUR_SERVICE', res);
+ });
+ },
+
/**
* 查询可转移客服列表
*/
@@ -127,7 +137,7 @@ const actions = {
/**
* 提交转移会话
*/
- submitTransferSession: ({ dispatch }, data) => {
+ submitTransferSession: ({}, data) => {
api.transferCustomerService({
storeId: 1,
...data,
diff --git a/src/utils/im.js b/src/utils/im.js
index 2ad55fa..bbe97df 100644
--- a/src/utils/im.js
+++ b/src/utils/im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-07 15:52:37
* @LastEditors: ch
- * @LastEditTime: 2022-06-09 10:59:15
+ * @LastEditTime: 2022-06-13 14:14:26
* @Description: file content
*/
import * as api from '@/api/chat';
@@ -13,27 +13,16 @@ import { FormatJsonSearch, ToAsyncAwait } from '@/utils/utils';
const Im = new MsbIm({
reconnect: true,
});
-const ImInit = () => {
+const ImInit = (waiterId) => {
return new Promise((reslove, reject) => {
- const storeUc = $store.state.auth.userInfo;
- if (!storeUc) {
- ImInit();
- return false;
- }
+ console.log(waiterId, 'waiterId');
api.getCustomeServiceTicket().then(async (res) => {
+ console.log(res);
const par = FormatJsonSearch({
client: res.client,
ticket: res.ticket,
- user: storeUc.userId,
- // nickname: storeUc.employeeName,
- // avatar: storeUc.avatar,
- // 1普通用户 2客服链接
+ user: waiterId,
connect: 2,
- // user: 2,
- // client: 'yan_xuan',
- // ticket: '9kpEgiLzVG14znSTvElLOJE5MEMa/EGdexhab4CbDmLzDGnE+UXmVOvUs4ixyPeQ',
- // nickname: '周渺',
- // avatar: 'https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/桌面水果.jpg',
});
const { error, result } = await ToAsyncAwait(
Im.init({
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index 01a6c3f..5e369ec 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -149,10 +149,24 @@
const { proxy } = getCurrentInstance();
const router = useRouter();
const store = useStore();
-
- ImInit().then(() => {
- Im.getSessionList();
+ store.dispatch('im/queryCurCustomerService');
+ const socketInit = () => {
+ console.log('----', store.state.im.curCustomerService);
+ if (typeof store.state.im.curCustomerService !== 'string') {
+ setTimeout(() => {
+ socketInit();
+ }, 1000);
+ return false;
+ }
+ console.log('++++', typeof store.state.im.curCustomerService);
+ ImInit(store.state.im.curCustomerService).then(() => {
+ Im.getSessionList();
+ });
+ };
+ onMounted(() => {
+ socketInit();
});
+
const opts = computed(() => store.state.chat.opts);
// 统计
@@ -208,12 +222,14 @@
Im.getHistoryMsg();
};
const handleSendMessage = (e) => {
+ const curService = store.state.im.curCustomerService;
if (e && e.shiftKey) {
state.message += '\n';
} else {
if (state.message) {
Im.sendMsg({
- fromId: userInfo.value.userId,
+ fromId: curService.waiterId,
+ fromAvatar: curService.waiterAvatar,
content: {
toSessionId: currentSessionId.value,
payload: { text: state.message },
From f978bb9b3f56163378d52d8b3bb0b78958f7a3db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com>
Date: Mon, 13 Jun 2022 14:32:57 +0800
Subject: [PATCH 09/26] conf: eslint
---
.eslintignore | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.eslintignore b/.eslintignore
index 03c5c1d..5f0eb95 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -4,5 +4,5 @@ public
dist
node_modules
src/utils/msb-im.js
-src/utils/proto-rsq.js
+src/utils/poto-req.js
src/utils/proto-rsp.js
\ No newline at end of file
From ad989779a2ed5263c2bcdc318bad2ae94507df0a Mon Sep 17 00:00:00 2001
From: ch
Date: Mon, 13 Jun 2022 15:47:03 +0800
Subject: [PATCH 10/26] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=B8=8D=E8=83=BD?=
=?UTF-8?q?=E8=B7=B3=E5=88=B0=E6=9C=80=E5=BA=95=E4=B8=8B=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/chat/index.js | 2 +-
src/store/modules/im/im.js | 4 +--
src/utils/im.js | 3 +--
src/utils/msb-im.js | 4 ++-
src/views/chat/index.vue | 53 +++++++++++++++++++-------------------
5 files changed, 34 insertions(+), 32 deletions(-)
diff --git a/src/api/chat/index.js b/src/api/chat/index.js
index 47484c2..e98fb7d 100644
--- a/src/api/chat/index.js
+++ b/src/api/chat/index.js
@@ -2,7 +2,7 @@
* @Author: xwk
* @Date: 2022-05-24 17:00:26
* @LastEditors: ch
- * @LastEditTime: 2022-06-11 18:41:23
+ * @LastEditTime: 2022-06-13 14:26:53
* @Description: file content
*/
import request from '@/utils/request.js';
diff --git a/src/store/modules/im/im.js b/src/store/modules/im/im.js
index 760fe51..131dc85 100644
--- a/src/store/modules/im/im.js
+++ b/src/store/modules/im/im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-07 15:41:05
* @LastEditors: ch
- * @LastEditTime: 2022-06-13 14:03:18
+ * @LastEditTime: 2022-06-13 14:32:42
* @Description: file content
*/
import * as api from '@/api/chat';
@@ -107,7 +107,7 @@ const getters = {
};
const mutations = {
SET_CUR_SERVICE(state, data) {
- state.curCustomerService = data;
+ state.curCustomerService = data || {};
},
SET_SESSION_DATA(state, data) {
state.sessionData = data;
diff --git a/src/utils/im.js b/src/utils/im.js
index bbe97df..8a0bc70 100644
--- a/src/utils/im.js
+++ b/src/utils/im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-07 15:52:37
* @LastEditors: ch
- * @LastEditTime: 2022-06-13 14:14:26
+ * @LastEditTime: 2022-06-13 15:46:19
* @Description: file content
*/
import * as api from '@/api/chat';
@@ -15,7 +15,6 @@ const Im = new MsbIm({
});
const ImInit = (waiterId) => {
return new Promise((reslove, reject) => {
- console.log(waiterId, 'waiterId');
api.getCustomeServiceTicket().then(async (res) => {
console.log(res);
const par = FormatJsonSearch({
diff --git a/src/utils/msb-im.js b/src/utils/msb-im.js
index 2bec60b..b94d6bb 100644
--- a/src/utils/msb-im.js
+++ b/src/utils/msb-im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-18 14:54:47
* @LastEditors: ch
- * @LastEditTime: 2022-06-10 19:15:46
+ * @LastEditTime: 2022-06-13 15:16:50
* @Description: file content
*/
import '@/utils/poto-req';
@@ -369,6 +369,8 @@ class MsbIm {
}
// 点发送,立即把消息加入消息列表,标记为发送中状态
curSession.messageList.push(msgCtx);
+ this.setSessionData(this.sessionData);
+
// 超过时间未返回视为发送失败
this.timerStatus(msgCtx);
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index c38e8c2..843b884 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -68,16 +68,11 @@
-
+
加载更多
{
- console.log('----', store.state.im.curCustomerService);
- if (typeof store.state.im.curCustomerService !== 'string') {
+ if (!store.state.im.curCustomerService.waiterId) {
setTimeout(() => {
socketInit();
}, 1000);
return false;
}
- console.log('++++', typeof store.state.im.curCustomerService);
- ImInit(store.state.im.curCustomerService).then(() => {
+ ImInit(store.state.im.curCustomerService.waiterId).then(() => {
Im.getSessionList();
});
};
@@ -190,20 +183,24 @@
currentSessionId.value = id;
// 设置实例对象当前会话ID
Im.setCurSessionId(id);
+
// 已读
Im.setRead({
content: {
sessionId: id,
},
});
- if (!sessionMessageList.length) {
- Im.getHistoryMsg();
- }
+ setTimeout(() => {
+ if (!sessionMessageList.value.length) {
+ Im.getHistoryMsg();
+ }
+ }, 100);
};
// 聊天
- const sessionMessageList = computed(() => {
- return currentSession.messageList || [];
+ const sessionMessageList = ref([]);
+ watch(currentSession, () => {
+ sessionMessageList.value = currentSession.value.messageList || [];
});
const refsMessageList = ref(null);
watch(sessionMessageList, (value, old) => {
@@ -211,11 +208,11 @@
? refsMessageList.value.resize$.scrollHeight - refsMessageList.value.resize$.scrollTop
: 0;
nextTick(() => {
- if (!old?.length || value.indexOf(old[0]) === 0) {
- refsMessageList.value.setScrollTop(refsMessageList.value.resize$.scrollHeight);
- } else {
- refsMessageList.value.setScrollTop(refsMessageList.value.resize$.scrollHeight - offset);
- }
+ // if (!old?.length || value.indexOf(old[0]) === 0) {
+ refsMessageList.value.setScrollTop(refsMessageList.value.resize$.scrollHeight);
+ // } else {
+ // refsMessageList.value.setScrollTop(refsMessageList.value.resize$.scrollHeight - offset);
+ // }
});
});
const handleLoadMore = () => {
@@ -230,6 +227,7 @@
Im.sendMsg({
fromId: curService.waiterId,
fromAvatar: curService.waiterAvatar,
+ fromNickname: curService.waiterNickname,
content: {
toSessionId: currentSessionId.value,
payload: { text: state.message },
@@ -324,10 +322,11 @@
const file = e.target.files[0];
e.target.value = null;
let url = await upload('mall-product', 'im/', file);
- // store.dispatch('chat/submitImage', { url });
-
+ const curService = store.state.im.curCustomerService;
Im.sendMsg({
- fromId: 2, //userInfo.value.id,
+ fromId: curService.waiterId,
+ fromAvatar: curService.waiterAvatar,
+ fromNickname: curService.waiterNickname,
content: {
toSessionId: currentSessionId.value,
payload: { url },
@@ -347,8 +346,11 @@
let url = await upload('mall-product', 'im/', file);
// store.dispatch('chat/submitVideo', { url });
+ const curService = store.state.im.curCustomerService;
Im.sendMsg({
- fromId: 2, //userInfo.value.id,
+ fromId: curService.waiterId,
+ fromAvatar: curService.waiterAvatar,
+ fromNickname: curService.waiterNickname,
content: {
toSessionId: currentSessionId.value,
payload: { url },
@@ -378,7 +380,6 @@
display: flex;
border: 1px solid #ebeef5;
.aside {
- width: 240px;
border-right: 1px solid #ebeef5;
.aside-header {
height: 60px;
From d269b48e600f53e86e9d2656d5a912e27e8e05f8 Mon Sep 17 00:00:00 2001
From: ch
Date: Mon, 13 Jun 2022 16:34:00 +0800
Subject: [PATCH 11/26] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/store/modules/chat/chat copy.js | 363 ++++++++++++++++++++++++++++
src/store/modules/chat/chat.js | 265 ++++----------------
src/store/modules/im/im.js | 154 ------------
src/utils/im.js | 6 +-
src/views/chat/index.vue | 24 +-
src/views/chat/message.vue | 12 +-
6 files changed, 427 insertions(+), 397 deletions(-)
create mode 100644 src/store/modules/chat/chat copy.js
delete mode 100644 src/store/modules/im/im.js
diff --git a/src/store/modules/chat/chat copy.js b/src/store/modules/chat/chat copy.js
new file mode 100644
index 0000000..5ded1e6
--- /dev/null
+++ b/src/store/modules/chat/chat copy.js
@@ -0,0 +1,363 @@
+import { login } from '@/api/chat';
+import config from '@/configs';
+import { ElMessage } from '@/plugins/element-plus';
+import { UUID } from '@/utils/chat';
+import dayjs from 'dayjs';
+const state = () => ({
+ socket: null,
+ heart: null,
+ queue: [],
+ task: [],
+
+ currentSession: null,
+ messageList: [],
+ messageType: { 1: 'text', 2: 'audio', 3: 'image', 4: 'video', 5: 'revoke', 6: 'custom', 7: 'notify' },
+
+ curCustomerService: {},
+ sessionData: [],
+ customerServiceList: [],
+ opts: {
+ customerServiceType: [
+ {
+ label: '售前',
+ value: 1,
+ },
+ {
+ label: '售后',
+ value: 2,
+ },
+ {
+ label: '发货',
+ value: 3,
+ },
+ ],
+ },
+});
+const getters = {
+ parseTime: () => {
+ return (timestamp) => {
+ dayjs(new Date(timestamp)).format('MM-DD HH:mm:ss');
+ };
+ },
+ parseText: () => {
+ return ({ payload, type }) => {
+ if (type === 2) {
+ payload = '[语音]';
+ } else if (type === 3) {
+ payload = '[图片]';
+ } else if (type === 4) {
+ payload = '[视频]';
+ } else if (type === 5) {
+ payload = '[撤回消息]';
+ } else if (type === 6 || type === 1) {
+ try {
+ // payload = JSON.parse(payload);
+ if ('text' in payload) {
+ payload = payload.text;
+ } else if ('linkJump' in payload) {
+ payload = '[超链接]';
+ } else if ('orderNo' in payload) {
+ payload = '[订单信息]';
+ } else if ('productImageUrl' in payload) {
+ payload = '[商品信息]';
+ } else {
+ payload = '[未知数据]';
+ }
+ } catch (e) {
+ payload = '[解析异常]';
+ }
+ } else if (type === 7) {
+ payload = '[撤回消息]';
+ } else {
+ payload = '[未知类型]';
+ }
+ return payload;
+ };
+ },
+ parseImage: () => {
+ return (payload) => {
+ try {
+ // payload = JSON.parse(payload);
+ if ('url' in payload) {
+ payload = payload.url;
+ } else {
+ payload = '[未知图片]';
+ }
+ } catch (e) {
+ payload = '[解析异常]';
+ }
+ return payload;
+ };
+ },
+ parseVideo: () => {
+ return (payload) => {
+ try {
+ // payload = JSON.parse(payload);
+ if ('url' in payload) {
+ payload = payload.url;
+ } else {
+ payload = '[未知视频]';
+ }
+ } catch (e) {
+ payload = '[解析异常]';
+ }
+ return payload;
+ };
+ },
+ parseContent: () => {
+ return (payload) => {
+ try {
+ // payload = JSON.parse(payload);
+ if ('linkJump' in payload) {
+ payload.type = 'link';
+ } else if ('orderNo' in payload) {
+ payload.type = 'order';
+ } else if ('productImageUrl' in payload) {
+ payload.type = 'product';
+ } else {
+ payload = '[未知消息]';
+ }
+ } catch (e) {
+ payload = '[解析异常]';
+ }
+ return payload;
+ };
+ },
+};
+const mutations = {
+ setSocket: (state, data) => (state.socket = data),
+ setHeart: (state, data) => (state.heart = data),
+ setTask: (state, data) => (state.task = data),
+ addTask: (state, data) => state.task.push(data),
+ delTask: (state, data) => state.task.splice(data, 1),
+ setCurrentSession: (state, data) => (state.currentSession = data),
+ setSessionData: (state, data) => (state.sessionData = data),
+ setMessageList: (state, data) => (state.messageList = data),
+ setCustomerServiceList: (state, data) => (state.customerServiceList = data),
+
+ SET_CUR_SERVICE(state, data) {
+ state.curCustomerService = data || {};
+ },
+ SET_SESSION_DATA(state, data) {
+ state.sessionData = data;
+ },
+ SET_SERVICE_LIST(state, data) {
+ state.customerServiceList = data;
+ },
+};
+const actions = {
+ /**
+ * 创建连接
+ */
+ connect: async ({ state, commit, dispatch }) => {
+ let { ticket } = await login({ storeId: 1 });
+ return new Promise((resolve, reject) => {
+ if (window.WebSocket) {
+ const socket = new WebSocket(`${config.socketURL}?client=${ticket}&type=2`);
+ socket.onmessage = ({ data }) => {
+ dispatch('receive', data);
+ };
+ socket.onopen = () => {
+ commit(
+ 'setHeart',
+ setInterval(() => {
+ dispatch('heart');
+ }, 3000)
+ );
+ console.info('[chat] open');
+ resolve(socket);
+ };
+ socket.onclose = () => {
+ clearInterval(state.heart);
+ console.info('[chat] close');
+ };
+ socket.onerror = (e) => {
+ clearInterval(state.heart);
+ console.info('[chat] error', e);
+ reject(e);
+ };
+ commit('setSocket', socket);
+ } else {
+ ElMessage.error('当前浏览器不支持 WebSocket');
+ reject('not support websocket');
+ }
+ });
+ },
+ /**
+ * 发送心跳,任务监测
+ */
+ heart: ({ state, dispatch }) => {
+ dispatch('send', {
+ traceType: 26,
+ content: { storeId: 1 },
+ });
+ // console.info('[chat] heart');
+ state.task.forEach((item) => {
+ dispatch('send', item);
+ });
+ },
+ /**
+ * 执行任务
+ */
+ invoke: ({ commit, dispatch }, data) => {
+ data.traceId = UUID();
+ commit('addTask', data);
+ dispatch('send', data);
+ },
+ /**
+ * 撤销任务
+ */
+ revoke: ({ state, commit }, data) => {
+ console.info(state.task.length);
+ commit(
+ 'setTask',
+ state.task.filter((item) => item.traceType !== data)
+ );
+ console.info(state.task.length);
+ },
+ /**
+ * 发送数据
+ */
+ send: ({ state }, data) => {
+ if (window.WebSocket) {
+ if (state.socket?.readyState === WebSocket.OPEN) {
+ data.traceId = data.traceId || UUID();
+ state.socket.send(JSON.stringify(data));
+ if (data.traceType !== 26) {
+ console.info('[chat] send', data);
+ }
+ }
+ }
+ },
+ /**
+ * 接收数据
+ */
+ receive: ({ state, commit, dispatch }, data) => {
+ data = JSON.parse(data);
+ if (data.traceType !== 0) {
+ let index = state.task.findIndex((item) => item.traceId === data.traceId);
+ if (index !== -1) {
+ console.info('[chat] data', data);
+ commit('delTask', index);
+ dispatch('handle', data);
+ } else if (data.traceType === 25) {
+ console.info('[chat] msg', data);
+ dispatch('handle', data);
+ } else {
+ console.info('[chat] deprecated', data);
+ }
+ }
+ },
+ /**
+ * 处理数据
+ */
+ handle: ({ state, commit, dispatch }, { code, traceType, content }) => {
+ if (code === 200) {
+ switch (traceType) {
+ case 25: // 收到消息
+ if (content.sessionId === state.currentSession) {
+ commit('setMessageList', [...state.messageList, content]);
+ dispatch('submitRead');
+ } else {
+ dispatch('querySession');
+ }
+ break;
+ case 32: // 发送消息
+ commit('setMessageList', [...state.messageList, content]);
+ break;
+ case 27: // 会话列表
+ commit('setSessionData', content);
+ break;
+ case 28: // 消息列表
+ commit('setMessageList', [...content, ...state.messageList]);
+ break;
+ case 29: // 客服列表
+ commit('setCustomerServiceList', content);
+ break;
+ case 31: // 已读消息
+ dispatch('querySession');
+ break;
+ default:
+ break;
+ }
+ }
+ },
+ /**
+ * 查询会话列表
+ */
+ querySession: ({ dispatch }) => {
+ dispatch('invoke', {
+ traceType: 27,
+ content: { storeId: 1 },
+ });
+ },
+ /**
+ * 查询会话消息列表
+ */
+ querySessionMessage: ({ state, dispatch }, data) => {
+ dispatch('invoke', {
+ traceType: 28,
+ content: { sessionId: state.currentSession, size: 10, topMessageId: null, ...data },
+ });
+ },
+ /**
+ * 查询可转移客服列表
+ */
+ queryCustomerService: ({ dispatch }) => {
+ dispatch('invoke', {
+ traceType: 29,
+ content: { storeId: 1 },
+ });
+ },
+ /**
+ * 提交转移会话
+ */
+ submitTransferSession: ({ dispatch }, data) => {
+ dispatch('invoke', {
+ traceType: 30,
+ 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 },
+ });
+ },
+ /**
+ * 提交发送图片
+ */
+ submitImage: ({ state, dispatch }, payload) => {
+ dispatch('invoke', {
+ traceType: 32,
+ content: { payload, toSessionId: state.currentSession, type: 3 },
+ });
+ },
+ /**
+ * 提交发送视频
+ */
+ submitVideo: ({ state, dispatch }, payload) => {
+ dispatch('invoke', {
+ traceType: 32,
+ content: { payload, toSessionId: state.currentSession, type: 4 },
+ });
+ },
+};
+export default {
+ state,
+ getters,
+ mutations,
+ actions,
+};
diff --git a/src/store/modules/chat/chat.js b/src/store/modules/chat/chat.js
index 0785fed..1585d5a 100644
--- a/src/store/modules/chat/chat.js
+++ b/src/store/modules/chat/chat.js
@@ -1,18 +1,18 @@
-import { login } from '@/api/chat';
-import config from '@/configs';
-import { ElMessage } from '@/plugins/element-plus';
-import { UUID } from '@/utils/chat';
+/*
+ * @Author: ch
+ * @Date: 2022-06-07 15:41:05
+ * @LastEditors: ch
+ * @LastEditTime: 2022-06-13 16:30:57
+ * @Description: file content
+ */
+import * as api from '@/api/chat';
import dayjs from 'dayjs';
-const state = () => ({
- socket: null,
- heart: null,
- queue: [],
- task: [],
- sessionData: {},
- currentSession: null,
- messageList: [],
- messageType: { 1: 'text', 2: 'audio', 3: 'image', 4: 'video', 5: 'revoke', 6: 'custom', 7: 'notify' },
+const state = {
+ curCustomerService: {},
+ sessionData: [],
customerServiceList: [],
+ messageType: { 1: 'text', 2: 'audio', 3: 'image', 4: 'video', 5: 'revoke', 6: 'custom', 7: 'notify' },
+
opts: {
customerServiceType: [
{
@@ -29,7 +29,8 @@ const state = () => ({
},
],
},
-});
+};
+
const getters = {
parseTime: () => {
return (timestamp) => {
@@ -48,7 +49,7 @@ const getters = {
payload = '[撤回消息]';
} else if (type === 6 || type === 1) {
try {
- payload = JSON.parse(payload);
+ // payload = JSON.parse(payload.value);
if ('text' in payload) {
payload = payload.text;
} else if ('linkJump' in payload) {
@@ -74,7 +75,7 @@ const getters = {
parseImage: () => {
return (payload) => {
try {
- payload = JSON.parse(payload);
+ // payload = JSON.parse(payload);
if ('url' in payload) {
payload = payload.url;
} else {
@@ -89,7 +90,7 @@ const getters = {
parseVideo: () => {
return (payload) => {
try {
- payload = JSON.parse(payload);
+ // payload = JSON.parse(payload);
if ('url' in payload) {
payload = payload.url;
} else {
@@ -104,7 +105,7 @@ const getters = {
parseContent: () => {
return (payload) => {
try {
- payload = JSON.parse(payload);
+ // payload = JSON.parse(payload);
if ('linkJump' in payload) {
payload.type = 'link';
} else if ('orderNo' in payload) {
@@ -122,223 +123,43 @@ const getters = {
},
};
const mutations = {
- setSocket: (state, data) => (state.socket = data),
- setHeart: (state, data) => (state.heart = data),
- setTask: (state, data) => (state.task = data),
- addTask: (state, data) => state.task.push(data),
- delTask: (state, data) => state.task.splice(data, 1),
- setCurrentSession: (state, data) => (state.currentSession = data),
- setSessionData: (state, data) => (state.sessionData = data),
- setMessageList: (state, data) => (state.messageList = data),
- setCustomerServiceList: (state, data) => (state.customerServiceList = data),
-};
-const actions = {
- /**
- * 创建连接
- */
- connect: async ({ state, commit, dispatch }) => {
- let { ticket } = await login({ storeId: 1 });
- return new Promise((resolve, reject) => {
- if (window.WebSocket) {
- const socket = new WebSocket(`${config.socketURL}?client=${ticket}&type=2`);
- socket.onmessage = ({ data }) => {
- dispatch('receive', data);
- };
- socket.onopen = () => {
- commit(
- 'setHeart',
- setInterval(() => {
- dispatch('heart');
- }, 3000)
- );
- console.info('[chat] open');
- resolve(socket);
- };
- socket.onclose = () => {
- clearInterval(state.heart);
- console.info('[chat] close');
- };
- socket.onerror = (e) => {
- clearInterval(state.heart);
- console.info('[chat] error', e);
- reject(e);
- };
- commit('setSocket', socket);
- } else {
- ElMessage.error('当前浏览器不支持 WebSocket');
- reject('not support websocket');
- }
- });
- },
- /**
- * 发送心跳,任务监测
- */
- heart: ({ state, dispatch }) => {
- dispatch('send', {
- traceType: 26,
- content: { storeId: 1 },
- });
- // console.info('[chat] heart');
- state.task.forEach((item) => {
- dispatch('send', item);
- });
+ SET_CUR_SERVICE(state, data) {
+ state.curCustomerService = data || {};
},
- /**
- * 执行任务
- */
- invoke: ({ commit, dispatch }, data) => {
- data.traceId = UUID();
- commit('addTask', data);
- dispatch('send', data);
+ SET_SESSION_DATA(state, data) {
+ state.sessionData = data;
},
- /**
- * 撤销任务
- */
- revoke: ({ state, commit }, data) => {
- console.info(state.task.length);
- commit(
- 'setTask',
- state.task.filter((item) => item.traceType !== data)
- );
- console.info(state.task.length);
+ SET_SERVICE_LIST(state, data) {
+ state.customerServiceList = data;
},
- /**
- * 发送数据
- */
- send: ({ state }, data) => {
- if (window.WebSocket) {
- if (state.socket?.readyState === WebSocket.OPEN) {
- data.traceId = data.traceId || UUID();
- state.socket.send(JSON.stringify(data));
- if (data.traceType !== 26) {
- console.info('[chat] send', data);
- }
- }
- }
- },
- /**
- * 接收数据
- */
- receive: ({ state, commit, dispatch }, data) => {
- data = JSON.parse(data);
- if (data.traceType !== 0) {
- let index = state.task.findIndex((item) => item.traceId === data.traceId);
- if (index !== -1) {
- console.info('[chat] data', data);
- commit('delTask', index);
- dispatch('handle', data);
- } else if (data.traceType === 25) {
- console.info('[chat] msg', data);
- dispatch('handle', data);
- } else {
- console.info('[chat] deprecated', data);
- }
- }
- },
- /**
- * 处理数据
- */
- handle: ({ state, commit, dispatch }, { code, traceType, content }) => {
- if (code === 200) {
- switch (traceType) {
- case 25: // 收到消息
- if (content.sessionId === state.currentSession) {
- commit('setMessageList', [...state.messageList, content]);
- dispatch('submitRead');
- } else {
- dispatch('querySession');
- }
- break;
- case 32: // 发送消息
- commit('setMessageList', [...state.messageList, content]);
- break;
- case 27: // 会话列表
- commit('setSessionData', content);
- break;
- case 28: // 消息列表
- commit('setMessageList', [...content, ...state.messageList]);
- break;
- case 29: // 客服列表
- commit('setCustomerServiceList', content);
- break;
- case 31: // 已读消息
- dispatch('querySession');
- break;
- default:
- break;
- }
- }
- },
- /**
- * 查询会话列表
- */
- querySession: ({ dispatch }) => {
- dispatch('invoke', {
- traceType: 27,
- content: { storeId: 1 },
- });
- },
- /**
- * 查询会话消息列表
- */
- querySessionMessage: ({ state, dispatch }, data) => {
- dispatch('invoke', {
- traceType: 28,
- content: { sessionId: state.currentSession, size: 10, topMessageId: null, ...data },
+};
+const actions = {
+ queryCurCustomerService: ({ commit }) => {
+ api.getCustomerService().then((res) => {
+ commit('SET_CUR_SERVICE', res);
});
},
+
/**
* 查询可转移客服列表
*/
- queryCustomerService: ({ dispatch }) => {
- dispatch('invoke', {
- traceType: 29,
- content: { storeId: 1 },
+ queryCustomerService: ({ commit }) => {
+ api.customerServiceList({
+ length: 100,
+ pageIndex: 1,
+ }).then((res) => {
+ commit('SET_SERVICE_LIST', res.records);
});
},
/**
* 提交转移会话
*/
- submitTransferSession: ({ dispatch }, data) => {
- dispatch('invoke', {
- traceType: 30,
- 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 },
- });
- },
- /**
- * 提交发送图片
- */
- submitImage: ({ state, dispatch }, payload) => {
- dispatch('invoke', {
- traceType: 32,
- content: { payload, toSessionId: state.currentSession, type: 3 },
- });
- },
- /**
- * 提交发送视频
- */
- submitVideo: ({ state, dispatch }, payload) => {
- dispatch('invoke', {
- traceType: 32,
- content: { payload, toSessionId: state.currentSession, type: 4 },
+ submitTransferSession: ({}, data) => {
+ api.transferCustomerService({
+ storeId: 1,
+ ...data,
+ }).then((res) => {
+ console.log(res, 'resresres');
});
},
};
diff --git a/src/store/modules/im/im.js b/src/store/modules/im/im.js
deleted file mode 100644
index 131dc85..0000000
--- a/src/store/modules/im/im.js
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * @Author: ch
- * @Date: 2022-06-07 15:41:05
- * @LastEditors: ch
- * @LastEditTime: 2022-06-13 14:32:42
- * @Description: file content
- */
-import * as api from '@/api/chat';
-import dayjs from 'dayjs';
-const state = {
- curCustomerService: {},
- sessionData: [],
- customerServiceList: [],
- messageType: { 1: 'text', 2: 'audio', 3: 'image', 4: 'video', 5: 'revoke', 6: 'custom', 7: 'notify' },
-};
-
-const getters = {
- parseTime: () => {
- return (timestamp) => {
- dayjs(new Date(timestamp)).format('MM-DD HH:mm:ss');
- };
- },
- parseText: () => {
- return ({ payload, type }) => {
- if (type === 2) {
- payload = '[语音]';
- } else if (type === 3) {
- payload = '[图片]';
- } else if (type === 4) {
- payload = '[视频]';
- } else if (type === 5) {
- payload = '[撤回消息]';
- } else if (type === 6 || type === 1) {
- try {
- // payload = JSON.parse(payload.value);
- if ('text' in payload) {
- payload = payload.text;
- } else if ('linkJump' in payload) {
- payload = '[超链接]';
- } else if ('orderNo' in payload) {
- payload = '[订单信息]';
- } else if ('productImageUrl' in payload) {
- payload = '[商品信息]';
- } else {
- payload = '[未知数据]';
- }
- } catch (e) {
- payload = '[解析异常]';
- }
- } else if (type === 7) {
- payload = '[撤回消息]';
- } else {
- payload = '[未知类型]';
- }
- return payload;
- };
- },
- parseImage: () => {
- return (payload) => {
- try {
- // payload = JSON.parse(payload);
- if ('url' in payload) {
- payload = payload.url;
- } else {
- payload = '[未知图片]';
- }
- } catch (e) {
- payload = '[解析异常]';
- }
- return payload;
- };
- },
- parseVideo: () => {
- return (payload) => {
- try {
- // payload = JSON.parse(payload);
- if ('url' in payload) {
- payload = payload.url;
- } else {
- payload = '[未知视频]';
- }
- } catch (e) {
- payload = '[解析异常]';
- }
- return payload;
- };
- },
- parseContent: () => {
- return (payload) => {
- try {
- // payload = JSON.parse(payload);
- if ('linkJump' in payload) {
- payload.type = 'link';
- } else if ('orderNo' in payload) {
- payload.type = 'order';
- } else if ('productImageUrl' in payload) {
- payload.type = 'product';
- } else {
- payload = '[未知消息]';
- }
- } catch (e) {
- payload = '[解析异常]';
- }
- return payload;
- };
- },
-};
-const mutations = {
- SET_CUR_SERVICE(state, data) {
- state.curCustomerService = data || {};
- },
- SET_SESSION_DATA(state, data) {
- state.sessionData = data;
- },
- SET_SERVICE_LIST(state, data) {
- state.customerServiceList = data;
- },
-};
-const actions = {
- queryCurCustomerService: ({ commit }) => {
- api.getCustomerService().then((res) => {
- commit('SET_CUR_SERVICE', res);
- });
- },
-
- /**
- * 查询可转移客服列表
- */
- queryCustomerService: ({ commit }) => {
- api.customerServiceList({
- length: 100,
- pageIndex: 1,
- }).then((res) => {
- commit('SET_SERVICE_LIST', res.records);
- });
- },
- /**
- * 提交转移会话
- */
- submitTransferSession: ({}, data) => {
- api.transferCustomerService({
- storeId: 1,
- ...data,
- }).then((res) => {
- console.log(res, 'resresres');
- });
- },
-};
-export default {
- state,
- getters,
- mutations,
- actions,
-};
diff --git a/src/utils/im.js b/src/utils/im.js
index 8a0bc70..4017e7e 100644
--- a/src/utils/im.js
+++ b/src/utils/im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-07 15:52:37
* @LastEditors: ch
- * @LastEditTime: 2022-06-13 15:46:19
+ * @LastEditTime: 2022-06-13 16:18:45
* @Description: file content
*/
import * as api from '@/api/chat';
@@ -38,7 +38,7 @@ const ImInit = (waiterId) => {
};
Im.interceptors.dataChangeAfter = () => {
- $store.commit('im/SET_SESSION_DATA', JSON.parse(JSON.stringify(Im.sessionData)));
+ $store.commit('chat/SET_SESSION_DATA', JSON.parse(JSON.stringify(Im.sessionData)));
// let msgCount = 0;
// Im.sessionData.forEach((i) => {
// msgCount += i.unreadCount;
@@ -49,7 +49,7 @@ Im.interceptors.dataChangeAfter = () => {
Im.interceptors.onLogout = () => {
Im.setSessionData([]);
// Im.setCurSessionId(null);
- $store.commit('im/SET_SESSION_DATA', []);
+ $store.commit('chat/SET_SESSION_DATA', []);
// $store.commit('SET_IM_MSG_COUNT', 0);
};
export { Im, ImInit };
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index 843b884..6635a61 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -37,12 +37,12 @@
{{ item.fromNickname }}
- {{ store.getters['im/parseTime'](item.lastMessage.createTimeStamp) }}
+ {{ store.getters['chat/parseTime'](item.lastMessage.createTimeStamp) }}
- {{ store.getters['im/parseText'](item.lastMessage) }}
+ {{ store.getters['chat/parseText'](item.lastMessage) }}
@@ -144,15 +144,15 @@
const { proxy } = getCurrentInstance();
const router = useRouter();
const store = useStore();
- store.dispatch('im/queryCurCustomerService');
+ store.dispatch('chat/queryCurCustomerService');
const socketInit = () => {
- if (!store.state.im.curCustomerService.waiterId) {
+ if (!store.state.chat.curCustomerService.waiterId) {
setTimeout(() => {
socketInit();
}, 1000);
return false;
}
- ImInit(store.state.im.curCustomerService.waiterId).then(() => {
+ ImInit(store.state.chat.curCustomerService.waiterId).then(() => {
Im.getSessionList();
});
};
@@ -177,7 +177,7 @@
const state = reactive({
message: '',
});
- const sessionList = computed(() => store.state.im.sessionData);
+ const sessionList = computed(() => store.state.chat.sessionData);
const currentSession = computed(() => sessionList.value.find((item) => item.id === currentSessionId.value));
const handleChangeSession = (id) => {
currentSessionId.value = id;
@@ -219,7 +219,7 @@
Im.getHistoryMsg();
};
const handleSendMessage = (e) => {
- const curService = store.state.im.curCustomerService;
+ const curService = store.state.chat.curCustomerService;
if (e && e.shiftKey) {
state.message += '\n';
} else {
@@ -282,9 +282,9 @@
},
],
});
- const customerServiceList = computed(() => store.state.im.customerServiceList);
+ const customerServiceList = computed(() => store.state.chat.customerServiceList);
const handleTransferSession = () => {
- store.dispatch('im/queryCustomerService');
+ store.dispatch('chat/queryCustomerService');
transferVisible.value = true;
};
const handleConfirmTransfer = async (row) => {
@@ -293,7 +293,7 @@
confirmButtonText: '确定',
});
if (res.action === 'confirm') {
- store.dispatch('im/submitTransferSession', {
+ store.dispatch('chat/submitTransferSession', {
toWaiterId: row.waiterId,
sessionId: unref(currentSessionId),
reason: res.value,
@@ -322,7 +322,7 @@
const file = e.target.files[0];
e.target.value = null;
let url = await upload('mall-product', 'im/', file);
- const curService = store.state.im.curCustomerService;
+ const curService = store.state.chat.curCustomerService;
Im.sendMsg({
fromId: curService.waiterId,
fromAvatar: curService.waiterAvatar,
@@ -346,7 +346,7 @@
let url = await upload('mall-product', 'im/', file);
// store.dispatch('chat/submitVideo', { url });
- const curService = store.state.im.curCustomerService;
+ const curService = store.state.chat.curCustomerService;
Im.sendMsg({
fromId: curService.waiterId,
fromAvatar: curService.waiterAvatar,
diff --git a/src/views/chat/message.vue b/src/views/chat/message.vue
index b648613..8664409 100644
--- a/src/views/chat/message.vue
+++ b/src/views/chat/message.vue
@@ -73,26 +73,26 @@
- {{ store.getters['im/parseText'](props.message) }}
+ {{ store.getters['chat/parseText'](props.message) }}
- {{ store.getters['im/parseTime'](props.message.createTimeStamp) }}
+ {{ store.getters['chat/parseTime'](props.message.createTimeStamp) }}
@@ -111,7 +111,7 @@
},
});
const messageType = computed(() => store.state.chat.messageType);
- const content = computed(() => store.getters['im/parseContent']({ ...props.message.payload }));
+ const content = computed(() => store.getters['chat/parseContent']({ ...props.message.payload }));
const handleProduct = (id) => {
router.push({
name: 'UpdateProduct',
From 97639e79645eac9ef843f5375f30f25ae6b169e4 Mon Sep 17 00:00:00 2001
From: ch
Date: Mon, 13 Jun 2022 17:01:51 +0800
Subject: [PATCH 12/26] =?UTF-8?q?fix:=20=E6=96=87=E4=BB=B6=E6=A0=BC?=
=?UTF-8?q?=E5=BC=8F=E4=BA=8C=E6=AC=A1=E6=A0=A1=E9=AA=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/chat/index.vue | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index 6635a61..5cc2f24 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -320,6 +320,10 @@
};
const handleSendImage = async (e) => {
const file = e.target.files[0];
+ if (!file.type.includes('image')) {
+ proxy.$message.warning('只能发送图片哦~');
+ return false;
+ }
e.target.value = null;
let url = await upload('mall-product', 'im/', file);
const curService = store.state.chat.curCustomerService;
@@ -342,6 +346,10 @@
};
const handleSendVideo = async (e) => {
const file = e.target.files[0];
+ if (!file.type.includes('video')) {
+ proxy.$message.warning('只能发送视频哦~');
+ return false;
+ }
e.target.value = null;
let url = await upload('mall-product', 'im/', file);
// store.dispatch('chat/submitVideo', { url });
From c755ff3eb0fa09a026af61f18d13757ed1874105 Mon Sep 17 00:00:00 2001
From: ch
Date: Mon, 13 Jun 2022 19:50:12 +0800
Subject: [PATCH 13/26] =?UTF-8?q?fix:=E8=BD=AC=E7=A7=BB=E4=BC=9A=E8=AF=9D?=
=?UTF-8?q?=E4=B8=8D=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/store/modules/chat/chat.js | 18 ++++++++++--------
src/utils/im.js | 2 +-
src/utils/msb-im.js | 14 ++++++++------
src/views/chat/index.vue | 21 +++++++++++++--------
4 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/src/store/modules/chat/chat.js b/src/store/modules/chat/chat.js
index 1585d5a..c32a560 100644
--- a/src/store/modules/chat/chat.js
+++ b/src/store/modules/chat/chat.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-07 15:41:05
* @LastEditors: ch
- * @LastEditTime: 2022-06-13 16:30:57
+ * @LastEditTime: 2022-06-13 17:16:27
* @Description: file content
*/
import * as api from '@/api/chat';
@@ -65,7 +65,7 @@ const getters = {
payload = '[解析异常]';
}
} else if (type === 7) {
- payload = '[撤回消息]';
+ payload = payload.text;
} else {
payload = '[未知类型]';
}
@@ -155,12 +155,14 @@ const actions = {
* 提交转移会话
*/
submitTransferSession: ({}, data) => {
- api.transferCustomerService({
- storeId: 1,
- ...data,
- }).then((res) => {
- console.log(res, 'resresres');
- });
+ return api
+ .transferCustomerService({
+ storeId: 1,
+ ...data,
+ })
+ .then((res) => {
+ console.log(res, 'resresres');
+ });
},
};
export default {
diff --git a/src/utils/im.js b/src/utils/im.js
index 4017e7e..d369ebf 100644
--- a/src/utils/im.js
+++ b/src/utils/im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-06-07 15:52:37
* @LastEditors: ch
- * @LastEditTime: 2022-06-13 16:18:45
+ * @LastEditTime: 2022-06-13 17:32:19
* @Description: file content
*/
import * as api from '@/api/chat';
diff --git a/src/utils/msb-im.js b/src/utils/msb-im.js
index b94d6bb..ab6b843 100644
--- a/src/utils/msb-im.js
+++ b/src/utils/msb-im.js
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-18 14:54:47
* @LastEditors: ch
- * @LastEditTime: 2022-06-13 15:16:50
+ * @LastEditTime: 2022-06-13 18:54:30
* @Description: file content
*/
import '@/utils/poto-req';
@@ -193,9 +193,9 @@ class MsbIm {
newData = [
...historyData,
{
- fromAvatar: ctx.fromAvatar,
+ fromAvatar: ctx.session.fromAvatar,
fromId: ctx.fromId,
- fromNickname: ctx.fromNickname,
+ fromNickname: ctx.session.fromNickname,
id: ctx.sessionId,
lastMessage: ctx,
messageList: [ctx],
@@ -270,6 +270,7 @@ class MsbIm {
return Promise.reject(error);
}
const { content } = result;
+ let newData = [];
content.sessionVOS.forEach((item) => {
if (item.lastMessage) {
@@ -280,13 +281,14 @@ class MsbIm {
if (hisIndex >= 0) {
historyData[hisIndex].lastMessage = item.lastMessage;
historyData[hisIndex].unreadCount++;
- this.setSessionData(historyData);
+ newData.push(historyData);
} else {
item.messageList = [];
- const newData = [...historyData, item];
- this.setSessionData(newData);
+ newData = [...newData, item];
}
});
+
+ this.setSessionData(newData);
return Promise.resolve(result);
}
/**
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index 5cc2f24..cc3d89b 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -49,7 +49,7 @@
-