从后台获取二维码base64码
success: res => {
// console.log(res.data.data)
var imgSrc = res.data.data;//base64编码
var save = wx.getFileSystemManager();
var number = Math.random();
//保存本地图片文件路径,也是绘图路径
let filePath = wx.env.USER_DATA_PATH + '/pic' + number + '.png'
save.writeFile({
filePath: filePath,
data: imgSrc,
encoding: 'base64'
success: res2 => {
wx.saveImageToPhotosAlbum({
filePath: filePath,
success: function (res2) {
console.log(res2)
// wx.showToast({
// title: '保存成功',
// })
if (res.data.data) {
//这是封装的模板,赋值
that.setData({
shareThree: {
avatar: userInfo.avatarUrl,
nickname: userInfo.nickName,
awardMoney: that.data.positionArr.jobName,
showShareModel: true
ErWeiMa: filePath,
awardContent: that.data.positionArr.nature + ' | ' + that.data.positionArr.city
}
})
}
}
})
}
})
}
另外,如果是从后台返回直接的图片路径,就需要先下载,用下载后返回的路径绘图
//下载二维码
//console.log(that.data.ErWeiMa)
// wx.downloadFile({
// url: that.data.ErWeiMa,
// success: function (res) {
// //console.log(res)
// if (res.statusCode == 200) {
// that.setData({
//设置ctx.drawImage(that.data.ErWeiMa, *,*,*)地址
// QRPath: res.tempFilePath
// })
// that.drawImage();
// }
// },
// fail: function () {
// that.showErrorModel('网络错误');
// }
// })
"writeFile:fail exceeded the maximum size of the file storage limit 10M" 报了个这个