uni-app下载图片
uni-app下载图片
·
url地址必须为合法域名,且是https开头。否则测试环境和调试模式可以下载图片,体验版和正式版不可以
let url = $this.ewmSrc.replace('http:','https:')
console.log(url)
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
uni.showToast({
title: '保存成功',
duration: 1000
})
$this.$refs.dialogImg.close();
},
fail() {
wx.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: false,
success() {
wx.openSetting({
success(settingdata) {
if (settingdata.authSetting['scope.writePhotosAlbum']) {//是否授权保存到相册
wx.showModal({
title: '提示',
content: '获取权限成功,再次保存图片即可成功',
showCancel: false,
})
} else {
wx.showModal({
title: '提示',
content: '获取权限失败,无法保存到相册',
showCancel: false,
})
}
},
complete(complet) {
console.log("complet", complet)
}
})
}
})
}
})
}
},
fail:() =>{
uni.showToast({
title: '下载失败',
duration: 1000
})
}
});
更多推荐
已为社区贡献1条内容
所有评论(0)