//也是参考了一大堆网上的资料,做出来的,亲测好用!!!!!
//下载图片
goDownImg=(e)=>{//下载图片
e.stopPropagation();
this.closeOpenSet();
let {currImg,prevList}=this.state;
//let imgPath1=prevList[currImg].img_url;
let imgPath1 ='https://aaa.tech.cn/1.jpg';
let that =this;
Taro.getSetting({
success (res) {
if (!res.authSetting['scope.writePhotosAlbum']) {//没有授权
Taro.authorize({
scope:'scope.writePhotosAlbum',
success () {
that.downloadImgToAlbum(imgPath1);
},
fail(){
that.setState({//显示授权层
openSetting:true
})
}
})
}else {//已授权
that.downloadImgToAlbum(imgPath1);
}
}
})
}
downloadImgToAlbum (imgPath1) {
Taro.showToast({
title:'正在保存,请稍等',
icon:'none',
duration:2000
})
//下载图片
this.downloadHttpImg(imgPath1)
.then((res)=>{
this.sharePosteCanvas(res)
})
//生成海报
//this.drawBall(imgPath1);
}
downloadHttpImg =(httpImg) =>{
return new Promise(((resolve, reject) => {
Taro.downloadFile({
url: httpImg,
success: (res) => {
if (res.statusCode ===200) {
resolve(res.tempFilePath)
}else {
Taro.showToast({
title:'图片下载失败!',
icon:'none',
duration:1000
})
}
},
fail: (res) => {
Taro.showToast({
title:'提示图片下载失败!',
icon:'none',
duration:1000
})
}
})
}))
}
sharePosteCanvas =(imgUrl)=> {
Taro.saveImageToPhotosAlbum({
filePath: imgUrl,
success (res) {
Taro.showToast({
title:'图片已保存到相册',
icon:'none',
duration:1000
})
},
fail (err) {
Taro.showToast({
title:'图片保存失败',
icon:'none',
duration:1000
})
}
})
}