feat:代码优化

This commit is contained in:
R524809
2025-12-04 17:26:04 +08:00
parent 7f8a9b1c4d
commit c8788669c7
23 changed files with 339 additions and 428 deletions
@@ -1,4 +1,5 @@
import { getImage } from '../../utils/index';
import { getRandomNumberColor } from '../../constants/colors';
interface DrawCountMatchContentParams {
canvas: WechatMiniprogram.Canvas;
@@ -130,8 +131,8 @@ export async function drawCountMatchContent({
true,
);
// 绘制数字
ctx.fillStyle = '#000';
// 绘制数字(使用随机颜色)
ctx.fillStyle = getRandomNumberColor();
ctx.font = `bold ${56}px "Microsoft Yahei"`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
@@ -1,21 +1,4 @@
/**
* 数字颜色映射(使用基础12色)
* 由于只有10个数字,使用全部12种颜色中的11种(跳过黑色,因为黑色不适合作为数字颜色)
*/
const NUMBER_COLORS: Record<number, string> = {
1: '#ED6D50', // 柔和红色
2: '#F9A857', // 柔和橙色
3: '#FFE176', // 柔和黄色
4: '#B2D94B', // 柔和黄绿色
5: '#53D1B6', // 柔和绿色
6: '#6CD2EA', // 柔和青色
7: '#79A7ED', // 柔和蓝色
8: '#9C98DE', // 柔和紫色
9: '#F2A4C0', // 柔和粉色
10: '#FC9B6C', // 柔和橙红色
11: '#BC8F71', // 柔和棕色
12: '#666666', // 柔和黑灰
};
import { getNumberColors } from '../../constants/colors';
interface DrawNumberColorContentParams {
canvas: WechatMiniprogram.Canvas;
@@ -366,7 +349,7 @@ export async function drawNumberColorContent({
const startYPos = startY + 20;
// 获取所有可用颜色值
const availableColors = Object.values(NUMBER_COLORS);
const availableColors = getNumberColors();
// 为每一行随机分配颜色,确保不重复
const shuffledColors = [...availableColors];