一 生成海报
菜鸟第一次接触这个业务,部分代码参考了 blog.csdn.net/zhihui1017/… 这篇博客,生成方法讲的比较清楚,就不再赘述了,记录一些自己遇到的坑
提供一个生成带圆角矩形的方法
roundRect(ctx,x, y, width, height, radius) {
if (width < 2 * radius) radius = width / 2;
if (height < 2 * radius) radius = height / 2;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height,radius);
ctx.arcTo(x + width, y + height, x, y + height,radius);
ctx.arcTo(x, y + height, x, y,radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
return ctx;
},
tips:尝试用这个方法画一条分割线,微信开发者工具正常显示,真机不显示,后来更改为fillRect方法
生成头像的方法
ctx.save()
ctx.beginPath()
ctx.arc(55,288,50*widthRate,0,2*Math.PI,false)
ctx.stroke()
ctx.clip()
ctx.drawImage(res[1].path,55-50*widthRate,288-50*widthRate, 100*widthRate, 100*widthRate)
ctx.restore()
绘制需要时间,添加loading
你一定想说,添加loading还用提出来,wx.showLoading() wx.hideLoading 谁不会,但问题是,直接使用ctx.draw的回调,在ios系统上不生效,需要如下加一个定时器。。。
ctx.draw(false,setTimeout(() => {
wx.hideLoading({
success(){
that.setData({posterVisible:true})
}
})
}, 300))
二 触底分页功能
方法一
// HTML
<scroll-view class="scroll_view" scroll-y bindscrolltolower="nextPage">
nextPage(){
if(this.data.listAll.length<this.data.total) {
this.setData({page:this.data.page+1},()=>{
this.getListAll
})
}
},
方法二
onReachBottom(){
const {dataList,total}=this.data
if(dataList.length<total) {
this.setData({page:this.data.page+1},()=>{
this.getDataPage()
})
}
},
tips:因为这个地方是收藏页面,支持删除,删除和分页在某种情况下会出现一定的冲突,所以就采用了数据总量小于10条(且删除后数据总量大于10),再进行删除操作就重新获取接口的操作。这样既可以避免删除完当前页无法请求数的bug,又可以减轻服务器压力。