saveImageToLocal(tempFilePath) { const that = this const folderPath = `${plus.io.convertLocalFileSystemURL('_documents')}/uniapp_save/images/`; console.log('临时文件' + tempFilePath) const fileName = this.fromData.number + '_' + Date.now() + ".jpg"; console.log('fromData数据'+this.fromData) console.log('图片名称' + fileName) console.log('当前任务唯一id' + this.fromData.number) const taskData = JSON.stringify(this.fromData); uni.setStorageSync(this.fromData.number, taskData); //numerb 是任务次数 //将图片保存到指定目录 uni.saveFile({ tempFilePath: tempFilePath, filePath: folderPath + fileName, success(res) { console.log("保存成功:", res); // 将保存的图片路径添加到 imgList 数组中 that.imgList.push(res.savedFilePath); // 将OID和对应的文件名存储起来 const fileObj = {}; const postData = { uid: that.uid, rid: that.jifangId, mid: that.id, mtid:that.mtid, maid: that.MaiorId, coordinate: that.coordinate, said: that.obj.aid, //天馈id sbid: that.obj.bid, //归属id spid: that.obj.pid, //电源类型 srid: that.obj.rid //机房类型 } fileObj[that.fromData.number] = fileName; const imageData = { oid: that.fromData.number, //这里将最原始的oid替换成本地任务缓存 id filePath: res.savedFilePath, postData: postData, tempFilePath: tempFilePath, taskData: that.fromData }; that.saveData.push(imageData); console.log('imgList是' + JSON.stringify(that.imgList)) console.log(uni.getStorageInfoSync(that.fromData.number)) } }) },这样保存文件图片之后如果我想一次性删掉怎么弄
时间: 2024-03-21 12:37:37 浏览: 110
iOS开发中关键字const/static/extern、UIKIT_EXTERN的区别和用法
你可以使用uni.getSavedFileList()方法获取已经保存的文件列表,然后使用uni.removeSavedFile()方法将它们一次性删除。代码示例如下:
```
uni.getSavedFileList({
success: function(res) {
for (let i = 0; i < res.fileList.length; i++) {
uni.removeSavedFile({
filePath: res.fileList[i].filePath,
success(res) {
console.log('删除成功', res)
},
fail(err) {
console.log('删除失败', err)
}
})
}
}
})
```
阅读全文