diff --git a/common/plugins/msbIm.js b/common/plugins/msbIm.js index 2669daf..a7cf50b 100644 --- a/common/plugins/msbIm.js +++ b/common/plugins/msbIm.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-18 14:54:47 * @LastEditors: ch - * @LastEditTime: 2022-05-21 16:11:44 + * @LastEditTime: 2022-05-21 19:32:49 * @Description: file content */ import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils"; @@ -110,7 +110,7 @@ export default class MsbIm { } let ctx = data.content; ctx.payload = JSON.parse(ctx.payload || {}); - let historyData = this.sessionData, + let historyData = [...this.sessionData], newData = []; const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId); if(hisIndex >= 0){ @@ -135,6 +135,7 @@ export default class MsbIm { unreadCount : 1 }] } + this.setSessionData(newData) } init (config) { @@ -248,12 +249,14 @@ export default class MsbIm { traceType : "6", ...params }); - for (let item of this.sessionData) { - if (item.sessionId === params.content.sessionId) { + let newData = this.sessionData.map(item => { + if (item.id == params.content.sessionId) { item.unreadCount = 0; - break; } - } + return item; + }); + + this.setSessionData(newData); } /** * 发送消息 diff --git a/common/utils/im.js b/common/utils/im.js index d97c967..797d5d4 100644 --- a/common/utils/im.js +++ b/common/utils/im.js @@ -2,18 +2,23 @@ * @Author: ch * @Date: 2022-05-20 11:00:07 * @LastEditors: ch - * @LastEditTime: 2022-05-21 15:59:39 + * @LastEditTime: 2022-05-21 19:22:07 * @Description: file content */ import MsbIm from '@/common/plugins/msbIm' ; -import {ToAsyncAwait} from '@/common/utils' ; +import { ToAsyncAwait } from '@/common/utils'; +import { ApiGetCurrentUser } from '@/common/api/account'; import $store from '@/common/store'; const Im = new MsbIm({ reconnect: true, }); const ImInit = async () => { + const { error } = await ApiGetCurrentUser(); + if (error) { + return false; + } await ToAsyncAwait(Im.init({ url: `wss://k8s-horse-gateway.mashibing.cn/ws?client=${$store.state.token}&type=1` })) @@ -25,6 +30,7 @@ Im.interceptors.dataChangeAfter = () => { Im.sessionData.forEach(i => { msgCount += i.unreadCount; }) + console.log(Im.sessionData) $store.commit('SET_IM_MSG_COUNT', msgCount); } diff --git a/common/utils/utils.js b/common/utils/utils.js index 7ef40fb..d75e33f 100644 --- a/common/utils/utils.js +++ b/common/utils/utils.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-17 19:15:10 * @LastEditors: ch - * @LastEditTime: 2022-05-20 10:02:24 + * @LastEditTime: 2022-05-21 19:15:18 * @Description: 一些无法归类的公共方法容器 */ @@ -79,7 +79,8 @@ const IsDouble = (str) => { * @param {number|string|Date} d 时间参数能被new Date识别的数字,字符串,日期 * @param {string} fmt 时间格式参数 字符串类型 默认'yyyy/mm/dd' */ -const FormatDate = (date, fmt = 'yyyy/mm/dd' ) =>{ +const FormatDate = (date = new Date(), fmt = 'yyyy/mm/dd') => { + // 处理不识别的时间表示字符串,如2020年01月01日00时00分00秒 if(date.constructor === String){ date = date.replace(/\D+/ig,'/'); diff --git a/pages/account/message/group.vue b/pages/account/message/group.vue index b8416f4..1db06c5 100644 --- a/pages/account/message/group.vue +++ b/pages/account/message/group.vue @@ -2,16 +2,16 @@ * @Author: ch * @Date: 2022-03-22 16:13:00 * @LastEditors: ch - * @LastEditTime: 2022-05-20 17:33:56 + * @LastEditTime: 2022-05-21 19:11:50 * @Description: file content -->