fix: 修改im

feat-im-0607-ch
ch 2 years ago
parent 71389fbb1a
commit 19c29050dd

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

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

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

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

Loading…
Cancel
Save