备份
This commit is contained in:
@@ -107,8 +107,51 @@ Page( {
|
||||
that.setData({
|
||||
savetitle:"保存中,请稍候..."
|
||||
})
|
||||
|
||||
// 检查权限
|
||||
wx.getSetting({
|
||||
success: function(res) {
|
||||
if (!res.authSetting['scope.writePhotosAlbum']) {
|
||||
// 未授权,请求授权
|
||||
wx.authorize({
|
||||
scope: 'scope.writePhotosAlbum',
|
||||
success: function() {
|
||||
// 授权成功,执行保存
|
||||
that.saveImage();
|
||||
},
|
||||
fail: function() {
|
||||
// 授权失败,引导用户去设置
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '需要授权保存到相册权限',
|
||||
confirmText: '去授权',
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
wx.openSetting({
|
||||
success: function(settingRes) {
|
||||
if (settingRes.authSetting['scope.writePhotosAlbum']) {
|
||||
that.saveImage();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 已授权,直接保存
|
||||
that.saveImage();
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 提取保存图片的逻辑到单独函数
|
||||
saveImage: function() {
|
||||
var userId = wx.getStorageSync("userId")
|
||||
var LoginId = wx.getStorageSync("LoginId")
|
||||
|
||||
wx.canvasToTempFilePath({
|
||||
canvasId: "myCanvas",
|
||||
destWidth: 520,
|
||||
@@ -140,30 +183,11 @@ Page( {
|
||||
},
|
||||
fail: function(err) {
|
||||
console.log('saveImageToPhotosAlbum fail:', err);
|
||||
if (err.errMsg.indexOf('auth deny') > -1 || err.errMsg.indexOf('authorize') > -1) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '需要授权保存到相册权限',
|
||||
confirmText: '去授权',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
wx.openSetting({
|
||||
success: function(settingRes) {
|
||||
if (settingRes.authSetting['scope.writePhotosAlbum']) {
|
||||
that.onxz(e);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '保存失败:' + err.errMsg,
|
||||
icon: "none",
|
||||
duration: 3000
|
||||
})
|
||||
}
|
||||
wx.showToast({
|
||||
title: '保存失败:' + err.errMsg,
|
||||
icon: "none",
|
||||
duration: 3000
|
||||
})
|
||||
that.setData({
|
||||
savetitle:"保存商家收款码到相册"
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user