feat: 完成分龄页开发

This commit is contained in:
R524809
2026-05-06 17:28:51 +08:00
parent 50394154f7
commit 9bdf850f20
54 changed files with 3499 additions and 1021 deletions
@@ -2,22 +2,27 @@ import type { LetterTracingMode } from './generators/letter-tracing-generator';
import type { DebugPublishMeta } from '../../utils/debugPublish';
import { inferGradeFromAge } from '../../utils/debugPublish';
interface ModeDefinition {
/** 本地 worksheet 元数据(与云库 `worksheets` 文档 `_id` 对齐) */
interface LetterTracingWorksheetDefinition {
id: LetterTracingMode;
icon: string;
title: string;
subtitle: string;
ageMin: number;
ageMax: number;
difficulty: 1 | 2 | 3 | 4;
tags: string[];
sortOrder: number;
}
const MODES = [
export const LETTER_TRACING_WORKSHEET_DEFINITIONS = [
{
id: 'letter-tracing-single',
icon: 'start-a',
title: '默认字帖',
subtitle: '配图、例句与描红',
ageMin: 4,
ageMax: 7,
difficulty: 1,
tags: ['字母', '描红', '看图描红'],
sortOrder: 42,
@@ -27,6 +32,8 @@ const MODES = [
icon: 'draw-o',
title: '基础描红',
subtitle: 'Uppercase / Lowercase 总览',
ageMin: 5,
ageMax: 7,
difficulty: 1,
tags: ['字母', '描红', '字母总览'],
sortOrder: 44,
@@ -36,6 +43,8 @@ const MODES = [
icon: 'font-size',
title: '大小写对照',
subtitle: '半组字母左大写右小写',
ageMin: 5,
ageMax: 7,
difficulty: 1,
tags: ['字母', '描红', '大小写练习'],
sortOrder: 45,
@@ -45,6 +54,8 @@ const MODES = [
icon: 'two-columns',
title: '两列描红',
subtitle: '左 AM、右 NZ 配对描红',
ageMin: 5,
ageMax: 7,
difficulty: 1,
tags: ['字母', '描红', '两列练习'],
sortOrder: 43,
@@ -54,6 +65,8 @@ const MODES = [
icon: 'square-half',
title: '13字母半表',
subtitle: '每行一个字母,13 字母半表',
ageMin: 5,
ageMax: 8,
difficulty: 2,
tags: ['字母', '描红', '半表练习'],
sortOrder: 47,
@@ -63,6 +76,8 @@ const MODES = [
icon: 'ABC-list',
title: '三字母精练',
subtitle: '每页聚焦 3 个字母深度书写',
ageMin: 5,
ageMax: 7,
difficulty: 2,
tags: ['字母', '描红', '三字母精练'],
sortOrder: 46,
@@ -72,36 +87,37 @@ const MODES = [
icon: 'task-o',
title: '每日打卡',
subtitle: '四宫格每日字母打卡练习',
ageMin: 6,
ageMax: 8,
difficulty: 2,
tags: ['字母', '描红', '每日打卡'],
sortOrder: 48,
},
] as const satisfies ReadonlyArray<ModeDefinition>;
] as const satisfies ReadonlyArray<LetterTracingWorksheetDefinition>;
type Mode = (typeof MODES)[number];
type LetterTracingWorksheetRow = (typeof LETTER_TRACING_WORKSHEET_DEFINITIONS)[number];
const MODE_BY_ID = Object.fromEntries(MODES.map((m) => [m.id, m])) as Record<
string,
Mode
>;
const LETTER_TRACING_WORKSHEET_BY_ID = Object.fromEntries(
LETTER_TRACING_WORKSHEET_DEFINITIONS.map((m) => [m.id, m]),
) as Record<string, LetterTracingWorksheetRow>;
/** 页面渲染用:模式选择器列表 */
export const LETTER_TRACING_MODE_OPTIONS = MODES;
/** 页面渲染用:模式选择器列表(与 `LETTER_TRACING_WORKSHEET_DEFINITIONS` 同义) */
export const LETTER_TRACING_MODE_OPTIONS = LETTER_TRACING_WORKSHEET_DEFINITIONS;
/** 页面 pageInfoLookup 用 */
export function getModeInfo(id: string) {
const m = MODE_BY_ID[id];
const m = LETTER_TRACING_WORKSHEET_BY_ID[id];
return m ? { title: m.title, desc: m.subtitle } : undefined;
}
/** 判断 id 是否有效 */
export function isValidMode(id: string): boolean {
return id in MODE_BY_ID;
return id in LETTER_TRACING_WORKSHEET_BY_ID;
}
/** 发布用:从当前 mode 生成 DebugPublishMeta */
export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
const m = MODE_BY_ID[id];
const m = LETTER_TRACING_WORKSHEET_BY_ID[id];
if (!m) return null;
return {
id: m.id,
@@ -110,9 +126,9 @@ export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
category: 'english',
subcategory: 'letter-tracing',
path: `/englishPages/letterTracing/letterTracing?id=${m.id}`,
ageMin: 4,
ageMax: 7,
grade: inferGradeFromAge(4, 7),
ageMin: m.ageMin,
ageMax: m.ageMax,
grade: inferGradeFromAge(m.ageMin, m.ageMax),
difficulty: m.difficulty,
previewImg: '',
tags: [...m.tags],
@@ -22,6 +22,7 @@ import {
} from '../shared/data/fontProfiles';
import { loadLetterFont } from '../shared/draw/drawTools';
import type { DebugPublishMeta } from '../../utils/debugPublish';
import { incrementWorksheetLikes } from '../../utils/worksheetStats';
/** 三字母精练分组:26 字母每 3 个一组 */
const TRIPLE_GROUPS: { title: string; letters: string[] }[] = [];
@@ -271,9 +272,12 @@ createPage(
this.drawCanvas();
},
onPreviewFavorite() {
async onPreviewFavorite() {
const next = !this.data.isPreviewFavorite;
this.setData({ isPreviewFavorite: next });
if (next) {
incrementWorksheetLikes(this.data.worksheetId);
}
wx.showToast({
title: next ? '收藏成功' : '已取消收藏',
icon: 'none',
@@ -354,6 +358,7 @@ createPage(
worksheetId,
functionId: worksheetId,
traceMode,
isPreviewFavorite: false,
selectedLetter,
selectedLetterPair: `${selectedLetter}${selectedLetter.toLowerCase()}`,
letterCaseLower,