msb_beta
ch 3 years ago
parent b261a1ded9
commit 5a7809230b

File diff suppressed because one or more lines are too long

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 18:28:52 * @Date: 2022-03-22 18:28:52
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-25 19:24:25 * @LastEditTime: 2022-04-28 23:03:06
* @Description: file content * @Description: file content
*/ */
import Vue from 'vue' import Vue from 'vue'
@ -23,7 +23,7 @@ export default new Vuex.Store({
userInfo : JSON.parse(uni.getStorageSync(USER_INFO) || '{}'), userInfo : JSON.parse(uni.getStorageSync(USER_INFO) || '{}'),
address : JSON.parse(uni.getStorageSync(ADDRESS) || '[]'), address : JSON.parse(uni.getStorageSync(ADDRESS) || '[]'),
sessionData : [], sessionData : [],
sessionMsgData : {}, sessionMsgId : '',
sessionMsgCount : 0 sessionMsgCount : 0
}, },
mutations:{ mutations:{
@ -44,6 +44,9 @@ export default new Vuex.Store({
}, },
SET_SESSION_MSG_COUNT (state, data){ SET_SESSION_MSG_COUNT (state, data){
state.sessionMsgCount = data; state.sessionMsgCount = data;
},
SET_SESSION_MSG_ID (state, data){
state.sessionMsgId = data;
} }
}, },
actions : { actions : {

@ -2,7 +2,7 @@
* @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:35:18 * @LastEditTime: 2022-04-28 20:54:08
* @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法 * @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法
*/ */
@ -12,7 +12,7 @@ import $store from '@/common/store';
const ENV = 'test'; const ENV = 'test';
const BASE_URL = { const BASE_URL = {
'test' : 'https://k8s-horse-gateway.mashibing.cn', 'test' : 'https://k8s-horse-gateway.mashibing.cn',
// 'test' : '', 'dev' : '',
'release' : '', 'release' : '',
'prod' : '//like-gateway.mashibing.com' 'prod' : '//like-gateway.mashibing.com'
}; };
@ -28,7 +28,7 @@ const successIntercept = (response, option) =>{
if(result.code === 'SUCCESS'){ if(result.code === 'SUCCESS'){
return result.data; return result.data;
} }
if(result.code === 'TOKEN_EXPIRE'){ if(result.code === 'TOKEN_FAIL'){
uni.navigateTo({url : '/login'}) uni.navigateTo({url : '/login'})
return result; return result;
} }

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

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-22 16:13:00 * @Date: 2022-03-22 16:13:00
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-25 19:34:58 * @LastEditTime: 2022-04-28 23:02:54
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -10,7 +10,7 @@
<BsEmpty tips="暂时还没有消息哦~" v-if="!$store.state.sessionData.length" <BsEmpty tips="暂时还没有消息哦~" v-if="!$store.state.sessionData.length"
:icon="require('@/static/message/empty.png')" /> :icon="require('@/static/message/empty.png')" />
<view class="msgItem" v-for="item in $store.state.sessionData" :key="item.id" <view class="msgItem" v-for="item in $store.state.sessionData" :key="item.id"
@click="$Router.push(`/messageList?id=${item.id}`)"> @click="openMsg(item)">
<image class="msgItem--headImg" src="@/static/account/tx.png"></image> <image class="msgItem--headImg" src="@/static/account/tx.png"></image>
<view class="msgItem--con"> <view class="msgItem--con">
<view> <view>
@ -33,6 +33,12 @@ export default {
return { return {
sessionData : this.$store.state.sessionData sessionData : this.$store.state.sessionData
} }
},
methods:{
openMsg(item){
this.$store.commit('SET_SESSION_MSG_ID',item.id);
this.$Router.push(`/messageList`);
}
} }
} }
</script> </script>

@ -2,14 +2,14 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-26 14:32:03 * @Date: 2022-03-26 14:32:03
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-28 14:36:13 * @LastEditTime: 2022-04-28 23:43:35
* @Description: file content * @Description: file content
--> -->
<template> <template>
<view> <view>
<view class="msgItem" v-for="item in msgData" :key="item.id"> <view class="msgItem" v-for="item in msgData" :key="item.id">
<view class="msgItem--title"> <view class="msgItem--title">
<text>{{item.payload.title}}</text> <text>{{item.payload.title }} {{item.id}}</text>
<text class="msgItem--time">{{item.createTimeStamp}}</text> <text class="msgItem--time">{{item.createTimeStamp}}</text>
</view> </view>
<view class="msgItem--con"> <view class="msgItem--con">
@ -17,40 +17,73 @@
<view class="msgItem--desc">{{item.payload.content}}</view> <view class="msgItem--desc">{{item.payload.content}}</view>
</view> </view>
</view> </view>
<u-loadmore status="loading" v-if="!msgData.length"/>
</view> </view>
</template> </template>
<script> <script>
// import {MsbWebSkt, createUUID} from '@/common/utils'; import {MsbWebSkt, createUUID} from '@/common/utils';
export default { export default {
data(){
return {
}
},
computed:{ computed:{
curSessionData(){
return this.$store.state.sessionData.find(i =>i.id == this.$store.state.sessionMsgId)
},
msgData (){ msgData (){
// console.log(this.$store.state.sessionData,'---',this.$Route.query.id); return this.curSessionData ? this.curSessionData.messageList : [];
const sessionData = this.$store.state.sessionData.find(i =>i.id == this.$Route.query.id)
return sessionData ? sessionData.messageList : [];
} }
}, },
onReachBottom(){
this.getHistoryMsg();
},
onShow(){ onShow(){
if(!this.$store.state.sessionMsgId){
this.$Router.back();
return false
}
this.getHistoryMsg(); this.getHistoryMsg();
this.readMsg();
}, },
methods:{ methods:{
/**
* 获取历史消息
*/
getHistoryMsg(){ getHistoryMsg(){
MsbWebSkt.send({ this.loading = true;
data : JSON.stringify({ const lastMsg = this.msgData[this.msgData.length - 1] || {};
traceId : createUUID(), MsbWebSkt.send({
traceType : "2", data : JSON.stringify({
content: { sessionId : this.$Route.query.id} traceId : createUUID(),
}), traceType : "2",
success(){ content: {
console.log('suxx'); sessionId : this.$store.state.sessionMsgId,
}, topMessageId : lastMsg.id || null
fail(e){
console.log('fxx',e);
} }
}) })
})
}, },
xx(){ /**
console.log(this.$store.state.sessionData); * 已读消息
*/
readMsg(){
MsbWebSkt.send({
data : JSON.stringify({
traceId : createUUID(),
traceType : "6",
content: {
sessionId : this.$store.state.sessionMsgId
}
})
});
//
const count = this.$store.state.sessionMsgCount - this.curSessionData.unreadCount;
//
this.curSessionData.unreadCount = 0;
this.$store.commit('SET_SESSION_MSG_COUNT', count)
} }
} }
} }

Loading…
Cancel
Save