Commit ca0e8c74 authored by Damon's avatar Damon

缓存图片队列清理

parent b4fb3328
......@@ -86,17 +86,33 @@ export default {
},
onShow: async function () {
// 应用启动,或从后台进入前台显示
this.handleImageTask()
},
onHide: function () {
// 应用从前台进入后台
},
watch: {
uploadTask: function(newValue, oldValue) {
console.log("oldValue, newValue", oldValue, newValue)
if(newValue.length > 0) upload.uploadImageTask(this)
}
},
methods: {
// 处理上传图片队列数据
handleImageTask() {
if (this.uploadTask.length > 0) {
upload.uploadImageTask(this)
} else { // 定时清理缓存在本地的文件
const result = uni.getStorageSync('delImg')
if (result.length > 0) {
for (let i of result) {
uni.removeSavedFile({
filePath: i
})
}
uni.setStorageSync('delImg', [])
}
}
},
getSystemInfo() {
try {
let a = wx.getSystemInfoSync();
......
......@@ -28,7 +28,7 @@
import arrMixin from './arrMixin'
import baseFile from '@/components/upload/index';
import takePhoto from '@/components/take/index.vue'
import uploader from '@/plugins/uploader/index.js'
// import uploader from '@/plugins/uploader/index.js'
export default {
name: 'XhFiles',
......
......@@ -7,7 +7,6 @@ export default {
*/
async uploadImageTask(that) {
const uploadTask = that.uploadTask
console.log("uploadTask", uploadTask)
const options = {
files: uploadTask, // 必填 临时文件路径 格式: [{path: "图片地址"}]
......@@ -15,13 +14,27 @@ export default {
maxSize: 300000, //(默认 无 说明:上传的文件最大字节数限制,默认不限制)
onEachUpdate: res => {
console.log("上传成功返回:",res);
const newTask = uploadTask.filter(v => v.key !== res.key)
// that.$u.vuex('uploadTask', newTask)
},
Update: res => {
console.log("上传进度返回:",res);
}
}
uploader.qnFileUpload(options)
},
const result = await uploader.qnFileUpload(options)
if (result) { // 匹配已上传完成的图片,更新缓存数据
let newTask = []
let delImg = []
uploadTask.forEach(v => {
if (result.includes(`/${v.key}`)) { // 删除已上传的图片
delImg.push(v.path)
} else { // 未上传的重新存储
newTask.push(v)
}
})
uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
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