perf: 优化消息发送失败

This commit is contained in:
kuaifan 2022-07-21 10:44:35 +08:00
parent 17e8dbb4d9
commit 86c19ce355
4 changed files with 63 additions and 25 deletions

View File

@ -38,6 +38,7 @@
@on-view-file="onViewFile" @on-view-file="onViewFile"
@on-down-file="onDownFile" @on-down-file="onDownFile"
@on-reply-list="onReplyList" @on-reply-list="onReplyList"
@on-error="onError"
@on-emoji="onEmoji" @on-emoji="onEmoji"
@on-show-emoji-user="onShowEmojiUser"/> @on-show-emoji-user="onShowEmojiUser"/>
</template> </template>
@ -192,6 +193,10 @@ export default {
this.dispatch("on-reply-list", data) this.dispatch("on-reply-list", data)
}, },
onError(data) {
this.dispatch("on-error", data)
},
onEmoji(data) { onEmoji(data) {
this.dispatch("on-emoji", data) this.dispatch("on-emoji", data)
}, },

View File

@ -128,8 +128,11 @@
<div v-if="msgData.modify" class="modify"> <div v-if="msgData.modify" class="modify">
<i class="taskfont">&#xe779;</i> <i class="taskfont">&#xe779;</i>
</div> </div>
<!--等待/时间/阅读--> <!--错误/等待/时间/阅读-->
<Loading v-if="isLoading"/> <div v-if="msgData.error === true" class="error" @click="onError">
<Icon type="ios-alert" />
</div>
<Loading v-else-if="isLoading"/>
<template v-else> <template v-else>
<!--时间--> <!--时间-->
<div v-if="timeShow" class="time" @click="timeShow=false">{{msgData.created_at}}</div> <div v-if="timeShow" class="time" @click="timeShow=false">{{msgData.created_at}}</div>
@ -462,6 +465,10 @@ export default {
}) })
}, },
onError() {
this.$emit("on-error", this.msgData)
},
onEmoji(symbol) { onEmoji(symbol) {
this.$emit("on-emoji", { this.$emit("on-emoji", {
msg_id: this.msgData.id, msg_id: this.msgData.id,

View File

@ -102,6 +102,7 @@
@on-view-file="onViewFile" @on-view-file="onViewFile"
@on-down-file="onDownFile" @on-down-file="onDownFile"
@on-reply-list="onReplyList" @on-reply-list="onReplyList"
@on-error="onError"
@on-emoji="onEmoji" @on-emoji="onEmoji"
@on-show-emoji-user="onShowEmojiUser"> @on-show-emoji-user="onShowEmojiUser">
<template slot="header"> <template slot="header">
@ -943,20 +944,12 @@ export default {
text: msgText, text: msgText,
}, },
method: 'post', method: 'post',
complete: _ => this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId)
}).then(({data}) => { }).then(({data}) => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId)
this.sendSuccess(data) this.sendSuccess(data)
}).catch(({msg}) => { }).catch(error => {
$A.modalConfirm({ this.$set(tempMsg, 'error', true)
icon: 'error', this.$set(tempMsg, 'errorData', {type: 'text', content: error.msg, msg: msgText})
title: '发送失败',
content: msg,
cancelText: '取消',
okText: '再次编辑',
onOk: () => {
this.msgText = msgText
}
})
}); });
} }
if (emptied) { if (emptied) {
@ -992,20 +985,12 @@ export default {
reply_id: this.replyId, reply_id: this.replyId,
}), }),
method: 'post', method: 'post',
complete: _ => this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId)
}).then(({data}) => { }).then(({data}) => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId)
this.sendSuccess(data); this.sendSuccess(data);
}).catch(error => { }).catch(error => {
$A.modalConfirm({ this.$set(tempMsg, 'error', true)
icon: 'error', this.$set(tempMsg, 'errorData', {type: 'record', content: error.msg, msg})
title: '发送失败',
content: error.msg,
cancelText: '取消',
okText: '重新发送',
onOk: () => {
this.sendRecord(msg)
}
})
}); });
}, },
@ -1929,6 +1914,39 @@ export default {
this.replyListShow = true this.replyListShow = true
}, },
onError(data) {
if (data.error !== true) {
return
}
const {type, content, msg} = data.errorData
const config = {
icon: 'error',
title: '发送失败',
content,
cancelText: '取消发送',
onCancel: _ => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != data.id)
}
}
if (type === 'text') {
config.okText = '再次编辑'
config.onOk = () => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != data.id)
this.msgText = msg
this.inputFocus()
}
} else if (type === 'record') {
config.okText = '重新发送'
config.onOk = () => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != data.id)
this.sendRecord(msg)
}
} else {
return
}
$A.modalConfirm(config)
},
onEmoji(data) { onEmoji(data) {
if (!$A.isJson(data)) { if (!$A.isJson(data)) {
data = { data = {

View File

@ -821,6 +821,14 @@
height: 21px; height: 21px;
line-height: 1; line-height: 1;
.error {
cursor: pointer;
color: #ED4014;
> i {
font-size: 14px;
}
}
.common-loading { .common-loading {
margin: 0 2px; margin: 0 2px;
width: 10px; width: 10px;