From 1d69edcd6417621c0635a1973ccfb6a64b5d8251 Mon Sep 17 00:00:00 2001 From: taiwan Date: Sat, 9 Apr 2022 23:51:23 +0800 Subject: [PATCH] 秒杀和拼单分享海报修改 --- pages/goods/goodsInfo/goodsInfo.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index c640bb3..bdb0241 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -4762,6 +4762,7 @@ Page({ if(type == 1) { // 秒杀 src = '../../../images/share/miao_share.png'; context.drawImage(src, 54 * unit, 648 * unit, 200 * unit, 36 * unit); + context.setTextAlign('left'); }; if(type == 2) { // 商家和会员团 src = '../../../images/share/ct_num.png'; @@ -4808,13 +4809,28 @@ Page({ price = parseFloat(price).toFixed(2); context.setFontSize(32 * unit); context.setFillStyle('#DE1117'); - context.fillText('¥' + price, 54 * unit, 730 * unit); + context.fillText('¥' + price, 54 * unit, 735 * unit); + + }; + //---市场价划掉--- + context.setFillStyle("gray") + context.setFontSize(22 * unit) + var pri0 = "¥" + this.data.data.market_price.toFixed(2); + var wd2 = this.data.screenWidth - ut.measureText(pri0, 22 * unit) - 25; + context.fillText(pri0, 54 * unit, 770 * unit); + + context.setStrokeStyle('gray'); + context.setLineWidth(1 * unit); + context.moveTo(54 * unit, 763 * unit); + context.lineTo(ut.measureText(pri0, 22 * unit) + 50, 763 * unit); + context.stroke(); + // 8.商品标题 context.setFontSize(20 * unit); context.setFillStyle('#898989'); - this.draw_Text(context, this.data.data.goods_name, 54 * unit, 770 * unit, 240 * unit, 240 * unit, unit); + this.draw_Text(context, this.data.data.goods_name, 54 * unit, 800 * unit, 240 * unit, 280 * unit, unit, 1); // 9.小程序码 context.drawImage(vpath, 375 * unit, 660 * unit, 120 * unit, 120 * unit); @@ -5385,18 +5401,21 @@ Page({ //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 - draw_Text: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) { + draw_Text: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit, lineNum) { var lineWidth = 0; var lastSubStrIndex = 0; //每次开始截取的字符串的索引 var han = 0; for (let i = 0; i < str.length; i++) { + if(lineNum) { + if(han == lineNum) return; + }; if (han == 2) return; //lineWidth += ctx.measureText(str[i]).width; lineWidth += ut.measureText(str[i], 21.3 * unit); if (lineWidth > canvasWidth) { han++; - if (han == 2) + if (han == 2 || han == lineNum) ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 else ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); @@ -5409,7 +5428,7 @@ Page({ if (i == str.length - 1) { //绘制剩余部分 ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); } - } + }; }, // ----视频图片---- -- libgit2 0.21.4