提交 eb39105b 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新 修复弱网的情况下,消息含图片等资源上传失败后,点击重发后接收方收到的消息资源错误的问题

上级 1a4fb12c
...@@ -562,8 +562,11 @@ ...@@ -562,8 +562,11 @@
longpressMsgAvatar(e) { longpressMsgAvatar(e) {
this.$emit('longpressMsgAvatar', e) this.$emit('longpressMsgAvatar', e)
}, },
retriesSendMsg(e) { retriesSendMsg(msg) {
this.$emit('retriesSendMsg', e) if(msg.state === 0){
return console.error('消息发送中')
}
this.$emit('retriesSendMsg', msg)
}, },
clickItem() { clickItem() {
this.$emit('clickItem') this.$emit('clickItem')
......
...@@ -476,18 +476,23 @@ ...@@ -476,18 +476,23 @@
data[fileType] = fileInfo data[fileType] = fileInfo
let msg = await this.beforeSendMsg(data,false) let msg = await this.beforeSendMsg(data,false)
// console.log('~~~beforeSendMsg',msg); // console.log('~~~beforeSendMsg',msg);
try{ const uploadFileFn = async ()=>{
const result = await uniCloud.uploadFile({ const result = await uniCloud.uploadFile({
filePath: tempFile.path, filePath: tempFile.path,
cloudPath: Date.now() + this.current_uid + '.' + name.split('.').pop(), cloudPath: Date.now() + this.current_uid + '.' + name.split('.').pop(),
}); });
// console.log('result.fileID',result.fileID); // console.log('result.fileID',result.fileID);
msg.body.url = result.fileID msg.body.url = result.fileID
}
try{
await uploadFileFn()
this.sendMsg(msg) this.sendMsg(msg)
}catch(e){ }catch(e){
console.error('uploadFile error:',e) console.error('uploadFile error:',e)
// 重发之前增加先上传图片的逻辑
msg.__beforeRetriesAction = uploadFileFn
msg.state = -200
} }
}); });
}, },
async chooseFileSendMsg(type,_config={}) { async chooseFileSendMsg(type,_config={}) {
...@@ -632,6 +637,7 @@ ...@@ -632,6 +637,7 @@
"rich-text":HtmlArr "rich-text":HtmlArr
},false) },false)
const uploadFileFn = async ()=>{
// 上传消息中的图片 // 上传消息中的图片
let promiseArr = [] let promiseArr = []
msg.body.forEach(async item=>{ msg.body.forEach(async item=>{
...@@ -665,8 +671,17 @@ ...@@ -665,8 +671,17 @@
} }
}) })
await Promise.all(promiseArr) await Promise.all(promiseArr)
}
try{
await uploadFileFn()
// 执行发送 // 执行发送
this.sendMsg(msg) this.sendMsg(msg)
}catch(e){
// 重发之前增加先上传图片的逻辑
msg.__beforeRetriesAction = uploadFileFn
msg.state = -200
}
}else{ }else{
// 把this.chatInputContent中的 变成空格,再把头尾的空格去掉 // 把this.chatInputContent中的 变成空格,再把头尾的空格去掉
this.chatInputContent = this.chatInputContent.replace(/ /g, ' ').trim() this.chatInputContent = this.chatInputContent.replace(/ /g, ' ').trim()
...@@ -787,10 +802,16 @@ ...@@ -787,10 +802,16 @@
} }
}); });
}, },
retriesSendMsg(msg) { async retriesSendMsg(msg) {
uni.showLoading({ uni.showLoading({
mask: true mask: true
}); });
msg.state = 0
// 检查文件是否上传成功
if(msg.__beforeRetriesAction){
await msg.__beforeRetriesAction()
}
delete msg.__beforeRetriesAction
// console.log('retriesSendMsg', msg); // console.log('retriesSendMsg', msg);
msg.isRetries = true msg.isRetries = true
this.sendMsg(msg, e => { this.sendMsg(msg, e => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册