pref:IM消息重发

fix/0523-ch
ch 3 years ago
parent 29b6ff483c
commit 5100284312

@ -3,7 +3,9 @@
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "npm run dev:h5",
"serve": "node env.config.js & npm run dev:h5",
"serve:bate": "node env.config.js --ENV:beta & npm run dev:h5",
"serve:prod": "node env.config.js --ENV:prod & npm run dev:h5",
"build": "npm run build:h5",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build:custom": "cross-env NODE_ENV=production uniapp-cli custom",

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-23 20:13:23
* @LastEditors: ch
* @LastEditTime: 2022-05-23 20:53:56
* @LastEditTime: 2022-05-24 10:00:15
* @Description: file content
-->
<script>
@ -20,6 +20,22 @@
</script>
<style>
/*每个页面公共css */
<style lang="scss">
/* 注意要写在第一行同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
view,text,textarea,input{
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-size: $font-size-base;
color: $color-grey6;
}
/* #ifdef H5 */
body{
padding-bottom: constant(safe-area-inset-bottom);
/* 兼容 iOS < 11.2 */
padding-bottom: env(safe-area-inset-bottom);
/* 兼容 iOS >= 11.2 */
}
/* #endif */
</style>

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-17 16:37:45
* @LastEditors: ch
* @LastEditTime: 2022-05-16 15:52:57
* @LastEditTime: 2022-05-24 17:25:25
* @Description: file content
*/
@ -18,7 +18,7 @@ export const ApiPostLogin = (data) => ToAsyncAwait(MsbRequest.post(`${BASE_URL}/
* 退出登录
* @param {*} data
*/
export const ApiGetLogout= () => ToAsyncAwait(MsbRequest.post(`${BASE_URL}/user/logout`));
export const ApiGetLogout= () => ToAsyncAwait(MsbRequest.get(`${BASE_URL}/user/logout`));
/**
* 获取手机验证码
* @param {*} params

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-18 14:54:47
* @LastEditors: ch
* @LastEditTime: 2022-05-21 19:32:49
* @LastEditTime: 2022-05-24 22:51:47
* @Description: file content
*/
import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils";
@ -52,6 +52,9 @@ export default class MsbIm {
this.socket.onOpen(() => {
this.socket.onMessage(async (res) => {
const result = JSON.parse(res.data);
if (result.content?.payload) {
result.content.payload = JSON.parse(result.content.payload);
}
// 401主动退出
if (result.code === 401) {
this.logout();
@ -109,7 +112,6 @@ export default class MsbIm {
return false;
}
let ctx = data.content;
ctx.payload = JSON.parse(ctx.payload || {});
let historyData = [...this.sessionData],
newData = [];
const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId);
@ -263,30 +265,72 @@ export default class MsbIm {
* @param {*} params
*/
async sendMsg(params) {
let curSession = this.sessionData.find(i => i.id === this.curSessionId);
curSession.messageList.push({
const index = this.sessionData.findIndex(i => i.id === this.curSessionId)
let curSession = this.sessionData[index];
// 临时消息体
let par = {
...params,
traceId: CreateUUID(),
traceType: 20,
}
let msgCtx = {
...params.content,
...par,
fromId: params.fromId,
createTimeStamp : (new Date()).getTime(),
sendStatus : 'loading'
});
const { error, result } = await ToAsyncAwait(this[send]({
traceId: CreateUUID(),
traceType: 20,
...params
}));
for (let item of curSession.messageList) {
if (item[this.option.ioKey] === params[this.option.ioKey]) {
item.sendStatus = error ? 'fail' : 'success';
}
// 点发送,立即把消息加入消息列表,标记为发送中状态
curSession.messageList.push(msgCtx);
// 超过时间未返回视为发送失败
this.timerStatus(msgCtx);
const { error, result } = await ToAsyncAwait(this[send](par));
// 接到通知,标记消息是否发送成功
for (let i = curSession.messageList.length; i--;) {
const item = curSession.messageList[i];
if (item[this.option.ioKey] === par[this.option.ioKey]) {
curSession.messageList[i].sendStatus = msgCtx.sendStatus = error ? 'fail' : 'success';
break;
}
}
let newData = [...this.sessionData];
newData[index] = curSession;
this.setSessionData(newData);
if (error) {
return Promise.reject(error);
}
return Promise.resolve(result);
}
/**
* 发送失败时重新发送
* @param {*} params
*/
async resend(params) {
params.sendStatus = 'loading';
this.timerStatus(params)
const { error, result } = await ToAsyncAwait(this[send]({
traceId: params.traceId,
traceType: params.traceType,
content : params.content
}));
params.createTimeStamp = result.createTimeStamp;
if (error) {
params.sendStatus = 'fail';
return Promise.reject(error);
}
params.sendStatus = 'success';
return Promise.resolve(result);
}
timerStatus(msg) {
setTimeout(() => {
if (msg.sendStatus === 'loading') {
msg.sendStatus = 'fail';
delete this.queue[msg.traceId];
}
}, 3000);
}
/**
* 主动创建会话
* @param {*} params

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-04-07 17:22:44
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:28
* @LastEditTime: 2022-05-24 09:57:03
* @Description: file content
-->
@ -175,7 +175,7 @@ export default {
}
}
}
::deep {
::v-deep {
.goods-item--pirce{
text{
font-size: $font-size-lg;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-31 14:49:33
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:30
* @LastEditTime: 2022-05-24 09:57:04
* @Description: file content
-->
<template>
@ -88,7 +88,7 @@ export default {
}
}
}
::deep{
::v-deep{
.ui-money{
text{
font-size: $font-size-base;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-04-22 16:48:11
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:32
* @LastEditTime: 2022-05-24 09:57:05
* @Description: file content
-->
<template>
@ -81,7 +81,7 @@ export default {
margin-left: 60rpx;
}
}
::deep{
::v-deep{
.ui-money{
text{
font-size: $font-size-base;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 14:12:18
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:36
* @LastEditTime: 2022-05-24 09:57:08
* @Description: file content
-->
<template>
@ -126,7 +126,7 @@ page {
left: 30rpx;
width: 670rpx;
}
::deep {
::v-deep {
.form--city .ui-cell{
padding: 0 40rpx;
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 14:12:18
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:37
* @LastEditTime: 2022-05-24 09:57:10
* @Description: file content
-->
<template>
@ -160,7 +160,7 @@ page {
left: 30rpx;
width: 670rpx;
}
::deep {
::v-deep {
.del-address .ui-cell--title{
color: $color-yellow3;
}

@ -3,7 +3,7 @@
components: { UiCell },: ch
* @Date: 2019-08-22 19:41:20
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:35
* @LastEditTime: 2022-05-24 09:57:07
* @Description: file content
-->
<template>
@ -209,7 +209,7 @@ page {
border: 0;
}
}
::deep{
::v-deep{
.header--cell .ui-cell--title{
font-weight: bold;
font-size: $font-size-lg;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-11 11:45:08
* @LastEditors: ch
* @LastEditTime: 2022-05-23 11:29:13
* @LastEditTime: 2022-05-24 22:54:29
* @Description: file content
-->
<template>
@ -134,6 +134,7 @@ export default {
break;
}
this.msgCtx = '';
const {error, result} = await ToAsyncAwait(Im.sendMsg({
fromId : this.$store.state.userInfo.id,
content: {
@ -147,7 +148,6 @@ export default {
uni.$u.toast(error.message);
return false
}
this.msgCtx = '';
this.focus = false;
this.$nextTick(() => {
this.focus = true;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-13 15:57:31
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:38
* @LastEditTime: 2022-05-24 09:57:11
* @Description: file content
-->
<template>
@ -85,7 +85,7 @@ export default {
right:30rpx;
}
}
::deep{
::v-deep{
.product--con-price{
text{
color: #FF512B;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-14 14:00:14
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:39
* @LastEditTime: 2022-05-24 09:57:12
* @Description: file content
-->
<template>
@ -78,7 +78,7 @@ export default {
margin-top: 26rpx;
}
}
::deep{
::v-deep{
.order--con-price{
text{
color: #FF512B;

@ -2,13 +2,15 @@
* @Author: ch
* @Date: 2022-03-26 14:32:03
* @LastEditors: ch
* @LastEditTime: 2022-05-21 16:08:32
* @LastEditTime: 2022-05-24 22:42:35
* @Description: file content
-->
<template>
<view class="main">
<template v-for="item in msgData">
<view class="send" :key="item.id" v-if="item.fromId == $store.state.userInfo.id">
<text class="send--status" v-if="item.sendStatus === 'loading'"></text>
<text class="send--status send--status__fail" v-if="item.sendStatus === 'fail'" @click="resend(item)"></text>
<template v-if="item.type == MSG_TYPE.CUSTOM">
<GoodsInfo class="send--box" position="msg" v-if="item.payload.id" :goodsInfo="item.payload"/>
<OrderInfo class="send--box" position="msg" v-if="item.payload.orderId" :orderInfo="item.payload"/>
@ -105,24 +107,26 @@ export default {
this.goodsId = this.$Route.query.goodsId;
this.orderId = this.$Route.query.orderId;
this.sessionId = this.$Route.query.sessionId;
if(this.goodsId){
this.createSessionMain();
this.getGoodsInfo();
}else if(this.orderId){
this.createSessionMain();
this.getOrderInfo();
}else if(this.sessionId){
if(this.sessionId){
this.getHistoryMsg();
this.readMsg();
}else{
this.createSessionMain();
}
if(this.goodsId){
this.getGoodsInfo();
}
if(this.orderId){
this.getOrderInfo();
}
this.$nextTick(()=>{
uni.pageScrollTo({
scrollTop : 99999,
duration : 0
});
})
uni.pageScrollTo({
scrollTop : 99999,
duration : 0
});
},
methods:{
/**
@ -151,25 +155,36 @@ export default {
async getHistoryMsg(){
this.loading = true;
const lastMsg = this.msgData?.length ? this.msgData[0] : {};
await Im.getHistoryMsg({
const {error, result} = await ToAsyncAwait(Im.getHistoryMsg({
content : {
sessionId : this.sessionId,
topMessageId : lastMsg.id || null
}
});
}));
if(error){
uni.$u.toast(error.errMsg || error.message);
return false
}
this.loading = false;
},
/**
* 把当前会话消息置为已读
*/
readMsg(){
Im.setRead({
async readMsg(){
const {error, result} = await ToAsyncAwait(Im.setRead({
content: {
sessionId : this.sessionId
}
})
}));
if(error){
uni.$u.toast(error.errMsg || error.message);
return false
}
},
resend(item){
Im.resend(item)
},
/**
* 从订单页进来查询订单信息
*/
@ -247,8 +262,19 @@ page{
display: flex;
justify-content: flex-end;
margin-top:30rpx ;
&--status{
font-size: $font-size-sm;
color: $color-grey3;
display: flex;
align-items: center;
line-height: 46rpx;
margin-right: 10rpx;
&__fail{
color: $color-yellow4;
}
}
&--box{
max-width: 552rpx;
max-width: 480rpx;
margin-right:30rpx;
&__txt{
padding: 20rpx 30rpx;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 15:09:06
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:40
* @LastEditTime: 2022-05-24 17:24:35
* @Description: file content
-->
<template>
@ -37,10 +37,13 @@ export default {
confirmColor : '#3A83FB',
success:async ({confirm})=>{
if(confirm){
await ApiGetLogout();
const {error} = await ApiGetLogout();
if(error){
uni.$u.toast(error.message);
return false;
}
this.$store.commit('SET_TOKEN');
Im.logout();
console.log(Im, this.$store.state);
this.$Router.replace('/login');
}
}
@ -91,7 +94,7 @@ page {
font-size: $font-size-lg;
}
::deep{
::v-deep{
.userInfo .uiCell--title{
font-size: $font-size-lg;
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-28 15:38:23
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:41
* @LastEditTime: 2022-05-24 09:57:14
* @Description: file content
-->
<template>
@ -143,7 +143,7 @@ page {
border: 0;
}
}
::deep{
::v-deep{
.userInfo .uiCell--title{
font-size: $font-size-lg;
}

@ -573,7 +573,7 @@ export default {
}
::deep{
::v-deep{
.cart-item--price{
text{
font-size: $font-size-lg;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-23 10:29:07
* @LastEditors: ch
* @LastEditTime: 2022-05-06 11:20:23
* @LastEditTime: 2022-05-24 09:57:02
* @Description: file content
-->
<template>
@ -165,16 +165,19 @@ export default {
margin-top: 0;
}
}
::deep .price{
text{
color: $color-yellow4;
font-size: $font-size-lg;
line-height: $font-size-lg;
font-weight: bold;
}
.ui-money--prefix{
font-size: $font-size-sm;
line-height: $font-size-sm;
::v-deep {
.price{
text{
color: $color-yellow4;
font-size: $font-size-lg;
line-height: $font-size-lg;
font-weight: bold;
}
.ui-money--prefix{
font-size: $font-size-sm;
line-height: $font-size-sm;
}
}
}
</style>

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-23 10:07:48
* @LastEditors: ch
* @LastEditTime: 2022-04-21 16:45:14
* @LastEditTime: 2022-05-24 09:57:16
* @Description: file content
-->
<template>
@ -204,8 +204,8 @@ export default {
}
::deep {
.seckill--item-pirce{
.seckill--item-pirce ::v-deep{
text{
color: $color-yellow4;
font-size: $font-size-lg;
@ -215,6 +215,6 @@ export default {
font-size: $font-size-base;
}
}
}
</style>

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 15:36:46
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:33
* @LastEditTime: 2022-05-24 09:57:06
* @Description: file content
-->
<template>
@ -220,7 +220,7 @@ export default {
}
}
}
::deep{
::v-deep{
.input-placeholder{
color: $color-grey3;
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-04-15 16:36:02
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:46
* @LastEditTime: 2022-05-24 09:57:18
* @Description: file content
-->
<template>
@ -81,7 +81,7 @@ export default {
}
}
::deep{
::v-deep{
.u-cell__body__content{
padding: 10rpx 0;
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-04-15 16:04:28
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:50
* @LastEditTime: 2022-05-24 09:57:19
* @Description: file content
-->
<template>
@ -103,7 +103,7 @@ export default {
color: $color-yellow4;
font-size: $font-size-lg;
}
::deep {
::v-deep {
.ui-money--price{
font-size: 36rpx;
color: $color-yellow4;

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 10:58:24
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:44
* @LastEditTime: 2022-05-24 09:57:16
* @Description: file content
-->
<template>
@ -240,7 +240,7 @@ page {
}
}
::deep{
::v-deep{
.orders--footer{
.ui-btn{
margin: 0 0 0 20rpx;

@ -191,7 +191,7 @@ export default {
padding: 0 30rpx;
}
.address{
::deep.u-cell__body__content{
::v-deep.u-cell__body__content{
padding: 10rpx 0;
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-20 14:14:53
* @LastEditors: ch
* @LastEditTime: 2022-05-23 18:17:45
* @LastEditTime: 2022-05-24 09:57:17
* @Description: file content
-->
<template>
@ -198,7 +198,7 @@ page {
</style>
<style lang="scss" scoped>
.address{
::deep.u-cell__body__content{
::v-deep.u-cell__body__content{
padding: 10rpx 0;
}

Loading…
Cancel
Save