修改未读

feature/1.0.1-im-ch
ch 3 years ago
parent bd2ccede25
commit bf72b62c13

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-18 14:54:47 * @Date: 2022-05-18 14:54:47
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-21 16:11:44 * @LastEditTime: 2022-05-21 19:32:49
* @Description: file content * @Description: file content
*/ */
import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils"; import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils";
@ -110,7 +110,7 @@ export default class MsbIm {
} }
let ctx = data.content; let ctx = data.content;
ctx.payload = JSON.parse(ctx.payload || {}); ctx.payload = JSON.parse(ctx.payload || {});
let historyData = this.sessionData, let historyData = [...this.sessionData],
newData = []; newData = [];
const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId); const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId);
if(hisIndex >= 0){ if(hisIndex >= 0){
@ -135,6 +135,7 @@ export default class MsbIm {
unreadCount : 1 unreadCount : 1
}] }]
} }
this.setSessionData(newData)
} }
init (config) { init (config) {
@ -248,12 +249,14 @@ export default class MsbIm {
traceType : "6", traceType : "6",
...params ...params
}); });
for (let item of this.sessionData) { let newData = this.sessionData.map(item => {
if (item.sessionId === params.content.sessionId) { if (item.id == params.content.sessionId) {
item.unreadCount = 0; item.unreadCount = 0;
break;
}
} }
return item;
});
this.setSessionData(newData);
} }
/** /**
* 发送消息 * 发送消息

@ -2,18 +2,23 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-20 11:00:07 * @Date: 2022-05-20 11:00:07
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-21 15:59:39 * @LastEditTime: 2022-05-21 19:22:07
* @Description: file content * @Description: file content
*/ */
import MsbIm from '@/common/plugins/msbIm' ; 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'; import $store from '@/common/store';
const Im = new MsbIm({ const Im = new MsbIm({
reconnect: true, reconnect: true,
}); });
const ImInit = async () => { const ImInit = async () => {
const { error } = await ApiGetCurrentUser();
if (error) {
return false;
}
await ToAsyncAwait(Im.init({ await ToAsyncAwait(Im.init({
url: `wss://k8s-horse-gateway.mashibing.cn/ws?client=${$store.state.token}&type=1` 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 => { Im.sessionData.forEach(i => {
msgCount += i.unreadCount; msgCount += i.unreadCount;
}) })
console.log(Im.sessionData)
$store.commit('SET_IM_MSG_COUNT', msgCount); $store.commit('SET_IM_MSG_COUNT', msgCount);
} }

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 19:15:10 * @Date: 2022-03-17 19:15:10
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-20 10:02:24 * @LastEditTime: 2022-05-21 19:15:18
* @Description: 一些无法归类的公共方法容器 * @Description: 一些无法归类的公共方法容器
*/ */
@ -79,7 +79,8 @@ const IsDouble = (str) => {
* @param {number|string|Date} d 时间参数能被new Date识别的数字字符串日期 * @param {number|string|Date} d 时间参数能被new Date识别的数字字符串日期
* @param {string} fmt 时间格式参数 字符串类型 默认'yyyy/mm/dd' * @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秒 // 处理不识别的时间表示字符串如2020年01月01日00时00分00秒
if(date.constructor === String){ if(date.constructor === String){
date = date.replace(/\D+/ig,'/'); date = date.replace(/\D+/ig,'/');

@ -2,16 +2,16 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 16:13:00 * @Date: 2022-03-22 16:13:00
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-20 17:33:56 * @LastEditTime: 2022-05-21 19:11:50
* @Description: file content * @Description: file content
--> -->
<template> <template>
<view > <view >
<BsEmpty tips="暂时还没有消息哦~" v-if="!$store.state.imData.length" <BsEmpty tips="暂时还没有消息哦~" v-if="!sessionData.length"
:icon="require('@/static/message/empty.png')" /> :icon="require('@/static/message/empty.png')" />
<view class="msgItem" v-for="item in $store.state.imData" :key="item.id" <view class="msgItem" v-for="item in sessionData" :key="item.id"
@click="openMsg(item)"> @click="openMsg(item)">
<image class="msgItem--headImg" src="@/static/account/tx.png"></image> <image class="msgItem--headImg" :src="item.fromAvatar || require('@/static/message/xt.png')"></image>
<view class="msgItem--con"> <view class="msgItem--con">
<view> <view>
<text class="msgItem--title">{{item.fromNickname}}</text> <text class="msgItem--title">{{item.fromNickname}}</text>
@ -23,7 +23,7 @@
</text> </text>
</view> </view>
<view class="msgItem--right"> <view class="msgItem--right">
<text class="msgItem--time" v-if="item.lastMessage">{{item.lastMessage.createTimeStamp}}</text> <text class="msgItem--time" v-if="item.lastMessage">{{FormatDate(item.lastMessage.createTimeStamp, 'mm-dd hh:ii:ss')}}</text>
<u-badge class="msgItem--badge" :value="item.unreadCount"></u-badge> <u-badge class="msgItem--badge" :value="item.unreadCount"></u-badge>
</view> </view>
</view> </view>
@ -33,12 +33,13 @@
<script> <script>
import BsEmpty from '../../../components/BsEmpty.vue'; import BsEmpty from '../../../components/BsEmpty.vue';
import {MSG_TYPE} from '@/common/dicts/im'; import {MSG_TYPE} from '@/common/dicts/im';
import {FormatDate} from '@/common/utils';
export default { export default {
components: { BsEmpty }, components: { BsEmpty },
data (){ data (){
return { return {
msgType : MSG_TYPE, msgType : MSG_TYPE,
sessionData : this.$store.state.imData
} }
}, },
onShow(){ onShow(){
@ -46,7 +47,13 @@ export default {
this.$Router.push('/login'); this.$Router.push('/login');
} }
}, },
computed:{
sessionData (){
return this.$store.state.imData;
}
},
methods:{ methods:{
FormatDate,
openMsg(item){ openMsg(item){
if(item.type === 3){ if(item.type === 3){
this.$Router.push(`/messageChat?sessionId=${item.id}`); this.$Router.push(`/messageChat?sessionId=${item.id}`);

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-26 14:32:03 * @Date: 2022-03-26 14:32:03
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-21 11:39:26 * @LastEditTime: 2022-05-21 19:10:58
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -10,18 +10,18 @@
<view class="msg-item" v-for="item in msgData" :key="item.id"> <view class="msg-item" v-for="item in msgData" :key="item.id">
<view class="msg-item--title"> <view class="msg-item--title">
<text>{{item.payload.title }} {{item.id}}</text> <text>{{item.payload.title }} {{item.id}}</text>
<text class="msg-item--time">{{item.createTimeStamp}}</text> <text class="msg-item--time">{{FormatDate(item.createTimeStamp, 'mm-dd hh:ii:ss')}}</text>
</view> </view>
<view class="msg-item--con"> <view class="msg-item--con">
<image class="msg-item--img" src="@/static/message/xt.png" mode="widthFix"/> <image class="msg-item--img" src="@/static/message/xt.png" mode="widthFix"/>
<view class="msg-item--desc">{{item.payload.content}}</view> <view class="msg-item--desc">{{item.payload.content}}</view>
</view> </view>
</view> </view>
<u-loadmore status="loading" v-if="!msgData.length"/> <u-loadmore status="loading" v-if="!msgData || !msgData.length"/>
</view> </view>
</template> </template>
<script> <script>
import {Im, CreateUUID, ToAsyncAwait} from '@/common/utils'; import {Im, CreateUUID, ToAsyncAwait, FormatDate} from '@/common/utils';
export default { export default {
data(){ data(){
return {} return {}
@ -57,6 +57,7 @@ export default {
this.setTitle(); this.setTitle();
}, },
methods:{ methods:{
FormatDate : FormatDate,
/** /**
* 获取历史消息 * 获取历史消息
*/ */

Loading…
Cancel
Save