This commit is contained in:
duan
2024-11-05 10:33:37 +08:00

View File

@@ -39,9 +39,7 @@ onShow(() => {
})
const saveImage = () => {
// #ifdef APP-PLUS
uni.downloadFile({
url: vdata.QrcodeUrl,
success: (res) => {
@@ -65,64 +63,10 @@ const saveImage = () => {
infoBox.showErrorToast('保存失败')
}
})
// #endif
//#ifdef MP-WEIXIN
downloadQR()
//#endif
}
//#ifdef MP-WEIXIN
function downloadQR() {
wx.getSetting({
//获取权限
success(res) {
console.log(res)
if (res.authSetting['scope.writePhotosAlbum']) {
saveWxQrcodeImg(vdata.QrcodeUrl)
} else {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
saveWxQrcodeImg(vdata.QrcodeUrl)
},
})
}
},
})
}
//#endif
const saveWxQrcodeImg = (data) => {
const fileManager = wx.getFileSystemManager()
console.log( )
const filePath = wx.env.USER_DATA_PATH + '/qrCode'+new Date().getTime()+'.png'
//这块是定义图片的名称,可自定义其他
fileManager.writeFile({
filePath: filePath,
data: data.slice(22),
encoding: 'base64',
success: (res) => {
wx.saveImageToPhotosAlbum({
filePath: filePath,
success: function (res) {
//保存成功
infoBox.showSuccessToast('保存成功')
},
fail: function (err) {
console.log(err)
//保存失败
infoBox.showErrorToast('保存失败')
},
})
},
fail: (err) => {
infoBox.showErrorToast('保存失败')
},
})
}
</script>
<style lang="scss" scoped>
.page-wrapper {