saveimg: function() {
var that = this;
wx.showLoading({
title: '保存中',
})
wx.downloadFile({
url: that.data.haibaoimg,
success: function(res) {
var imgpath = res.tempFilePath;
if (res.statusCode == 200) {
wx.getSetting({
success(res) {
//第一次进来res.authSetting['scope.writePhotosAlbum']为undefined
if (res.authSetting['scope.writePhotosAlbum'] != undefined && res.authSetting['scope.writePhotosAlbum'] == false) {
//显示自定义弹框,第一次进来不显示自定义
that.setData({
userauth: true
});
wx.hideLoading();
} else {
wx.saveImageToPhotosAlbum({
filePath: imgpath,
success: function(res) {
wx.hideLoading();
wx.showToast({
title: '保存成功!'
})
},
fail: function(res) {
wx.hideLoading();
wx.showToast({
title: '保存失败!'
})
}
})
}
}
})
}
}
})
},
自定义弹框:
<view class="userauth" wx:if="{{userauth}}">
<view class="auth_content">
<view class="authtitle">
提示
</view>
<view class="authtext">
允许保存图片或视频到你的相册?
</view>
<view class="authfooter">
<view bindtap="closeauth">取消</view>
<view>
/*利用button调用设置*/
<button plain="{{true}}" hover-class="none" open-type='openSetting' bindopensetting="getseetting">
确定
</button>
</view>
</view>
</view>
</view>
监听打开设置用户是否打开了授权
getseetting: function(res) {
if (res.detail.authSetting['scope.writePhotosAlbum'] == true) {
this.saveimg();
} else {
wx.showToast({
title: '保存到相册授权未打开!',
icon: 'none'
})
}
this.setData({
userauth: false
});
},