feat:完成自定义文字涂色卡

This commit is contained in:
2025-07-02 15:17:50 +08:00
parent 26af95b604
commit 8006695f65
19 changed files with 201 additions and 39 deletions
+14 -12
View File
@@ -1,6 +1,5 @@
// import { PAPER_SIZE } from './constant';
import { PAPER_SIZE } from '../constants/colors';
import { CHANNEL } from '../config/config';
import { getMiniCodeImage, getImage } from '../utils/index';
/**
@@ -51,6 +50,7 @@ function calculateCircleCenters(
}
class TextDrawService {
headerType: PrintHeader;
canvas: WechatMiniprogram.Canvas;
ctx: RenderingContext;
options: Record<string, any>;
@@ -83,12 +83,13 @@ class TextDrawService {
}
draw(list: Array<{ color: string; word: string }>) {
this.headerType = getApp().getPrintHeader() || 'wechat';
this.colors = list.map((item) => item.color || '#000');
this.characters = list.map((item) => item.word || '日');
this.clear();
this.setPaper();
// @ts-ignore
if (CHANNEL !== 'miniHeader') {
if (this.headerType !== 'minimal') {
this.drawHeader();
} else {
this.drawMiniHeader();
@@ -112,15 +113,17 @@ class TextDrawService {
const logoWidth = 200;
const logoHeight = 200;
switch (CHANNEL) {
// @ts-ignore
case 'rednoteLogo': {
switch (this.headerType) {
case 'LogoImage': {
const image = await getImage(canvas, '/assets/imgs/doodle-logo.png');
ctx.drawImage(image, logoX, logoY, logoWidth, logoHeight);
break;
}
// @ts-ignore
case 'noLogo': {
case 'noLogoImage': {
titleX = 120;
break;
}
case 'minimal': {
titleX = 120;
break;
}
@@ -187,6 +190,7 @@ class TextDrawService {
const { canvas, ctx, colors, characters } = this;
if (characters.length <= 0) return;
// const { colors, characters } = options;
this.currentY = this.headerType === 'minimal' ? 200 : 304;
const radius = 65;
const rectWidth = 180;
const rectHeight = 80;
@@ -233,8 +237,7 @@ class TextDrawService {
);
});
// @ts-ignore
this.currentY = CHANNEL === 'miniHeader' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px
this.currentY = this.headerType === 'minimal' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px
this.drawLine(this.currentY);
}
@@ -243,8 +246,7 @@ class TextDrawService {
if (characters.length <= 0) return;
const len = characters.length;
// @ts-ignore
const rows = CHANNEL === 'miniHeader' ? 9 : 8;
const rows = this.headerType === 'minimal' ? 9 : 8;
const radius = 80;
const fontSize = 72;