Commit 078b63bf2fd64baa1ec9a40911da37467403fbfc

Authored by F5VT98DI7XY4X12\Administrator
1 parent d011df3f

拼团文字不显示

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