feat: 首页增加每日练习模块
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
||||
import { inferGradeFromAge } from '../../utils/debugPublish';
|
||||
|
||||
export type HandwritingSheetMode =
|
||||
| 'handwriting-sheet'
|
||||
| 'handwriting-daily-checkin';
|
||||
export type HandwritingSheetMode = 'hanzi-sheet' | 'hanzi-daily-checkin';
|
||||
|
||||
interface HandwritingSheetWorksheetDefinition {
|
||||
id: HandwritingSheetMode;
|
||||
@@ -20,7 +18,7 @@ interface HandwritingSheetWorksheetDefinition {
|
||||
export const HANDWRITING_SHEET_WORKSHEET_DEFINITIONS: HandwritingSheetWorksheetDefinition[] =
|
||||
[
|
||||
{
|
||||
id: 'handwriting-sheet',
|
||||
id: 'hanzi-sheet',
|
||||
icon: 'draw-o',
|
||||
title: '自定义练字帖',
|
||||
subtitle: '自定义田字格练字帖',
|
||||
@@ -31,7 +29,7 @@ export const HANDWRITING_SHEET_WORKSHEET_DEFINITIONS: HandwritingSheetWorksheetD
|
||||
sortOrder: 35,
|
||||
},
|
||||
{
|
||||
id: 'handwriting-daily-checkin',
|
||||
id: 'hanzi-daily-checkin',
|
||||
icon: 'task-o',
|
||||
title: '汉字每日打卡',
|
||||
subtitle: '每日 8 字带拼音笔顺打卡',
|
||||
@@ -74,7 +72,7 @@ export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
|
||||
title: item.title,
|
||||
subtitle: item.subtitle,
|
||||
category: 'chinese',
|
||||
subcategory: 'handwriting-sheet',
|
||||
subcategory: 'hanzi-sheet',
|
||||
path: `/chinesePages/handwritingSheet/handwritingSheet?id=${item.id}`,
|
||||
ageMin: item.ageMin,
|
||||
ageMax: item.ageMax,
|
||||
|
||||
@@ -33,6 +33,8 @@ const CUSTOM_MAX_WORDS = 11;
|
||||
const CHECKIN_MAX_WORDS = 8;
|
||||
const RANDOM_WORD_COUNT = 8;
|
||||
const CUSTOM_DEFAULT_WORDS = '东西南北日月山河风雨';
|
||||
/** 汉字每日打卡默认文案(8 字,与 CHECKIN_MAX_WORDS 一致) */
|
||||
const CHECKIN_DEFAULT_WORDS = '日拱一卒不期而至';
|
||||
const CUSTOM_CATEGORY_TAGS = WORDS.slice(0, 3).map((cat) => ({
|
||||
categoryId: cat.categoryId,
|
||||
icon: cat.icon,
|
||||
@@ -65,8 +67,7 @@ createPage(
|
||||
data: {
|
||||
pageTitle: HANDWRITING_SHEET_WORKSHEET_DEFINITIONS[0].title,
|
||||
functionId: HANDWRITING_SHEET_WORKSHEET_ID,
|
||||
currentMode:
|
||||
HANDWRITING_SHEET_WORKSHEET_ID as HandwritingSheetMode,
|
||||
currentMode: HANDWRITING_SHEET_WORKSHEET_ID as HandwritingSheetMode,
|
||||
modeOptions: HANDWRITING_SHEET_MODE_OPTIONS,
|
||||
hasContent: false,
|
||||
words: [] as string[],
|
||||
@@ -155,7 +156,7 @@ createPage(
|
||||
|
||||
async prepareCanvasForCurrentMode() {
|
||||
if (!this.canvas) return;
|
||||
if (this.data.currentMode === 'handwriting-sheet') {
|
||||
if (this.data.currentMode === 'hanzi-sheet') {
|
||||
if (!this.wordDrawService) return;
|
||||
await this.wordDrawService.drawLayout();
|
||||
const { maxRow, maxCol } =
|
||||
@@ -167,11 +168,8 @@ createPage(
|
||||
}
|
||||
},
|
||||
|
||||
applyMode(
|
||||
mode: HandwritingSheetMode,
|
||||
options?: { redraw?: boolean },
|
||||
) {
|
||||
const isCheckin = mode === 'handwriting-daily-checkin';
|
||||
applyMode(mode: HandwritingSheetMode, options?: { redraw?: boolean }) {
|
||||
const isCheckin = mode === 'hanzi-daily-checkin';
|
||||
const max = isCheckin ? CHECKIN_MAX_WORDS : CUSTOM_MAX_WORDS;
|
||||
|
||||
this.setData(
|
||||
@@ -253,7 +251,7 @@ createPage(
|
||||
},
|
||||
|
||||
getMaxWordsForMode(): number {
|
||||
return this.data.currentMode === 'handwriting-daily-checkin'
|
||||
return this.data.currentMode === 'hanzi-daily-checkin'
|
||||
? CHECKIN_MAX_WORDS
|
||||
: CUSTOM_MAX_WORDS;
|
||||
},
|
||||
@@ -375,8 +373,25 @@ createPage(
|
||||
},
|
||||
|
||||
initDefaultWords() {
|
||||
if (this.data.currentMode === 'handwriting-daily-checkin') {
|
||||
this.refreshWords();
|
||||
if (this.data.currentMode === 'hanzi-daily-checkin') {
|
||||
const defaults = this.getSupportedWords(
|
||||
this.splitToSingleChars(CHECKIN_DEFAULT_WORDS),
|
||||
).slice(0, CHECKIN_MAX_WORDS);
|
||||
|
||||
if (defaults.length === 0) {
|
||||
this.refreshWords();
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData(
|
||||
{
|
||||
words: defaults,
|
||||
inputWords: defaults,
|
||||
selectedWords: [],
|
||||
inputValue: defaults.join(''),
|
||||
},
|
||||
() => this.renderPracticeContent().catch(console.error),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -401,8 +416,7 @@ createPage(
|
||||
},
|
||||
|
||||
refreshWords() {
|
||||
const isCheckin =
|
||||
this.data.currentMode === 'handwriting-daily-checkin';
|
||||
const isCheckin = this.data.currentMode === 'hanzi-daily-checkin';
|
||||
const candidates = isCheckin
|
||||
? collectFirstGradeWords()
|
||||
: WORDS.slice(0, 3).reduce(
|
||||
@@ -446,7 +460,7 @@ createPage(
|
||||
|
||||
const words = this.data.words as string[];
|
||||
|
||||
if (this.data.currentMode === 'handwriting-daily-checkin') {
|
||||
if (this.data.currentMode === 'hanzi-daily-checkin') {
|
||||
await this.renderCheckinContent(words);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user