commit
dec23c473a
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* @Author: ch
|
||||||
|
* @Date: 2022-06-07 15:52:37
|
||||||
|
* @LastEditors: ch
|
||||||
|
* @LastEditTime: 2022-06-09 10:59:15
|
||||||
|
* @Description: file content
|
||||||
|
*/
|
||||||
|
import * as api from '@/api/chat';
|
||||||
|
import config from '@/configs';
|
||||||
|
import $store from '@/store';
|
||||||
|
import MsbIm from '@/utils/msb-im';
|
||||||
|
import { FormatJsonSearch, ToAsyncAwait } from '@/utils/utils';
|
||||||
|
const Im = new MsbIm({
|
||||||
|
reconnect: true,
|
||||||
|
});
|
||||||
|
const ImInit = () => {
|
||||||
|
return new Promise((reslove, reject) => {
|
||||||
|
const storeUc = $store.state.auth.userInfo;
|
||||||
|
if (!storeUc) {
|
||||||
|
ImInit();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
api.getCustomeServiceTicket().then(async (res) => {
|
||||||
|
const par = FormatJsonSearch({
|
||||||
|
client: res.client,
|
||||||
|
ticket: res.ticket,
|
||||||
|
user: storeUc.userId,
|
||||||
|
// nickname: storeUc.employeeName,
|
||||||
|
// avatar: storeUc.avatar,
|
||||||
|
// 1普通用户 2客服链接
|
||||||
|
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({
|
||||||
|
url: `${config.socketURL}${par}`,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
reslove(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Im.interceptors.dataChangeAfter = () => {
|
||||||
|
$store.commit('im/SET_SESSION_DATA', JSON.parse(JSON.stringify(Im.sessionData)));
|
||||||
|
// let msgCount = 0;
|
||||||
|
// Im.sessionData.forEach((i) => {
|
||||||
|
// msgCount += i.unreadCount;
|
||||||
|
// });
|
||||||
|
// $store.commit('SET_IM_MSG_COUNT', msgCount);
|
||||||
|
};
|
||||||
|
|
||||||
|
Im.interceptors.onLogout = () => {
|
||||||
|
Im.setSessionData([]);
|
||||||
|
// Im.setCurSessionId(null);
|
||||||
|
$store.commit('im/SET_SESSION_DATA', []);
|
||||||
|
// $store.commit('SET_IM_MSG_COUNT', 0);
|
||||||
|
};
|
||||||
|
export { Im, ImInit };
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* @Author: ch
|
||||||
|
* @Date: 2022-06-07 11:34:12
|
||||||
|
* @LastEditors: ch
|
||||||
|
* @LastEditTime: 2022-06-07 16:12:42
|
||||||
|
* @Description: file content
|
||||||
|
*/
|
||||||
|
|
||||||
|
//生成UUID
|
||||||
|
const CreateUUID = () => {
|
||||||
|
let d = _.now();
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
|
var r = (d + _.random(16)) % 16 | 0;
|
||||||
|
d = Math.floor(d / 16);
|
||||||
|
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const ToAsyncAwait = (promise, fromatResult = true) => {
|
||||||
|
if (!fromatResult) {
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
return promise.then((res) => ({ error: null, result: res })).catch((err) => ({ error: err, result: null }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormatJsonSearch = (myJson, connector = '?') => {
|
||||||
|
if (myJson.constructor !== Object) {
|
||||||
|
throw new Error('必须是JSON对象');
|
||||||
|
}
|
||||||
|
let arr = [];
|
||||||
|
for (let i in myJson) {
|
||||||
|
arr.push(`${i}=${encodeURIComponent(myJson[i])}`);
|
||||||
|
}
|
||||||
|
return `${connector}${arr.join('&')}`;
|
||||||
|
};
|
||||||
|
export { CreateUUID, ToAsyncAwait, FormatJsonSearch };
|
Loading…
Reference in new issue