|
@@ -861,7 +861,8 @@ const onSubmit = async () => {
|
|
|
.filter(Boolean) // 过滤掉空字符串
|
|
|
.join('\n') // 每个内容项换行
|
|
|
console.log('content',content)
|
|
|
- const subtitle = formData.value.content2 ? '(' + item[formData.value.content2] + ')' : ''
|
|
|
+ const subtitle = formData.value.content2 ? item[formData.value.content2] : undefined
|
|
|
+ console.log('subtitle',subtitle)
|
|
|
return {
|
|
|
title: item[formData.value.content],
|
|
|
subtitle:subtitle, // 添加副标题
|
|
@@ -876,12 +877,21 @@ const onSubmit = async () => {
|
|
|
const canvas = document.createElement('canvas')
|
|
|
const ctx = canvas.getContext('2d')
|
|
|
if (ctx) {
|
|
|
+ //内容项数量
|
|
|
+ const lines = label.content.split('\n')
|
|
|
+ console.log('lines',lines)
|
|
|
const size = formData.value.sizeMap[formData.value.size]
|
|
|
canvas.width = size.width
|
|
|
canvas.height = size.height
|
|
|
ctx.fillStyle = 'white'
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
|
|
|
|
|
+ // 绘制黑色边框
|
|
|
+ ctx.strokeStyle = 'black'
|
|
|
+ ctx.lineWidth = 0.5
|
|
|
+ ctx.strokeRect(0, 0, canvas.width, canvas.height)
|
|
|
+
|
|
|
+
|
|
|
// 设置文本对齐方式为居中
|
|
|
ctx.textAlign = 'center'
|
|
|
// 设置字体样式
|
|
@@ -889,19 +899,41 @@ const onSubmit = async () => {
|
|
|
// 设置文本颜色
|
|
|
ctx.fillStyle = 'black'
|
|
|
// 绘制标题
|
|
|
- if (label.subtitle && label.subtitle !== '') {
|
|
|
- ctx.fillText(label.title, canvas.width / 2, size.height * 0.2)
|
|
|
+ if (lines.length>3){
|
|
|
+ if (label.subtitle && label.subtitle !== '') {
|
|
|
+ ctx.fillText(label.title, canvas.width / 2, size.height * 0.2)
|
|
|
+ }else {
|
|
|
+ ctx.fillText(label.title, canvas.width / 2, size.height * 0.3)
|
|
|
+ }
|
|
|
+ }else if (lines.length>2){
|
|
|
+ if (label.subtitle && label.subtitle !== '') {
|
|
|
+ ctx.fillText(label.title, canvas.width / 2, size.height * 0.25)
|
|
|
+ }else {
|
|
|
+ ctx.fillText(label.title, canvas.width / 2, size.height * 0.32)
|
|
|
+ }
|
|
|
}else {
|
|
|
- ctx.fillText(label.title, canvas.width / 2, size.height * 0.3)
|
|
|
+ if (label.subtitle && label.subtitle !== '') {
|
|
|
+ ctx.fillText(label.title, canvas.width / 2, size.height * 0.3)
|
|
|
+ }else {
|
|
|
+ ctx.fillText(label.title, canvas.width / 2, size.height * 0.35)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 添加副标题
|
|
|
if (label.subtitle && label.subtitle !== '') {
|
|
|
ctx.textAlign = 'center'
|
|
|
- ctx.font = `${(size.width + size.height) * 0.03}px Times New Roman`
|
|
|
+ ctx.font = `${(size.width + size.height) * 0.037}px Times New Roman`
|
|
|
ctx.fillStyle = 'black'
|
|
|
- ctx.fillText(label.subtitle, canvas.width / 2, size.height * 0.3)
|
|
|
+ if (lines.length>3) {
|
|
|
+ ctx.fillText('(' + label.subtitle + ')', canvas.width / 2, size.height * 0.3)
|
|
|
+ }else if (lines.length>2){
|
|
|
+ ctx.fillText('(' + label.subtitle + ')', canvas.width / 2, size.height * 0.35)
|
|
|
+ }else {
|
|
|
+ ctx.fillText('(' + label.subtitle + ')', canvas.width / 2, size.height * 0.40)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -910,8 +942,15 @@ const onSubmit = async () => {
|
|
|
// 设置字体样式
|
|
|
ctx.font = `${(size.width+size.height) * 0.03}px 方正黑体简`
|
|
|
// 绘制内容
|
|
|
- const lines = label.content.split('\n')
|
|
|
- let y = size.height * 0.45
|
|
|
+ let y
|
|
|
+ if (lines.length>3) {
|
|
|
+ y = size.height * 0.46
|
|
|
+ }else if (lines.length>2){
|
|
|
+ y = size.height * 0.50
|
|
|
+ }else {
|
|
|
+ y = size.height * 0.55
|
|
|
+ }
|
|
|
+
|
|
|
for (const line of lines) {
|
|
|
ctx.fillText(line, size.width * 0.15, y)
|
|
|
y += Math.min(size.width, size.height) * 0.15 // 每行间隔
|
|
@@ -938,6 +977,8 @@ const onSubmit = async () => {
|
|
|
dialogTableVisible.value = false
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
|