From 26af95b60490a258d5c27ae19ef3bc560a97098c Mon Sep 17 00:00:00 2001 From: joey Date: Tue, 1 Jul 2025 17:18:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/config/config.ts | 6 ++- miniprogram/pages/index/index.less | 6 +-- miniprogram/pages/index/index.ts | 57 ++++++++++++++++++++------ miniprogram/service/textDrawService.ts | 3 ++ 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/miniprogram/config/config.ts b/miniprogram/config/config.ts index 867433a..5cd3918 100644 --- a/miniprogram/config/config.ts +++ b/miniprogram/config/config.ts @@ -1,4 +1,6 @@ type Channel = 'wechat' | 'noLogo' | 'rednoteLogo' | 'miniHeader'; -const channel: Channel = 'miniHeader'; +const channel: Channel = 'wechat'; -export const CHANNEL = channel; \ No newline at end of file +export const CHANNEL = channel; + +export const APP_NAME = '涂鸦丫'; \ No newline at end of file diff --git a/miniprogram/pages/index/index.less b/miniprogram/pages/index/index.less index 9d64614..15834e1 100644 --- a/miniprogram/pages/index/index.less +++ b/miniprogram/pages/index/index.less @@ -81,9 +81,9 @@ page { box-sizing: border-box; } -#canvasContent { - border: 1px solid #666; -} +// #canvasContent { +// border: 1px solid #666; +// } .btn-area { position: fixed; diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index ce0724a..a13e21a 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -49,9 +49,7 @@ Page({ this.boxHeight = boxHeight; this.boxWidth = boxWidth; - setTimeout(() => { - this.initCanvas(boxWidth, boxHeight); - }, 500); + this.initCanvas(boxWidth, boxHeight); } }) .exec(); @@ -132,7 +130,6 @@ Page({ const newCharacters: string[] = []; let isBeyond = false; for (const char of characters) { - // 检查字符是否是新字符且未被使用 if (newCharacters.length >= remainingSlots) { isBeyond = true; break; @@ -150,11 +147,25 @@ Page({ } // 为新字符创建卡片 - const newCards = newCharacters.map((char, index) => { - const colorIndex = index % shuffledColors.length; + const newCards = newCharacters.map((char) => { + // 获取字对应的颜色 + const colorHex = this.getColorByWord(char); + let color: string; + + if (colorHex && !usedColors.includes(colorHex)) { + // 如果有对应颜色且未被使用,使用对应颜色 + color = colorHex; + } else { + // 否则随机选择一个可用颜色 + const randomIndex = Math.floor(Math.random() * shuffledColors.length); + color = shuffledColors[randomIndex]; + // 从可用颜色中移除已使用的颜色 + shuffledColors.splice(randomIndex, 1); + } + return { word: char, - color: shuffledColors[colorIndex], + color: color }; }); @@ -301,14 +312,36 @@ Page({ }); }, + // 获取颜色字对应的16进制颜色值 + getColorByWord(word: string): string | null { + const colorMap: Record = { + '红': '#FF0000', + '蓝': '#0000FF', + '绿': '#00FF00', + '黄': '#FFFF00', + '黑': '#000000', + '白': '#FFFFFF', + '紫': '#800080', + '橙': '#FF7F00', + '粉': '#FF69B4', + '棕': '#A52A2A', + '灰': '#808080' + }; + return colorMap[word] || null; + }, + onChangeWord(e: WechatMiniprogram.CustomEvent) { const selectedWords = e.detail.selectedWords as string[]; - const colors = [...WATER_COLORS.basic12]; - const cardList = selectedWords.map((word, index) => ({ - color: colors[index].hex, - word, - })); + + const cardList = selectedWords.map((word, index) => { + const colorHex = this.getColorByWord(word); + return { + color: colorHex || colors[index].hex, + word + }; + }); + this.setData({ showSelectWordPopup: false }); this.drawCanvas(cardList); }, diff --git a/miniprogram/service/textDrawService.ts b/miniprogram/service/textDrawService.ts index d4efa4a..4b04f45 100644 --- a/miniprogram/service/textDrawService.ts +++ b/miniprogram/service/textDrawService.ts @@ -87,6 +87,7 @@ class TextDrawService { this.characters = list.map((item) => item.word || '日'); this.clear(); this.setPaper(); + // @ts-ignore if (CHANNEL !== 'miniHeader') { this.drawHeader(); } else { @@ -232,6 +233,7 @@ class TextDrawService { ); }); + // @ts-ignore this.currentY = CHANNEL === 'miniHeader' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px this.drawLine(this.currentY); } @@ -241,6 +243,7 @@ class TextDrawService { if (characters.length <= 0) return; const len = characters.length; + // @ts-ignore const rows = CHANNEL === 'miniHeader' ? 9 : 8; const radius = 80; const fontSize = 72;