获取用户资料
onGotUserInfo() {
uni.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
uni.setStorage({
key: 'userData',
data: res
})
},
fail: (res) => {
console.log("err", res);
}
})
},
微信图片修改成jpg
换成jpg才能在canvas中画出来
还得去微信开发平台的后台,把头像添加到白名单,不然手机头像不出来 o(╥﹏╥)o
模拟器有头像,手机预览没有 o(╥﹏╥)o
开发管理--开发设置---服务器域名---downloadFile合法域名 添加o(╥﹏╥)o
https://thirdwx.qlogo.cn
这个是头像没转换前的头像域名 o(╥﹏╥)o
getNetworkImage(url) {
return new Promise((resolve, reject) => {
uni.downloadFile({
url,
success: (e) => {
const p = e.tempFilePath;//这个就是jpg地址
this.pic0 = p;
if (p.indexOf('json') > -1) {
reject(p)
return false
}
resolve(p)
},
fail: (r) => {
reject(r)
}
})
})
},
用canvas画图,保存图片到本地相册
<canvas style="width: 375px; height: 821px;" canvas-id="firstCanvas" id="firstCanvas"
class="firse_cavas"></canvas>
drawCanvas() {
var _this = this;
_this.showCanvas = true;
_this.context = uni.createCanvasContext('firstCanvas',_this)
_this.context.drawImage(clock_bg, 0, 0, 375, 821)//背景
_this.context.drawImage(_this.pic0, 120, 120, 150, 150)//头像转换的jpg
_this.context.drawImage("../../static/qr.png", 30, 670, 100, 100)//二维码
_this.context.setFontSize(14)
_this.context.setFillStyle("#ff7c00")
_this.context.fillText('“不忘初心、牢记使命”', 120, 360)//文字
_this.context.draw(true);//绘制
_this.saveCanvas();//保存图片
},
saveCanvas(){//保存图片到本地
let _this = this;
uni.canvasToTempFilePath({ // 保存canvas为图片
canvasId: 'firstCanvas',
quality: 1,
complete: function(res) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
console.log('save success');
setTimeout(() => {
_this.showCanvas = false;
}, 2000);
},
fail() {
setTimeout(() => {
_this.showCanvas = false;
}, 1000);
}
});
},
})
}
o(╥﹏╥)o 记录一下,不说了,我都不想看见它了...