feat: 优化

This commit is contained in:
2025-07-01 17:18:39 +08:00
parent 6d38a17652
commit 26af95b604
4 changed files with 55 additions and 17 deletions
+3 -1
View File
@@ -1,4 +1,6 @@
type Channel = 'wechat' | 'noLogo' | 'rednoteLogo' | 'miniHeader'; type Channel = 'wechat' | 'noLogo' | 'rednoteLogo' | 'miniHeader';
const channel: Channel = 'miniHeader'; const channel: Channel = 'wechat';
export const CHANNEL = channel; export const CHANNEL = channel;
export const APP_NAME = '涂鸦丫';
+3 -3
View File
@@ -81,9 +81,9 @@ page {
box-sizing: border-box; box-sizing: border-box;
} }
#canvasContent { // #canvasContent {
border: 1px solid #666; // border: 1px solid #666;
} // }
.btn-area { .btn-area {
position: fixed; position: fixed;
+45 -12
View File
@@ -49,9 +49,7 @@ Page({
this.boxHeight = boxHeight; this.boxHeight = boxHeight;
this.boxWidth = boxWidth; this.boxWidth = boxWidth;
setTimeout(() => { this.initCanvas(boxWidth, boxHeight);
this.initCanvas(boxWidth, boxHeight);
}, 500);
} }
}) })
.exec(); .exec();
@@ -132,7 +130,6 @@ Page({
const newCharacters: string[] = []; const newCharacters: string[] = [];
let isBeyond = false; let isBeyond = false;
for (const char of characters) { for (const char of characters) {
// 检查字符是否是新字符且未被使用
if (newCharacters.length >= remainingSlots) { if (newCharacters.length >= remainingSlots) {
isBeyond = true; isBeyond = true;
break; break;
@@ -150,11 +147,25 @@ Page({
} }
// 为新字符创建卡片 // 为新字符创建卡片
const newCards = newCharacters.map((char, index) => { const newCards = newCharacters.map((char) => {
const colorIndex = index % shuffledColors.length; // 获取字对应的颜色
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 { return {
word: char, word: char,
color: shuffledColors[colorIndex], color: color
}; };
}); });
@@ -301,14 +312,36 @@ Page({
}); });
}, },
// 获取颜色字对应的16进制颜色值
getColorByWord(word: string): string | null {
const colorMap: Record<string, string> = {
'红': '#FF0000',
'蓝': '#0000FF',
'绿': '#00FF00',
'黄': '#FFFF00',
'黑': '#000000',
'白': '#FFFFFF',
'紫': '#800080',
'橙': '#FF7F00',
'粉': '#FF69B4',
'棕': '#A52A2A',
'灰': '#808080'
};
return colorMap[word] || null;
},
onChangeWord(e: WechatMiniprogram.CustomEvent) { onChangeWord(e: WechatMiniprogram.CustomEvent) {
const selectedWords = e.detail.selectedWords as string[]; const selectedWords = e.detail.selectedWords as string[];
const colors = [...WATER_COLORS.basic12]; const colors = [...WATER_COLORS.basic12];
const cardList = selectedWords.map((word, index) => ({
color: colors[index].hex, const cardList = selectedWords.map((word, index) => {
word, const colorHex = this.getColorByWord(word);
})); return {
color: colorHex || colors[index].hex,
word
};
});
this.setData({ showSelectWordPopup: false }); this.setData({ showSelectWordPopup: false });
this.drawCanvas(cardList); this.drawCanvas(cardList);
}, },
+3
View File
@@ -87,6 +87,7 @@ class TextDrawService {
this.characters = list.map((item) => item.word || '日'); this.characters = list.map((item) => item.word || '日');
this.clear(); this.clear();
this.setPaper(); this.setPaper();
// @ts-ignore
if (CHANNEL !== 'miniHeader') { if (CHANNEL !== 'miniHeader') {
this.drawHeader(); this.drawHeader();
} else { } else {
@@ -232,6 +233,7 @@ class TextDrawService {
); );
}); });
// @ts-ignore
this.currentY = CHANNEL === 'miniHeader' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px this.currentY = CHANNEL === 'miniHeader' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px
this.drawLine(this.currentY); this.drawLine(this.currentY);
} }
@@ -241,6 +243,7 @@ class TextDrawService {
if (characters.length <= 0) return; if (characters.length <= 0) return;
const len = characters.length; const len = characters.length;
// @ts-ignore
const rows = CHANNEL === 'miniHeader' ? 9 : 8; const rows = CHANNEL === 'miniHeader' ? 9 : 8;
const radius = 80; const radius = 80;
const fontSize = 72; const fontSize = 72;