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

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

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