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

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

@ -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, {

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

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