Commit 62f27c7a authored by Damon's avatar Damon

perf: 图片上传队列-删除本地不存在的临时文件

parent 847e1ed8
...@@ -19,22 +19,29 @@ export default { ...@@ -19,22 +19,29 @@ export default {
console.log("上传进度返回:",res); console.log("上传进度返回:",res);
} }
} }
const result = await uploader.qnFileUpload(options)
if (result && !result.statusCode) { // 匹配已上传完成的图片,更新缓存数据 uploader.qnFileUpload(options).then(res => {
let newTask = [] this.refreshTask(that, res)
let delImg = [] }).catch(err => {
uploadTask.forEach(v => { console.log("err", err)
if (result.includes(`/${v.key}`)) { // 删除已上传的图片 if (err.errMsg.indexOf('fail file not found') !== -1) { // 在任务中删除不存在的图片
delImg.push(v.path) this.refreshTask(that, ['failErr'])
} else { // 未上传的重新存储 }
newTask.push(v) })
} },
}) refreshTask(that, result) {
const uploadTask = that.uploadTask
let newTask = []
let delImg = []
uploadTask.forEach(v => {
if (result.includes(`/${v.key}`) || result.includes('failErr')) { // 删除已上传的图片
delImg.push(v.path)
} else { // 未上传的重新存储
newTask.push(v)
}
})
// uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理 // uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
that.$u.vuex('uploadTask', newTask) that.$u.vuex('uploadTask', newTask)
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment