// 选择相册图片
tapPic() {
this.gData.openMedia = true;
uni.chooseImage({
count: 1, // 图片数量
sizeType:[‘compressed’], //压缩图
sourceType: [‘album’], //从相册选择
success: (res) => {
console.log(res)
if (res.tempFilePaths.length > 0) {
let path = res.tempFilePaths[0];
uni.saveFile({
tempFilePath: path,
success: (res) =>{
var savedFilePath = res.savedFilePath;
//检查文件是否已存在
plus.io.resolveLocalFileSystemURL(savedFilePath,(entry)=> {
console.log(entry.fullPath)
try{
let photoPath = "file://"+entry.fullPath;
console.log(photoPath)
for(let bgitem of this.bgList) {
bgitem.checked = false;
}
this.bgList.push({
url: photoPath,
value: this.bgList[this.bgList.length - 1].value + 2,
checked: true
})
this.photoList.push({
url: photoPath,
value: this.bgList[this.bgList.length - 1].value + 2,
checked: false
})
this.$storage.editSet(this.backKey, photoPath);
uni.setStorageSync(this.key, JSON.stringify(this.photoList));
uni.$emit("editChatBack");
}catch(e){
console.log(e)
//TODO handle the exception
}
//如果文件存在
}, function (e) {
});
}
});
}
}
});
},