保存按钮调用的方法,savePosterPath(url) ,url是服务端生成二维码的url地址。
savePosterPath(url) {
let that = this
//获取用户的当前设置。获取相册权限
uni.getSetting({
success: (res) => {
//如果没有相册权限
if (!res.authSetting["scope.writePhotosAlbum"]) {
//向用户发起授权请求
uni.authorize({
scope: "scope.writePhotosAlbum",
success: () => {
//授权成功保存图片到系统相册
that.downloadFile(url)
},
//授权失败
fail: () => {
uni.hideLoading();
uni.showModal({
title: "您已拒绝获取相册权限",
content: "是否进入权限管理,调整授权?",
success: (res) => {
if (res.confirm) {
//调起客户端小程序设置界面,返回用户设置的操作结果。(重新让用户授权)
uni.openSetting({
success: (res) => {
// uni.authorize({
// scope: 'scope.writePhotosAlbum',
// success: () => {
// //授权成功保存图片到系统相册
// that.downloadFile(url)
// }
// })
// }
},
});
} else if (res.cancel) {
return uni.showToast({
title: "已取消!",
});
}
},
});
},
});
} else {
//如果已有相册权限,直接保存图片到系统相册
that.downloadFile(url)
}
},
fail: (res) => {},
});
}
downloadFile(url) {
uni.showLoading({
title: '正在保存图片...'
});
let that = this
uni.downloadFile({ //下载文件资源到本地,返回文件的本地临时路径
url: url, //网络图片路径
success: (res) => {
let imageUrl = res.tempFilePath; //临时文件路径
console.log('imageUrl', imageUrl)
uni.saveImageToPhotosAlbum({ //保存图片到系统相册
filePath: imageUrl, //图片路径,不支持网络图片路径
success: (res) => {
uni.hideLoading();
return uni.showToast({
title: "保存成功!",
});
that.close()
},
fail: (err) => {
return uni.showToast({
title: res.errMsg,
});
uni.hideLoading();
}
})
}
})
}
界面点保存之后 一直 显示 “正在保存图片...”
下载域名未配置。体验版关闭调试应该是一样的效果。
隐私协议吧