|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
* @Author: ch
|
|
|
|
|
* @Date: 2022-04-25 14:39:19
|
|
|
|
|
* @LastEditors: ch
|
|
|
|
|
* @LastEditTime: 2022-04-28 14:43:16
|
|
|
|
|
* @LastEditTime: 2022-04-28 23:33:33
|
|
|
|
|
* @Description: file content
|
|
|
|
|
*/
|
|
|
|
|
import store from "../store";
|
|
|
|
@ -26,9 +26,13 @@ const sessionList = (ctx) => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 消息总数
|
|
|
|
|
store.commit('SET_SESSION_MSG_COUNT', ctx.totalUnreadCount || 10);
|
|
|
|
|
store.commit('SET_SESSION_MSG_COUNT', ctx.totalUnreadCount);
|
|
|
|
|
}
|
|
|
|
|
const historyMsg = (ctx) => {
|
|
|
|
|
if(!ctx.length){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
ctx.reverse();
|
|
|
|
|
let newData = store.state.sessionData;
|
|
|
|
|
const hisIdx = newData.findIndex(i => i.id === ctx[0].sessionId);
|
|
|
|
|
ctx.forEach(item => {
|
|
|
|
@ -38,23 +42,32 @@ const historyMsg = (ctx) => {
|
|
|
|
|
newData[hisIdx].messageList = ctx.concat(newData[hisIdx].messageList);
|
|
|
|
|
store.commit('SET_SESSION_DATA', newData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 收到某个会话的信息
|
|
|
|
|
* @param {*} ctx
|
|
|
|
|
*/
|
|
|
|
|
const sessionMsg = (ctx)=>{
|
|
|
|
|
// 没接到会话列表时接到的消息不做处理
|
|
|
|
|
if(!sessionListFlag){
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ctx.payload = JSON.parse(ctx.payload || {});
|
|
|
|
|
ctx.createTimeStamp = formatDate(ctx.createTimeStamp, 'mm-dd hh:ii')
|
|
|
|
|
let historyData = store.state.sessionData;
|
|
|
|
|
const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId);
|
|
|
|
|
store.commit('SET_SESSION_MSG_COUNT', store.state.sessionMsgCount + 1);
|
|
|
|
|
// 不在当前会话框则全局消息加1
|
|
|
|
|
if(ctx.sessionId !== store.state.sessionMsgId){
|
|
|
|
|
store.commit('SET_SESSION_MSG_COUNT', store.state.sessionMsgCount + 1);
|
|
|
|
|
}
|
|
|
|
|
if(hisIndex >= 0){
|
|
|
|
|
// 存在会话往现有会话增加一条消息
|
|
|
|
|
const curHisData = historyData[hisIndex];
|
|
|
|
|
curHisData.messageList = [ ...(curHisData.messageList || []), ctx]
|
|
|
|
|
curHisData.unreadCount++;
|
|
|
|
|
curHisData.messageList = [ ctx, ...(curHisData.messageList || [])]
|
|
|
|
|
// 不在当前会话框则会话框消息加1
|
|
|
|
|
if(ctx.sessionId !== store.state.sessionMsgId){
|
|
|
|
|
curHisData.unreadCount++;
|
|
|
|
|
}
|
|
|
|
|
store.commit('SET_SESSION_DATA', historyData);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
// 会话列表不存在,则创建一个会话
|
|
|
|
|
store.commit('SET_SESSION_DATA',[...historyData, {
|
|
|
|
|