parent
3f501f0cce
commit
e593b5e7dd
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* @Author: ch
|
||||||
|
* @Date: 2022-06-07 15:41:05
|
||||||
|
* @LastEditors: ch
|
||||||
|
* @LastEditTime: 2022-06-08 14:45:05
|
||||||
|
* @Description: file content
|
||||||
|
*/
|
||||||
|
const state = {
|
||||||
|
sessionData: [],
|
||||||
|
};
|
||||||
|
const getters = {};
|
||||||
|
const mutations = {
|
||||||
|
SET_SESSION_DATA(state, data) {
|
||||||
|
state.sessionData = data;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const actions = {};
|
||||||
|
export default {
|
||||||
|
state,
|
||||||
|
getters,
|
||||||
|
mutations,
|
||||||
|
actions,
|
||||||
|
};
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* @Author: ch
|
||||||
|
* @Date: 2022-06-07 15:52:37
|
||||||
|
* @LastEditors: ch
|
||||||
|
* @LastEditTime: 2022-06-08 14:51:11
|
||||||
|
* @Description: file content
|
||||||
|
*/
|
||||||
|
import $store from '@/store';
|
||||||
|
import MsbIm from '@/utils/msb-im';
|
||||||
|
import { FormatJsonSearch, ToAsyncAwait } from '@/utils/utils';
|
||||||
|
const Im = new MsbIm({
|
||||||
|
reconnect: true,
|
||||||
|
});
|
||||||
|
const ImInit = async () => {
|
||||||
|
// const { error, result } = await ApiGetCurrentUser();
|
||||||
|
// if (error) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// const { error: er, result: res } = await ApiGetSoketTicket();
|
||||||
|
// if (er) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
const par = FormatJsonSearch({
|
||||||
|
// client: res.client,
|
||||||
|
// ticket: res.ticket,
|
||||||
|
client: 'yan_xuan',
|
||||||
|
ticket: '9kpEgiLzVG14znSTvElLOJE5MEMa/EGdexhab4CbDmLzDGnE+UXmVOvUs4ixyPeQ',
|
||||||
|
// 1普通用户 2客服链接
|
||||||
|
connect: 2,
|
||||||
|
user: 2,
|
||||||
|
// nickname: result.nickname,
|
||||||
|
nickname: '周渺',
|
||||||
|
// avatar: result.avatar,
|
||||||
|
avatar: 'https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/桌面水果.jpg',
|
||||||
|
});
|
||||||
|
await ToAsyncAwait(
|
||||||
|
Im.init({
|
||||||
|
url: `ws://192.168.10.94:8090/ws${par}`,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
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