|
|
@@ -454,7 +454,7 @@ function drawCouponDescription(ctx, width, height, scale) {
|
|
|
ctx.textAlign = 'center'
|
|
|
|
|
|
// 文本自动换行辅助函数
|
|
|
- const drawWrappedText = (text, fontSize, yPosition, color) => {
|
|
|
+ const drawWrappedText = (text, fontSize, yPosition, color, maxLines = 2) => {
|
|
|
ctx.font = `${fontSize * scale}px sans-serif`
|
|
|
ctx.fillStyle = color
|
|
|
ctx.textAlign = 'center'
|
|
|
@@ -463,6 +463,7 @@ function drawCouponDescription(ctx, width, height, scale) {
|
|
|
const lineHeight = fontSize * 1.5 * scale
|
|
|
let currentY = yPosition
|
|
|
let currentLine = ''
|
|
|
+ let lineCount = 0
|
|
|
|
|
|
for (let char of text) {
|
|
|
const testLine = currentLine + char
|
|
|
@@ -472,13 +473,21 @@ function drawCouponDescription(ctx, width, height, scale) {
|
|
|
ctx.fillText(currentLine, width / 2, currentY)
|
|
|
currentLine = char
|
|
|
currentY += lineHeight
|
|
|
+ lineCount++
|
|
|
+
|
|
|
+ // 超过最大行数则停止
|
|
|
+ if (lineCount >= maxLines) {
|
|
|
+ // 最后一行添加省略号
|
|
|
+ currentLine = `${currentLine}...`
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
currentLine = testLine
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (currentLine) {
|
|
|
+ if (currentLine && lineCount < maxLines) {
|
|
|
ctx.fillText(currentLine, width / 2, currentY)
|
|
|
}
|
|
|
|
|
|
@@ -516,7 +525,7 @@ function drawCouponDescription(ctx, width, height, scale) {
|
|
|
// ctx.textAlign = 'center'
|
|
|
|
|
|
// 有效期
|
|
|
- let currentY = 350 * scale
|
|
|
+ let currentY = nextLineY - lineHeight + 40 * scale
|
|
|
const validityType = couponDetail.value.validityType
|
|
|
let validityText = ''
|
|
|
|
|
|
@@ -722,7 +731,7 @@ async function drawQRCodeArea(ctx, canvas, qrCodeImg, width, height, scale) {
|
|
|
|
|
|
// 4. 优化二维码提示文字:使用更现代的字体和颜色
|
|
|
ctx.fillStyle = '#424242'
|
|
|
- ctx.font = `${22 * scale}px -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`
|
|
|
+ ctx.font = `${20 * scale}px -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`
|
|
|
ctx.textAlign = 'center'
|
|
|
ctx.textBaseline = 'middle'
|
|
|
ctx.fillText('长按识别小程序码', width / 2, qrY + qrSize + 31 * scale)
|