修改未读

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

@ -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);
}
/**
* 发送消息

@ -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);
}

@ -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,'/');

@ -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
-->
<template>
<view >
<BsEmpty tips="暂时还没有消息哦~" v-if="!$store.state.imData.length"
<BsEmpty tips="暂时还没有消息哦~" v-if="!sessionData.length"
: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)">
<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>
<text class="msgItem--title">{{item.fromNickname}}</text>
@ -23,7 +23,7 @@
</text>
</view>
<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>
</view>
</view>
@ -33,12 +33,13 @@
<script>
import BsEmpty from '../../../components/BsEmpty.vue';
import {MSG_TYPE} from '@/common/dicts/im';
import {FormatDate} from '@/common/utils';
export default {
components: { BsEmpty },
data (){
return {
msgType : MSG_TYPE,
sessionData : this.$store.state.imData
}
},
onShow(){
@ -46,7 +47,13 @@ export default {
this.$Router.push('/login');
}
},
computed:{
sessionData (){
return this.$store.state.imData;
}
},
methods:{
FormatDate,
openMsg(item){
if(item.type === 3){
this.$Router.push(`/messageChat?sessionId=${item.id}`);

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

Loading…
Cancel
Save