Commit 078b63bf2fd64baa1ec9a40911da37467403fbfc

Authored by F5VT98DI7XY4X12\Administrator
1 parent d011df3f

拼团文字不显示

pages/goods/goodsInfo/goodsInfo.js
@@ -2215,6 +2215,12 @@ Page({ @@ -2215,6 +2215,12 @@ Page({
2215 //---产品名称--- 2215 //---产品名称---
2216 //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 2216 //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
2217 console.log("ssssssss", th.data.data.goods_name); 2217 console.log("ssssssss", th.data.data.goods_name);
  2218 +
  2219 +f //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
  2220 + console.log("ssssssss", th.data.data.goods_name);
  2221 +
  2222 + context.setFillStyle("black");
  2223 + context.setFontSize(21.3 * unit)
2218 th.draw_Text(context, th.data.data.goods_name, 2224 th.draw_Text(context, th.data.data.goods_name,
2219 38 * unit, 180 * unit, 200 * unit, 279 * unit, unit); 2225 38 * unit, 180 * unit, 200 * unit, 279 * unit, unit);
2220 //------产品的价格------- 2226 //------产品的价格-------
@@ -2302,7 +2308,7 @@ Page({ @@ -2302,7 +2308,7 @@ Page({
2302 context.fillText("快来和我一起拼团吧!", 40 * unit, 826 * unit); 2308 context.fillText("快来和我一起拼团吧!", 40 * unit, 826 * unit);
2303 context.setFillStyle("black") 2309 context.setFillStyle("black")
2304 context.font = 'normal bold 18px sans-serif'; 2310 context.font = 'normal bold 18px sans-serif';
2305 - context.setFontSize(22 * unit) 2311 + context.setFontSize(21.3 * unit)
2306 context.fillText("长按识别二维码,立即参团", 40 * unit, 856 * unit); 2312 context.fillText("长按识别二维码,立即参团", 40 * unit, 856 * unit);
2307 //---二维吗图--- 2313 //---二维吗图---
2308 context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); 2314 context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit);
@@ -2406,12 +2412,11 @@ Page({ @@ -2406,12 +2412,11 @@ Page({
2406 var han=0; 2412 var han=0;
2407 for (let i = 0; i < str.length; i++) { 2413 for (let i = 0; i < str.length; i++) {
2408 if(han==2) return; 2414 if(han==2) return;
2409 - lineWidth += ctx.measureText(str[i]).width; 2415 + //lineWidth += ctx.measureText(str[i]).width;
  2416 + lineWidth += ut.measureText(str[i], 21.3 * unit);
2410 if (lineWidth > canvasWidth) { 2417 if (lineWidth > canvasWidth) {
2411 han++; 2418 han++;
2412 - ctx.setFontSize(21.3 * unit)  
2413 - ctx.setFillStyle("black")  
2414 - 2419 +
2415 if (han==2) 2420 if (han==2)
2416 ctx.fillText(str.substring(lastSubStrIndex, i)+'...', leftWidth, initHeight); //绘制截取部分 2421 ctx.fillText(str.substring(lastSubStrIndex, i)+'...', leftWidth, initHeight); //绘制截取部分
2417 else 2422 else
@@ -2423,8 +2428,6 @@ Page({ @@ -2423,8 +2428,6 @@ Page({
2423 titleHeight += 20; 2428 titleHeight += 20;
2424 } 2429 }
2425 if (i == str.length - 1) { //绘制剩余部分 2430 if (i == str.length - 1) { //绘制剩余部分
2426 - ctx.setFontSize(21.3 * unit)  
2427 - ctx.setFillStyle("black")  
2428 ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); 2431 ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight);
2429 } 2432 }
2430 } 2433 }
pages/team/team_success/team_success.js
@@ -47,7 +47,6 @@ Page({ @@ -47,7 +47,6 @@ Page({
47 }, 47 },
48 onLoad: function (t) { 48 onLoad: function (t) {
49 wx.setNavigationBarTitle({ title: "拼团订单",}) 49 wx.setNavigationBarTitle({ title: "拼团订单",})
50 -  
51 var that=this; 50 var that=this;
52 //获取用户设备信息,屏幕宽度 51 //获取用户设备信息,屏幕宽度
53 wx.getSystemInfo({ 52 wx.getSystemInfo({
@@ -201,7 +200,6 @@ Page({ @@ -201,7 +200,6 @@ Page({
201 } 200 }
202 201
203 202
204 -  
205 //获取商品信息 203 //获取商品信息
206 await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, { 204 await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, {
207 }).then(res => { 205 }).then(res => {
@@ -270,8 +268,7 @@ Page({ @@ -270,8 +268,7 @@ Page({
270 wx.setNavigationBarTitle({ 268 wx.setNavigationBarTitle({
271 title: "拼团详情", 269 title: "拼团详情",
272 }) 270 })
273 -  
274 - 271 +
275 ee.countDown2(); 272 ee.countDown2();
276 273
277 //获取分享图片的本地地址 274 //获取分享图片的本地地址
@@ -365,6 +362,10 @@ Page({ @@ -365,6 +362,10 @@ Page({
365 th.get_head_temp(th.get_goods_temp,function () { 362 th.get_head_temp(th.get_goods_temp,function () {
366 var vpath = res.path; 363 var vpath = res.path;
367 var context = wx.createCanvasContext('share'); 364 var context = wx.createCanvasContext('share');
  365 +
  366 + console.log("saveImageToPhotosAlbum");
  367 + console.log(vpath);
  368 +
368 //先画背景 369 //先画背景
369 var pg_path = "../../../images/share/share_bg.png"; 370 var pg_path = "../../../images/share/share_bg.png";
370 context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit); 371 context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit);
@@ -381,8 +382,8 @@ Page({ @@ -381,8 +382,8 @@ Page({
381 context.fillText('强烈推荐', 152 * unit + width + 20 * unit, 76 * unit); 382 context.fillText('强烈推荐', 152 * unit + width + 20 * unit, 76 * unit);
382 383
383 //---产品名称--- 384 //---产品名称---
384 - context.setFontSize(22 * unit)  
385 - context.setFillStyle("black") 385 + context.setFontSize(21.3 * unit);
  386 + context.setFillStyle("black");
386 th.draw_Text(context, th.data.goods.goods_name, 387 th.draw_Text(context, th.data.goods.goods_name,
387 40 * unit, 180 * unit, 200 * unit, 380 * unit); 388 40 * unit, 180 * unit, 200 * unit, 380 * unit);
388 //------产品的价格------- 389 //------产品的价格-------
@@ -403,6 +404,10 @@ Page({ @@ -403,6 +404,10 @@ Page({
403 context.moveTo(438 * unit, 204 * unit) 404 context.moveTo(438 * unit, 204 * unit)
404 context.lineTo(510 * unit, 204 * unit) 405 context.lineTo(510 * unit, 204 * unit)
405 context.stroke(); 406 context.stroke();
  407 +
  408 + console.log(th.data.share_img_localpath);
  409 +
  410 +
406 //---中间大图--- 411 //---中间大图---
407 context.drawImage(th.data.share_img_localpath, 68 * unit, 242 * unit, 410 * unit, 410 * unit); 412 context.drawImage(th.data.share_img_localpath, 68 * unit, 242 * unit, 410 * unit, 410 * unit);
408 413
@@ -429,7 +434,6 @@ Page({ @@ -429,7 +434,6 @@ Page({
429 434
430 //---文字--- 435 //---文字---
431 context.setFontSize(22 * unit) 436 context.setFontSize(22 * unit)
432 - context.font = 'normal bold';  
433 context.setFillStyle("black") 437 context.setFillStyle("black")
434 context.fillText("好物拼起来,拼拼更划算", 40 * unit, 726 * unit); 438 context.fillText("好物拼起来,拼拼更划算", 40 * unit, 726 * unit);
435 439
@@ -438,7 +442,7 @@ Page({ @@ -438,7 +442,7 @@ Page({
438 context.drawImage(ct_img, 40 * unit, 740 * unit, 120 * unit, 30 * unit); 442 context.drawImage(ct_img, 40 * unit, 740 * unit, 120 * unit, 30 * unit);
439 var ct_num = th.data.teamlist.ct_num; 443 var ct_num = th.data.teamlist.ct_num;
440 context.setFontSize(14 * unit) 444 context.setFontSize(14 * unit)
441 - context.font = 'normal'; 445 +
442 context.setFillStyle("red") 446 context.setFillStyle("red")
443 if(ct_num<10){ 447 if(ct_num<10){
444 context.fillText(ct_num+"人拼团", 92 * unit, 760 * unit); 448 context.fillText(ct_num+"人拼团", 92 * unit, 760 * unit);
@@ -450,7 +454,7 @@ Page({ @@ -450,7 +454,7 @@ Page({
450 context.setFillStyle("gray") 454 context.setFillStyle("gray")
451 context.fillText(wz+"快来和我一起拼团吧!", 40 * unit, 826 * unit); 455 context.fillText(wz+"快来和我一起拼团吧!", 40 * unit, 826 * unit);
452 context.setFillStyle("black") 456 context.setFillStyle("black")
453 - context.font = 'normal bold 18px sans-serif'; 457 +
454 context.setFontSize(22 * unit) 458 context.setFontSize(22 * unit)
455 context.fillText("长按识别二维码,立即参团", 40 * unit, 856 * unit); 459 context.fillText("长按识别二维码,立即参团", 40 * unit, 856 * unit);
456 //---二维吗图--- 460 //---二维吗图---
@@ -464,7 +468,6 @@ Page({ @@ -464,7 +468,6 @@ Page({
464 context.stroke(); 468 context.stroke();
465 //---文字--- 469 //---文字---
466 context.setFontSize(22 * unit) 470 context.setFontSize(22 * unit)
467 - context.font = 'normal bold';  
468 context.setFillStyle("black") 471 context.setFillStyle("black")
469 context.fillText("好物拼起来,拼拼更划算", 40 * unit, 726 * unit); 472 context.fillText("好物拼起来,拼拼更划算", 40 * unit, 726 * unit);
470 //---绘制中间阶梯的价格--- 473 //---绘制中间阶梯的价格---
@@ -472,7 +475,6 @@ Page({ @@ -472,7 +475,6 @@ Page({
472 for(var i=0; i<list.length;i++){ 475 for(var i=0; i<list.length;i++){
473 var item=list[i]; 476 var item=list[i];
474 var wi=i*90*unit; 477 var wi=i*90*unit;
475 - context.font = 'normal';  
476 context.setFontSize(16 * unit) 478 context.setFontSize(16 * unit)
477 context.setFillStyle("red") 479 context.setFillStyle("red")
478 context.fillText("¥", 40 * unit+wi, 756 * unit); 480 context.fillText("¥", 40 * unit+wi, 756 * unit);
@@ -486,9 +488,9 @@ Page({ @@ -486,9 +488,9 @@ Page({
486 //----------------下面部分---------------- 488 //----------------下面部分----------------
487 context.setFillStyle("gray") 489 context.setFillStyle("gray")
488 context.fillText(wz+"快来和我一起拼团吧!", 40 * unit, 830 * unit); 490 context.fillText(wz+"快来和我一起拼团吧!", 40 * unit, 830 * unit);
489 - context.setFillStyle("black")  
490 - context.font = 'normal bold 18px sans-serif'; 491 + context.setFillStyle("black")
491 context.setFontSize(22 * unit) 492 context.setFontSize(22 * unit)
  493 +
492 context.fillText("长按识别二维码,立即参团", 40 * unit, 860 * unit); 494 context.fillText("长按识别二维码,立即参团", 40 * unit, 860 * unit);
493 //---二维吗图--- 495 //---二维吗图---
494 context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); 496 context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit);
@@ -554,12 +556,12 @@ Page({ @@ -554,12 +556,12 @@ Page({
554 var han = 0; 556 var han = 0;
555 for (let i = 0; i < str.length; i++) { 557 for (let i = 0; i < str.length; i++) {
556 if (han == 2) return; 558 if (han == 2) return;
557 - lineWidth += ctx.measureText(str[i]).width; 559 +
  560 + //lineWidth += ctx.measureText(str[i]).width;
  561 + lineWidth += ut.measureText(str[i], 21.3 * unit);
  562 +
558 if (lineWidth > canvasWidth) { 563 if (lineWidth > canvasWidth) {
559 han++; 564 han++;
560 - ctx.setFontSize(21.3 * unit)  
561 - ctx.setFillStyle("black")  
562 -  
563 if (han == 2) 565 if (han == 2)
564 ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 566 ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分
565 else 567 else
@@ -571,8 +573,6 @@ Page({ @@ -571,8 +573,6 @@ Page({
571 titleHeight += 20; 573 titleHeight += 20;
572 } 574 }
573 if (i == str.length - 1) { //绘制剩余部分 575 if (i == str.length - 1) { //绘制剩余部分
574 - ctx.setFontSize(21.3 * unit)  
575 - ctx.setFillStyle("black")  
576 ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); 576 ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight);
577 } 577 }
578 } 578 }
@@ -649,7 +649,10 @@ Page({ @@ -649,7 +649,10 @@ Page({
649 tt(); 649 tt();
650 } 650 }
651 }); 651 });
652 - } 652 + },
  653 +
  654 +
  655 +
653 656
654 }) 657 })
655 658
utils/util.js
@@ -200,6 +200,37 @@ function gettimestamp(){ @@ -200,6 +200,37 @@ function gettimestamp(){
200 timestamp = timestamp / 1000; 200 timestamp = timestamp / 1000;
201 return timestamp; 201 return timestamp;
202 } 202 }
  203 +
  204 +
  205 +function measureText(text, fontSize = 10) {
  206 + text = String(text);
  207 + var text = text.split('');
  208 + var width = 0;
  209 + text.forEach(function (item) {
  210 + if (/[a-zA-Z]/.test(item)) {
  211 + width += 7;
  212 + } else if (/[0-9]/.test(item)) {
  213 + width += 5.5;
  214 + } else if (/\./.test(item)) {
  215 + width += 2.7;
  216 + } else if (/-/.test(item)) {
  217 + width += 3.25;
  218 + } else if (/[\u4e00-\u9fa5]/.test(item)) { //中文匹配
  219 + width += 10;
  220 + } else if (/\(|\)/.test(item)) {
  221 + width += 3.73;
  222 + } else if (/\s/.test(item)) {
  223 + width += 2.5;
  224 + } else if (/%/.test(item)) {
  225 + width += 8;
  226 + } else {
  227 + width += 10;
  228 + }
  229 + });
  230 + return width * fontSize / 10;
  231 +}
  232 +
  233 +
203 module.exports = { 234 module.exports = {
204 formatTime: function(e, r) { 235 formatTime: function(e, r) {
205 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) { 236 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 = { @@ -287,4 +318,5 @@ module.exports = {
287 isString: isString, 318 isString: isString,
288 isArray: isArray, 319 isArray: isArray,
289 sub_last: sub_last,//去掉末尾一个字符 320 sub_last: sub_last,//去掉末尾一个字符
  321 + measureText: measureText,//画布需要的函数
290 }; 322 };