4144关注12286浏览
代码如下:
onLoad(options) {
const height = app.globalData.window_height;
const width = app.globalData.window_width;
const options = {
head_photo = 'https://wx.qlogo.cn/mmopen/vi_32/N78NX78hLfDwG56Ocyyjhibqro6sFjIZmUzJM5aI90ySicyqMeRToKLImXl7v8DRVwMmVggfMzy1m15d2P5beejg/0',
qrcode='http://oixavq5ec.bkt.clouddn.com/yaliapi/1302/wechat/b07f9201804161810206895.png'
}
if (options) {
const optionsArr = Object.keys(options).filter(x => x != 'nickname');
optionsArr.map((x, k) => {
if (x == 'head_photo' || x == 'qrcode') {
this.downloadCanvasImg(x, options[x], (optionsArr.length - 1 == k ? true : false))
}
})
}
},
downloadCanvasImg(name, url, end) {
const options = immutable.fromJS(this.data.options).toJS();
wx.downloadFile({
url,
success: res => {
const urls = res.tempFilePath;
options[name] = urls;
this.setData({ options })
console.log(name, url, end, urls);
if (end) {
this.drawCanvas(this.data.options);
}
},
fail: fres => {
this.downloadCanvasImg(options, end)
}
})
},
drawCanvas(options) {
const { width, height, backgroundColor } = this.data;
const imgUrl = options.head_photo;
const qrcodeUrl = options.qrcode
const ctx = wx.createCanvasContext('myCanvas');
const grd = ctx.createLinearGradient(0, 0, 0, 160)
// grd.addColorStop(0, this.colorRgb(backgroundColor))
// grd.addColorStop(.2, this.colorRgb(backgroundColor))
// grd.addColorStop(1, this.colorRgb(backgroundColor, true))
grd.addColorStop(0, '#16ca4e')
grd.addColorStop(.2, '#16ca4e')
grd.addColorStop(1, '#16ca4e')
ctx.beginPath()
ctx.arc(width / 2, -180, width / 2 + 200, 2 * Math.PI) // height: width / 2 + 20
ctx.fillStyle = grd
ctx.fill()
ctx.closePath()
ctx.beginPath()
ctx.setFillStyle('#ffffff')
ctx.setTextAlign('center')
ctx.setFontSize(55)
ctx.fillText('佣金升级', width / 2, 80)
ctx.fillText('福利双赢', width / 2, 130)
ctx.setTextAlign('center')
ctx.closePath()
ctx.save()
ctx.beginPath();
ctx.setFillStyle('white');
ctx.setShadow(0, 2, 5, 'rgba(0, 0, 0, .2
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>