|
|
@ -136,6 +136,93 @@ Page({ |
|
|
icon: 'none', |
|
|
icon: 'none', |
|
|
duration: 2000 |
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 长按二维码保存到相册
|
|
|
|
|
|
onQRCodeLongPress: function () { |
|
|
|
|
|
const { qrCodeUrl } = this.data; |
|
|
|
|
|
|
|
|
|
|
|
if (!qrCodeUrl) { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请先生成二维码', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 显示加载提示
|
|
|
|
|
|
wx.showLoading({ |
|
|
|
|
|
title: '保存中...', |
|
|
|
|
|
mask: true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 下载图片到本地临时文件
|
|
|
|
|
|
wx.downloadFile({ |
|
|
|
|
|
url: qrCodeUrl, |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
if (res.statusCode === 200) { |
|
|
|
|
|
// 保存图片到相册
|
|
|
|
|
|
wx.saveImageToPhotosAlbum({ |
|
|
|
|
|
filePath: res.tempFilePath, |
|
|
|
|
|
success: () => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '保存成功', |
|
|
|
|
|
icon: 'success', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (err) => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.error('保存图片到相册失败:', err); |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否是权限问题
|
|
|
|
|
|
if (err.errMsg.includes('auth deny')) { |
|
|
|
|
|
wx.showModal({ |
|
|
|
|
|
title: '保存失败', |
|
|
|
|
|
content: '需要相册权限才能保存二维码,请在设置中开启', |
|
|
|
|
|
confirmText: '去设置', |
|
|
|
|
|
cancelText: '取消', |
|
|
|
|
|
success: (modalRes) => { |
|
|
|
|
|
if (modalRes.confirm) { |
|
|
|
|
|
wx.openSetting({ |
|
|
|
|
|
success: (settingRes) => { |
|
|
|
|
|
console.log('设置结果:', settingRes); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '保存失败,请重试', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.error('下载图片失败,状态码:', res.statusCode); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '下载图片失败,请重试', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (err) => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.error('下载图片失败:', err); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '保存失败,请重试', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
}); |