feat: 新增幼儿测字表

This commit is contained in:
R524809
2026-06-11 14:39:06 +08:00
parent a6e8f4df02
commit 25a37fc5e2
15 changed files with 1046 additions and 52 deletions
@@ -0,0 +1,76 @@
import { WORDS } from '../../../core/data/words';
export const WORD_TEST_GROUP_SIZE = 50;
export interface WordTestCategory {
id: string;
icon: string;
name: string;
parentName?: string;
words: string[];
}
export interface WordTestGroup {
index: number;
label: string;
words: string[];
}
const EXCLUDED_CATEGORY_IDS = new Set([4, 5]);
/** 默认分类:一年级上册 */
export const DEFAULT_WORD_TEST_CATEGORY_ID = '26-一年级上册';
export function buildWordTestCategories(): WordTestCategory[] {
const result: WordTestCategory[] = [];
for (const cat of WORDS) {
if (EXCLUDED_CATEGORY_IDS.has(cat.categoryId)) continue;
if (cat.sections?.length) {
for (const section of cat.sections) {
result.push({
id: `${cat.categoryId}-${section.sectionName}`,
icon: cat.icon,
name: section.sectionName,
parentName: cat.categoryName,
words: section.words,
});
}
continue;
}
if (cat.words?.length) {
result.push({
id: String(cat.categoryId),
icon: cat.icon,
name: cat.categoryName,
words: cat.words,
});
}
}
return result;
}
export function buildWordTestGroups(words: string[]): WordTestGroup[] {
if (!words.length) return [];
const groups: WordTestGroup[] = [];
for (let i = 0; i < words.length; i += WORD_TEST_GROUP_SIZE) {
const index = Math.floor(i / WORD_TEST_GROUP_SIZE) + 1;
groups.push({
index,
label: `${index}`,
words: words.slice(i, i + WORD_TEST_GROUP_SIZE),
});
}
return groups;
}
export function findWordTestCategory(
categories: WordTestCategory[],
id: string,
): WordTestCategory | undefined {
return categories.find((cat) => cat.id === id);
}