From 58b443d30a1cf8bd2eed05c24bd2cb2ddc800cef Mon Sep 17 00:00:00 2001 From: luqc Date: Tue, 28 May 2019 18:10:25 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=95=86=E6=88=B7=E6=B5=B7=E6=8A=A5][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]=E4=BF=A1=E6=81=AF=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/canvas/index.js | 45 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/pages/canvas/index.js b/pages/canvas/index.js index e50de84..a18b77a 100644 --- a/pages/canvas/index.js +++ b/pages/canvas/index.js @@ -140,7 +140,6 @@ Page({ ctx.fillRect(0, 0, that.data.windowWidth, that.data.windowHeight); ctx.drawImage(res.path, 0, 50, topImageWidth, topImageHeight); that.roundRect(ctx, 15 * scale, 270 * scale, 325 * scale, 125 * scale, 10); - that.drawOtherImage(ctx, scale); that.drawOtherContent(ctx, scale, options); that.drawAvatarimg(ctx, scale); that.drawqrCode(ctx, scale); @@ -213,9 +212,7 @@ Page({ this.data.qrCode + `?imageView/2/w/${coImageWidth}/h/${coImageHeight}`; src2 = util.getProxyImgUrl(src1); } else { - src1 = - this.data.data.qrCode + - `?imageView/2/w/${coImageWidth}/h/${coImageHeight}`; + src1 =this.data.data.qrCode +`?imageView/2/w/${coImageWidth}/h/${coImageHeight}`; src2 = util.getProxyImgUrl(src1); } wx.getImageInfo({ @@ -226,27 +223,7 @@ Page({ } }); }, - // 绘制活动图片 - drawOtherImage(ctx, scale) { - var that = this; - // 如果该商户有活动商品 - if (that.data.couponList.length > 0) { - let cotentImageWidth = parseInt(80 * scale); - let cotentImageHeight = parseInt(80 * scale); - for (let i = 0; i < that.data.couponList.length; i++) { - let imageItem = that.data.couponList[i].coverImg; - let src1 = imageItem + `?imageView/2/w/${cotentImageWidth}/h/${cotentImageHeight}`; - let src2 = util.getProxyImgUrl(src1); - wx.getImageInfo({ - src: src2, - success: function(res) { - ctx.drawImage(res.path, 35 * scale + i * 110 * scale, 300 * scale, cotentImageWidth, cotentImageHeight); - } - }); - } - } - that.drawqrCode(ctx, scale); - }, + //截取商品名 substrTile(str) { return str.substr(0, 5) + "..."; @@ -263,15 +240,7 @@ Page({ * 绘制多行文本,自动换行,超出添加... * */ - canvasTextAutoLine: function( - str, - ctx, - initX, - initY, - lineHeight, - maxWidth, - row = 1 - ) { + canvasTextAutoLine: function(str,ctx,initX,initY,font,style,align,baseLine,lineHeight,maxWidth,row = 1) { var lineWidth = 0; var lastSubStrIndex = 0; var currentRow = 1; @@ -283,6 +252,10 @@ Page({ if (currentRow > row && str.length > i) { newStr = str.substring(lastSubStrIndex, i - 2) + "..."; } + ctx.setFontSize(font); + ctx.setFillStyle(style); + ctx.setTextAlign(align); + ctx.setTextBaseline(baseLine); ctx.fillText(newStr, initX, initY); initY += lineHeight; lineWidth = 0; @@ -293,6 +266,10 @@ Page({ } } if (i == str.length - 1) { + ctx.setFontSize(font); + ctx.setFillStyle(style); + ctx.setTextAlign(align); + ctx.setTextBaseline(baseLine); ctx.fillText(str.substring(lastSubStrIndex, i + 1), initX, initY); } }