Commit e6505421 by 谢中龙

修改商品保存海报时名字过长两行显示多余不显示

parent 61016ebc
......@@ -163,7 +163,6 @@ Component({
var right = rect.right;
width = rect.width;
var left = rect.left;
console.log(rect)
ctx.setFillStyle('#fff');
ctx.fillRect(0, 0, rect.width, height);
......@@ -183,12 +182,51 @@ Component({
ctx.drawImage(that.data.userAvatar, 12, 290, 40, 40);
}
// title
console.log('productDesc', that.data.productDesc)
if (that.data.productDesc){
ctx.setFontSize(12);
ctx.setFillStyle('#333333');
ctx.setTextAlign('left');
ctx.fillText(that.data.productDesc, 61, 300);
ctx.setFontSize(12);
ctx.setFillStyle('#333333');
ctx.setTextAlign('left');
let arr = that.data.productDesc.split('');
let row = [];
let tempStr = '';
for(let i = 0 ; i < arr.length ; i ++){
if (ctx.measureText(tempStr).width < 100){
tempStr += arr[i];
}
else{
i --;
row.push(tempStr);
tempStr = '';
}
}
console.log(row)
if(row.length > 2){
var rowCut = row.slice(0, 2);
var rowPart = rowCut[1];
var test = "";
var empty = [];
for (var a = 0; a < rowPart.length; a++) {
if (context.measureText(test).width < 220) {
test += rowPart[a];
}
else {
break;
}
}
empty.push(test);
var group = empty[0] + "..."//
rowCut.splice(1, 1, group);
row = rowCut;
}
for (var b = 0; b < row.length; b++) {
ctx.fillText(row[b], 61, 300 + b * 20);
}
// ctx.fillText(that.data.productDesc, 61, 300);
}else{
let explain = JSON.parse(JSON.stringify(that.data.cardExplain))
if (explain[0]){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment