提交 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,41 +637,51 @@ ...@@ -632,41 +637,51 @@
"rich-text":HtmlArr "rich-text":HtmlArr
},false) },false)
// 上传消息中的图片 const uploadFileFn = async ()=>{
let promiseArr = [] // 上传消息中的图片
msg.body.forEach(async item=>{ let promiseArr = []
if(item.name === 'img'){ msg.body.forEach(async item=>{
promiseArr.push(new Promise((resolve,reject)=>{ if(item.name === 'img'){
uni.getImageInfo({
src:item.attrs.src,
success:res=>{
item.attrs.width = res.width
item.attrs.height = res.height
resolve()
},
fail:reject
});
}))
if(item.attrs.src.indexOf('blob:http') === 0){
promiseArr.push(new Promise((resolve,reject)=>{ promiseArr.push(new Promise((resolve,reject)=>{
uniCloud.uploadFile({ uni.getImageInfo({
filePath: item.attrs.src, src:item.attrs.src,
cloudPath: Date.now() + this.current_uid + '.' + name.split('.').pop(), success:res=>{
}).then(res=>{ item.attrs.width = res.width
item.attrs.src = res.fileID item.attrs.height = res.height
// console.log('上传成功',res); resolve()
resolve() },
}).catch(e=>{ fail:reject
reject() });
})
})) }))
if(item.attrs.src.indexOf('blob:http') === 0){
promiseArr.push(new Promise((resolve,reject)=>{
uniCloud.uploadFile({
filePath: item.attrs.src,
cloudPath: Date.now() + this.current_uid + '.' + name.split('.').pop(),
}).then(res=>{
item.attrs.src = res.fileID
// console.log('上传成功',res);
resolve()
}).catch(e=>{
reject()
})
}))
}
} }
} })
}) await Promise.all(promiseArr)
await Promise.all(promiseArr) }
// 执行发送 try{
this.sendMsg(msg) await uploadFileFn()
// 执行发送
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.
先完成此消息的编辑!
想要评论请 注册