feat: 拼音描红和默写一

This commit is contained in:
R524809
2026-05-20 10:18:25 +08:00
parent b70e54d6b0
commit cab4e9c33f
5 changed files with 23 additions and 20 deletions
@@ -48,7 +48,7 @@ Component({
formSubtitle: '', formSubtitle: '',
formTags: '', formTags: '',
formStatus: 'draft', formStatus: 'draft',
formCropMode: 'header-footer', formCropMode: 'header-only', // header-only | header-footer | none
formQuality: DEBUG_PUBLISH_DEFAULT_QUALITY, formQuality: DEBUG_PUBLISH_DEFAULT_QUALITY,
formWidth: DEBUG_PUBLISH_DEFAULT_WIDTH, formWidth: DEBUG_PUBLISH_DEFAULT_WIDTH,
maxSizeKB: DEBUG_PUBLISH_MAX_SIZE_KB, maxSizeKB: DEBUG_PUBLISH_MAX_SIZE_KB,
@@ -83,7 +83,7 @@ Component({
formSubtitle: meta?.subtitle ?? '', formSubtitle: meta?.subtitle ?? '',
formTags: meta?.tags?.join(', ') ?? '', formTags: meta?.tags?.join(', ') ?? '',
formStatus: meta?.status ?? 'draft', formStatus: meta?.status ?? 'draft',
formCropMode: 'header-footer', formCropMode: 'header-only', // 默认裁剪头部
formQuality: DEBUG_PUBLISH_DEFAULT_QUALITY, formQuality: DEBUG_PUBLISH_DEFAULT_QUALITY,
formWidth: DEBUG_PUBLISH_DEFAULT_WIDTH, formWidth: DEBUG_PUBLISH_DEFAULT_WIDTH,
}); });
@@ -19,7 +19,7 @@ export const PINYIN_DICTATION_WORKSHEET_DEFINITIONS = [
{ {
id: 'pinyin-tracing', id: 'pinyin-tracing',
icon: 'draw-o', icon: 'draw-o',
title: '描红练习', title: '拼音描红练习',
subtitle: '跟着描红学拼音字母', subtitle: '跟着描红学拼音字母',
ageMin: 5, ageMin: 5,
ageMax: 7, ageMax: 7,
@@ -30,7 +30,7 @@ export const PINYIN_DICTATION_WORKSHEET_DEFINITIONS = [
{ {
id: 'pinyin-dictation', id: 'pinyin-dictation',
icon: 'start-a', icon: 'start-a',
title: '默写练习', title: '拼音默写练习',
subtitle: '空白格子默写拼音字母', subtitle: '空白格子默写拼音字母',
ageMin: 6, ageMin: 6,
ageMax: 8, ageMax: 8,
@@ -106,7 +106,7 @@ createPage(
const next = !this.data.isPreviewFavorite; const next = !this.data.isPreviewFavorite;
this.setData({ isPreviewFavorite: next }); this.setData({ isPreviewFavorite: next });
const id = this.data.worksheetId; const id = this.data.worksheetId;
if (id) { if (id && this._favoritedMap) {
this._favoritedMap[id] = next; this._favoritedMap[id] = next;
if (next) { if (next) {
addFavorite(id); addFavorite(id);
@@ -124,7 +124,7 @@ createPage(
const ids = PINYIN_DICTATION_MODE_OPTIONS.map((d) => d.id); const ids = PINYIN_DICTATION_MODE_OPTIONS.map((d) => d.id);
this._favoritedMap = await batchCheckFavorited(ids); this._favoritedMap = await batchCheckFavorited(ids);
const currentId = this.data.worksheetId; const currentId = this.data.worksheetId;
if (this._favoritedMap[currentId]) { if (this._favoritedMap?.[currentId]) {
this.setData({ isPreviewFavorite: true }); this.setData({ isPreviewFavorite: true });
} }
}, },
@@ -145,7 +145,7 @@ createPage(
worksheetId, worksheetId,
functionId: worksheetId, functionId: worksheetId,
currentMode: worksheetId as PinyinDictationMode, currentMode: worksheetId as PinyinDictationMode,
isPreviewFavorite: !!this._favoritedMap[worksheetId], isPreviewFavorite: !!this._favoritedMap?.[worksheetId],
}, },
() => { () => {
this.initPageInfo(worksheetId, '拼音字母默写'); this.initPageInfo(worksheetId, '拼音字母默写');
@@ -1,4 +1,8 @@
import { MOCK_SEED_COUNTS } from './mockLikes'; import { MOCK_SEED_COUNTS } from './mockLikes';
import { MATH_WORKSHEET_DEFINITIONS } from '../../mathPages/mathDraw/mathDraw.config';
import { FOCUS_WORKSHEET_DEFINITIONS } from '../../focusPages/focusDraw/focusDraw.config';
import { LETTER_TRACING_WORKSHEET_DEFINITIONS } from '../../englishPages/letterTracing/letterTracing.config';
import { PINYIN_DICTATION_MODE_OPTIONS } from '../../pinyinPages/pinyinDictation/pinyinDictation.config';
type CloudFunctionResult<T> = { type CloudFunctionResult<T> = {
success?: boolean; success?: boolean;
@@ -47,29 +51,28 @@ function inferGradeFromAge(ageMin: number, ageMax: number): number {
return ageGradeMap[centerAge] ?? 0; return ageGradeMap[centerAge] ?? 0;
} }
type ConfigModule = Record<string, readonly LocalDef[] | unknown>;
type ConfigSource = { type ConfigSource = {
label: string; label: string;
modulePath: string; data: readonly LocalDef[];
exportName: string;
}; };
const CONFIG_SOURCES: ConfigSource[] = [ const CONFIG_SOURCES: ConfigSource[] = [
{ {
label: 'math', label: 'math',
modulePath: '../../mathPages/mathDraw/mathDraw.config', data: MATH_WORKSHEET_DEFINITIONS as unknown as LocalDef[],
exportName: 'MATH_WORKSHEET_DEFINITIONS',
}, },
{ {
label: 'focus', label: 'focus',
modulePath: '../../focusPages/focusDraw/focusDraw.config', data: FOCUS_WORKSHEET_DEFINITIONS as unknown as LocalDef[],
exportName: 'FOCUS_WORKSHEET_DEFINITIONS',
}, },
{ {
label: 'letterTracing', label: 'letterTracing',
modulePath: '../../englishPages/letterTracing/letterTracing.config', data: LETTER_TRACING_WORKSHEET_DEFINITIONS as unknown as LocalDef[],
exportName: 'LETTER_TRACING_WORKSHEET_DEFINITIONS', },
{
label: 'pinyin',
data: PINYIN_DICTATION_MODE_OPTIONS as unknown as LocalDef[],
}, },
]; ];
@@ -85,8 +88,7 @@ function isLocalDef(value: unknown): value is LocalDef {
} }
async function loadConfigSource(source: ConfigSource): Promise<LocalDef[]> { async function loadConfigSource(source: ConfigSource): Promise<LocalDef[]> {
const mod = (await require.async(source.modulePath)) as ConfigModule; const rows = source.data;
const rows = mod[source.exportName];
if (!Array.isArray(rows) || !rows.every(isLocalDef)) { if (!Array.isArray(rows) || !rows.every(isLocalDef)) {
throw new Error(`${source.label} 配置格式不正确`); throw new Error(`${source.label} 配置格式不正确`);
+3 -2
View File
@@ -69,7 +69,7 @@ export async function getFavoriteList(
data: { action: 'list', page, pageSize }, data: { action: 'list', page, pageSize },
}); });
const result = (res?.result as any) || {}; const result = (res?.result as any) || {};
return result.code === 0 ? result.data : []; return result.code === 0 ? result.data || [] : [];
} catch (e) { } catch (e) {
console.error('getFavoriteList failed', e); console.error('getFavoriteList failed', e);
return []; return [];
@@ -126,9 +126,10 @@ export async function batchCheckFavorited(
data: { action: 'batchCheck', worksheetIds }, data: { action: 'batchCheck', worksheetIds },
}); });
const result = (res?.result as any) || {}; const result = (res?.result as any) || {};
return result.code === 0 ? result.data : {}; return result.code === 0 ? result.data || {} : {};
} catch (e) { } catch (e) {
console.error('batchCheckFavorited failed', e); console.error('batchCheckFavorited failed', e);
return {}; return {};
} }
} }