msb_beta
ch 3 years ago
parent 4650f597dd
commit ea6628172b

@ -2,15 +2,15 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 16:52:28 * @Date: 2022-03-22 16:52:28
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-26 17:52:05 * @LastEditTime: 2022-04-26 19:04:27
* @Description: 所有工具类统一在这输出 * @Description: 所有工具类统一在这输出
*/ */
import * as util from './utils'; import * as util from './utils';
import * as requset from './requset'; import * as requset from './requset';
// import * as websocket from './requset'; import * as websocket from './requset';
export * from './utils'; export * from './utils';
export * from './requset'; export * from './requset';
// export * from './websocket'; export * from './websocket';
export default { ...util, ...requset} export default { ...util, ...requset, ...websocket}

@ -2,16 +2,16 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 17:42:32 * @Date: 2022-03-17 17:42:32
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-26 18:13:01 * @LastEditTime: 2022-04-26 18:35:18
* @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法 * @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法
*/ */
import MsbUniRequest from '@/common/plugins/msbUniRequest'; import MsbUniRequest from '@/common/plugins/msbUniRequest';
import $store from '@/common/store'; import $store from '@/common/store';
const ENV = 'prod'; const ENV = 'test';
const BASE_URL = { const BASE_URL = {
'test' : 'https://like-app.mashibing.com/test', 'test' : 'https://k8s-horse-gateway.mashibing.cn',
// 'test' : '', // 'test' : '',
'release' : '', 'release' : '',
'prod' : '//like-gateway.mashibing.com' 'prod' : '//like-gateway.mashibing.com'

@ -2,105 +2,113 @@
* @Author: ch * @Author: ch
* @Date: 2022-04-25 14:39:19 * @Date: 2022-04-25 14:39:19
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-26 16:28:01 * @LastEditTime: 2022-04-27 10:12:40
* @Description: file content * @Description: file content
*/ */
import store from "../store"; import store from "../store";
import {createUUID, formatDate} from '@/common/utils'; import {createUUID, formatDate} from '@/common/utils';
export const MsbWebSkt = uni.connectSocket({
url : `ws://192.168.10.92:8090/ws?client=${store.state.token}`, // url是websocket连接ip
success: () => {
console.log('websocket连接成功')
},
fail: e => {
console.log('连接失败' + e)
}
});
MsbWebSkt.onClose(()=>{
console.log('WebSocket关闭...')
})
let sessionListFlag = false; let sessionListFlag = false;
MsbWebSkt.onMessage((res)=>{ const sessionList = (ctx) => {
const data = JSON.parse(res.data || {}); sessionListFlag = true;
if(data.code === 200){ // 来新消息先查会话列表是否一存在,存在则加消息数。不存在则向会话列表加一个会话框
const ctx = data.content; ctx.sessionVOS.forEach(item => {
switch(data.traceType){ item.lastMessage.createTimeStamp = formatDate(item.lastMessage.createTimeStamp, 'mm-dd hh:ii')
// 会话列表 item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {});
case 1 : let historyData = store.state.sessionData;
sessionListFlag = true; let hisIndex = historyData.findIndex(i => i.id === item.id);
// 来新消息先查会话列表是否一存在,存在则加消息数。不存在则向会话列表加一个会话框 if(hisIndex >= 0){
ctx.sessionVOS.forEach(item => { historyData[hisIndex].lastMessage = item.lastMessage;
item.lastMessage.createTimeStamp = formatDate(item.lastMessage.createTimeStamp, 'mm-dd hh:ii') historyData[hisIndex].unreadCount++;
item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {}); store.commit('SET_SESSION_DATA', historyData);
let historyData = store.state.sessionData; }else{
let hisIndex = historyData.findIndex(i => i.id === item.id); item.messageList = [];
if(hisIndex >= 0){ store.commit('SET_SESSION_DATA',[...historyData, item]);
historyData[hisIndex].lastMessage = item.lastMessage; }
historyData[hisIndex].unreadCount++; });
store.commit('SET_SESSION_DATA', historyData); // 消息总数
}else{ store.commit('SET_SESSION_MSG_COUNT', ctx.totalUnreadCount || 10);
item.messageList = []; }
store.commit('SET_SESSION_DATA',[...historyData, item]); const historyMsg = (ctx) => {
} let newData = store.state.sessionData;
}); const hisIdx = newData.findIndex(i => i.id === ctx[0].sessionId);
// 消息总数 ctx.forEach(item => {
store.commit('SET_SESSION_MSG_COUNT', ctx.totalUnreadCount || 10); item.createTimeStamp = formatDate(item.createTimeStamp, 'mm-dd hh:ii')
break; item.payload = JSON.parse(item.payload)
// 历史消息 })
case 2 : newData[hisIdx].messageList = ctx.concat(newData[hisIdx].messageList);
let newData = store.state.sessionData; store.commit('SET_SESSION_DATA', newData);
const hisIdx = newData.findIndex(i => i.id === ctx[0].sessionId); }
ctx.forEach(item => {
item.createTimeStamp = formatDate(item.createTimeStamp, 'mm-dd hh:ii')
item.payload = JSON.parse(item.payload)
})
newData[hisIdx].messageList = ctx.concat(newData[hisIdx].messageList);
store.commit('SET_SESSION_DATA', newData);
console.log(newData);
break;
// 会话消息
case 7 :
// 没接到会话列表时接到的消息不做处理
if(!sessionListFlag){
break;
}
// ctx.forEach(item => {
ctx.payload = JSON.parse(ctx.payload || {});
let historyData = store.state.sessionData;
const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId);
store.commit('SET_SESSION_MSG_COUNT', store.state.sessionMsgCount + 1);
if(hisIndex >= 0){
// 存在会话往现有会话增加一条消息
const curHisData = historyData[hisIndex];
curHisData.messageList = [ ...(curHisData.messageList || []), ctx]
curHisData.unreadCount++;
store.commit('SET_SESSION_DATA', historyData);
}else{ const sessionMsg = (ctx)=>{
// 会话列表不存在,则创建一个会话 // 没接到会话列表时接到的消息不做处理
store.commit('SET_SESSION_DATA',[...historyData, { if(!sessionListFlag){
fromAvatar : ctx.fromAvatar, return
fromId : ctx.fromId, }
fromNickname : ctx.fromNickname, // ctx.forEach(item => {
id : ctx.id, ctx.payload = JSON.parse(ctx.payload || {});
lastMessage : ctx, let historyData = store.state.sessionData;
messageList : [ctx], const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId);
unreadCount : 1 store.commit('SET_SESSION_MSG_COUNT', store.state.sessionMsgCount + 1);
}]); if(hisIndex >= 0){
} // 存在会话往现有会话增加一条消息
const curHisData = historyData[hisIndex];
// }); curHisData.messageList = [ ...(curHisData.messageList || []), ctx]
break; curHisData.unreadCount++;
default : store.commit('SET_SESSION_DATA', historyData);
break;
} }else{
// 会话列表不存在,则创建一个会话
store.commit('SET_SESSION_DATA',[...historyData, {
fromAvatar : ctx.fromAvatar,
fromId : ctx.fromId,
fromNickname : ctx.fromNickname,
id : ctx.id,
lastMessage : ctx,
messageList : [ctx],
unreadCount : 1
}]);
} }
})
// });
}
export let MsbWebSkt = null;
MsbWebSkt.onError(()=>{ export const MsbWebSktInit = () => {
console.log('WebSocket连接错误') return new Promise((resolve, reject) => {
}) MsbWebSkt = uni.connectSocket({
url : `ws://192.168.10.92:8090/ws?client=${store.state.token}`, // url是websocket连接ip
fail: e => {
reject(e)
}
});
MsbWebSkt.onOpen(()=>{
MsbWebSkt.onMessage((res)=>{
const data = JSON.parse(res.data || {});
if(data.code === 200){
const ctx = data.content;
switch(data.traceType){
// 会话列表
case 1 :
sessionList(ctx);
break;
// 历史消息
case 2 :
historyMsg(ctx)
break;
// 会话消息
case 7 :
sessionMsg(ctx)
break;
default :
break;
}
}
})
resolve();
})
})
}

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2021-07-26 23:22:16 * @Date: 2021-07-26 23:22:16
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-26 17:45:58 * @LastEditTime: 2022-04-27 10:12:54
* @Description: file content * @Description: file content
*/ */
import Vue from 'vue'; import Vue from 'vue';
@ -12,28 +12,21 @@ import {router,RouterMount} from '@/common/router/index.js';
import uView from 'uview-ui'; import uView from 'uview-ui';
import store from '@/common/store'; import store from '@/common/store';
import Confirm from '@/components/mount/index'; import Confirm from '@/components/mount/index';
// import {MsbWebSkt, createUUID} from '@/common/utils'; import {MsbWebSkt, MsbWebSktInit, createUUID} from '@/common/utils';
if(store.state.token){
// 进入应用则向IM发起心跳包 以及获取IM会话数据 // 进入应用则向IM发起心跳包 以及获取IM会话数据
// MsbWebSkt.onOpen(()=>{ MsbWebSktInit().then(()=>{
// MsbWebSkt.send({ MsbWebSkt.send({
// data : JSON.stringify({ data : JSON.stringify({
// traceId : createUUID(), traceId : createUUID(),
// traceType : "1", traceType : "1",
// content: { sysId : "1"} content: { sysId : "1"}
// }) })
// }); });
// setInterval(()=>{ })
// MsbWebSkt.send({ }
// data : JSON.stringify({
// traceId : createUUID(),
// traceType : "0",
// content: { text : "ping"}
// })
// })
// }, 5000)
// });
Vue.use(router); Vue.use(router);

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-21 18:08:07 * @Date: 2022-03-21 18:08:07
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-25 10:43:11 * @LastEditTime: 2022-04-27 10:47:46
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -42,7 +42,6 @@
</view> </view>
</view> </view>
<u-loadmore :status="loadingStatus" color="#FF8384" iconColor="#FF8384" nomoreText="我也是有底线的啦~"/> <u-loadmore :status="loadingStatus" color="#FF8384" iconColor="#FF8384" nomoreText="我也是有底线的啦~"/>
</view> </view>
</template> </template>
<script> <script>

Loading…
Cancel
Save