diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index ca137e4..16ee9ee 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -2215,6 +2215,12 @@ Page({ //---产品名称--- //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 console.log("ssssssss", th.data.data.goods_name); + +f //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 + console.log("ssssssss", th.data.data.goods_name); + + context.setFillStyle("black"); + context.setFontSize(21.3 * unit) th.draw_Text(context, th.data.data.goods_name, 38 * unit, 180 * unit, 200 * unit, 279 * unit, unit); //------产品的价格------- @@ -2302,7 +2308,7 @@ Page({ context.fillText("快来和我一起拼团吧!", 40 * unit, 826 * unit); context.setFillStyle("black") context.font = 'normal bold 18px sans-serif'; - context.setFontSize(22 * unit) + context.setFontSize(21.3 * unit) context.fillText("长按识别二维码,立即参团", 40 * unit, 856 * unit); //---二维吗图--- context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); @@ -2406,12 +2412,11 @@ Page({ var han=0; for (let i = 0; i < str.length; i++) { if(han==2) return; - lineWidth += ctx.measureText(str[i]).width; + //lineWidth += ctx.measureText(str[i]).width; + lineWidth += ut.measureText(str[i], 21.3 * unit); if (lineWidth > canvasWidth) { han++; - ctx.setFontSize(21.3 * unit) - ctx.setFillStyle("black") - + if (han==2) ctx.fillText(str.substring(lastSubStrIndex, i)+'...', leftWidth, initHeight); //绘制截取部分 else @@ -2423,8 +2428,6 @@ Page({ titleHeight += 20; } if (i == str.length - 1) { //绘制剩余部分 - ctx.setFontSize(21.3 * unit) - ctx.setFillStyle("black") ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); } } diff --git a/pages/team/team_success/team_success.js b/pages/team/team_success/team_success.js index 8c5ba9a..a1ed7ac 100644 --- a/pages/team/team_success/team_success.js +++ b/pages/team/team_success/team_success.js @@ -47,7 +47,6 @@ Page({ }, onLoad: function (t) { wx.setNavigationBarTitle({ title: "拼团订单",}) - var that=this; //获取用户设备信息,屏幕宽度 wx.getSystemInfo({ @@ -201,7 +200,6 @@ Page({ } - //获取商品信息 await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, { }).then(res => { @@ -270,8 +268,7 @@ Page({ wx.setNavigationBarTitle({ title: "拼团详情", }) - - + ee.countDown2(); //获取分享图片的本地地址 @@ -365,6 +362,10 @@ Page({ th.get_head_temp(th.get_goods_temp,function () { var vpath = res.path; var context = wx.createCanvasContext('share'); + + console.log("saveImageToPhotosAlbum"); + console.log(vpath); + //先画背景 var pg_path = "../../../images/share/share_bg.png"; context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit); @@ -381,8 +382,8 @@ Page({ context.fillText('强烈推荐', 152 * unit + width + 20 * unit, 76 * unit); //---产品名称--- - context.setFontSize(22 * unit) - context.setFillStyle("black") + context.setFontSize(21.3 * unit); + context.setFillStyle("black"); th.draw_Text(context, th.data.goods.goods_name, 40 * unit, 180 * unit, 200 * unit, 380 * unit); //------产品的价格------- @@ -403,6 +404,10 @@ Page({ context.moveTo(438 * unit, 204 * unit) context.lineTo(510 * unit, 204 * unit) context.stroke(); + + console.log(th.data.share_img_localpath); + + //---中间大图--- context.drawImage(th.data.share_img_localpath, 68 * unit, 242 * unit, 410 * unit, 410 * unit); @@ -429,7 +434,6 @@ Page({ //---文字--- context.setFontSize(22 * unit) - context.font = 'normal bold'; context.setFillStyle("black") context.fillText("好物拼起来,拼拼更划算", 40 * unit, 726 * unit); @@ -438,7 +442,7 @@ Page({ context.drawImage(ct_img, 40 * unit, 740 * unit, 120 * unit, 30 * unit); var ct_num = th.data.teamlist.ct_num; context.setFontSize(14 * unit) - context.font = 'normal'; + context.setFillStyle("red") if(ct_num<10){ context.fillText(ct_num+"人拼团", 92 * unit, 760 * unit); @@ -450,7 +454,7 @@ Page({ context.setFillStyle("gray") context.fillText(wz+"快来和我一起拼团吧!", 40 * unit, 826 * unit); context.setFillStyle("black") - context.font = 'normal bold 18px sans-serif'; + context.setFontSize(22 * unit) context.fillText("长按识别二维码,立即参团", 40 * unit, 856 * unit); //---二维吗图--- @@ -464,7 +468,6 @@ Page({ context.stroke(); //---文字--- context.setFontSize(22 * unit) - context.font = 'normal bold'; context.setFillStyle("black") context.fillText("好物拼起来,拼拼更划算", 40 * unit, 726 * unit); //---绘制中间阶梯的价格--- @@ -472,7 +475,6 @@ Page({ for(var i=0; i canvasWidth) { han++; - ctx.setFontSize(21.3 * unit) - ctx.setFillStyle("black") - if (han == 2) ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 else @@ -571,8 +573,6 @@ Page({ titleHeight += 20; } if (i == str.length - 1) { //绘制剩余部分 - ctx.setFontSize(21.3 * unit) - ctx.setFillStyle("black") ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); } } @@ -649,7 +649,10 @@ Page({ tt(); } }); - } + }, + + + }) diff --git a/utils/util.js b/utils/util.js index 26779aa..1d4929b 100644 --- a/utils/util.js +++ b/utils/util.js @@ -200,6 +200,37 @@ function gettimestamp(){ timestamp = timestamp / 1000; return timestamp; } + + +function measureText(text, fontSize = 10) { + text = String(text); + var text = text.split(''); + var width = 0; + text.forEach(function (item) { + if (/[a-zA-Z]/.test(item)) { + width += 7; + } else if (/[0-9]/.test(item)) { + width += 5.5; + } else if (/\./.test(item)) { + width += 2.7; + } else if (/-/.test(item)) { + width += 3.25; + } else if (/[\u4e00-\u9fa5]/.test(item)) { //中文匹配 + width += 10; + } else if (/\(|\)/.test(item)) { + width += 3.73; + } else if (/\s/.test(item)) { + width += 2.5; + } else if (/%/.test(item)) { + width += 8; + } else { + width += 10; + } + }); + return width * fontSize / 10; +} + + module.exports = { formatTime: function(e, r) { var t = e ? new Date(1e3 * e) : new Date(), n = t.getFullYear(), o = t.getMonth() + 1, a = t.getDate(), u = t.getHours(), i = t.getMinutes(), f = t.getSeconds(), s = function(e) { @@ -287,4 +318,5 @@ module.exports = { isString: isString, isArray: isArray, sub_last: sub_last,//去掉末尾一个字符 + measureText: measureText,//画布需要的函数 };