diff --git a/miniprogram/app.json b/miniprogram/app.json index 75b0adc..872492a 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -23,7 +23,10 @@ "makeTen/makeTen", "breakTen/breakTen", "flatTen/flatTen", - "borrowTen/borrowTen" + "borrowTen/borrowTen", + "oneDigitAddition/oneDigitAddition", + "calculationPractice/calculationPractice", + "multiplicationTable/multiplicationTable" ], "independent": false }, diff --git a/miniprogram/assets/mathEntrance/multiplication-table.png b/miniprogram/assets/mathEntrance/multiplication-table.png new file mode 100644 index 0000000..0e2cf59 Binary files /dev/null and b/miniprogram/assets/mathEntrance/multiplication-table.png differ diff --git a/miniprogram/assets/mathEntrance/one-digit-addition.png b/miniprogram/assets/mathEntrance/one-digit-addition.png new file mode 100644 index 0000000..bf5c605 Binary files /dev/null and b/miniprogram/assets/mathEntrance/one-digit-addition.png differ diff --git a/miniprogram/assets/mathEntrance/practice-addition.png b/miniprogram/assets/mathEntrance/practice-addition.png new file mode 100644 index 0000000..8fa2f3d Binary files /dev/null and b/miniprogram/assets/mathEntrance/practice-addition.png differ diff --git a/miniprogram/assets/mathEntrance/practice-mixed.png b/miniprogram/assets/mathEntrance/practice-mixed.png new file mode 100644 index 0000000..ad9244f Binary files /dev/null and b/miniprogram/assets/mathEntrance/practice-mixed.png differ diff --git a/miniprogram/assets/mathEntrance/practice-subtraction.png b/miniprogram/assets/mathEntrance/practice-subtraction.png new file mode 100644 index 0000000..34d9ea5 Binary files /dev/null and b/miniprogram/assets/mathEntrance/practice-subtraction.png differ diff --git a/miniprogram/config/config.ts b/miniprogram/config/config.ts index 35e83e2..5570e0a 100644 --- a/miniprogram/config/config.ts +++ b/miniprogram/config/config.ts @@ -10,7 +10,7 @@ export const defaultPrintConfig: PrintConfig = { // header: 'LogoImage', header: 'wechat', appName: '涂鸦丫小程序', - appHint: '数学|专注力|练字|涂鸦', + appHint: '数学|专注力|识字|练字', }; export const defaultShareConfig = { diff --git a/miniprogram/constants/mathFunctions.ts b/miniprogram/constants/mathFunctions.ts index a64ff54..adfe312 100644 --- a/miniprogram/constants/mathFunctions.ts +++ b/miniprogram/constants/mathFunctions.ts @@ -8,6 +8,22 @@ export interface MathFunctionType { } export const MATH_FUNCTION_TYPES: MathFunctionType[] = [ + { + id: 'number-sort', + page: 'numberSort', + title: '数字排序', + desc: '数字排序,写出正确顺序', + icon: '🔢', + img: '/assets/mathEntrance/number-sort.png', + }, + { + id: 'one-digit-addition', + page: 'oneDigitAddition', + title: '一位数加法', + desc: '通过圆点学习一位数加法运算', + icon: '➕', + img: '/assets/mathEntrance/one-digit-addition.png', + }, { id: 'make-ten', page: 'makeTen', @@ -140,14 +156,6 @@ export const MATH_FUNCTION_TYPES: MathFunctionType[] = [ icon: '❓', img: '/assets/mathEntrance/missing-number.png', }, - { - id: 'number-sort', - page: 'numberSort', - title: '数字排序', - desc: '数字排序,写出正确顺序', - icon: '🔢', - img: '/assets/mathEntrance/number-sort.png', - }, // 第四阶段:简单运算(从易到难) { @@ -182,4 +190,38 @@ export const MATH_FUNCTION_TYPES: MathFunctionType[] = [ icon: '±', img: '/assets/mathEntrance/addition-subtraction-10.png', }, + // 计算练习题 + { + id: 'practice-addition', + page: 'calculationPractice', + title: '加法运算', + desc: '练习10/20/50/100以内加法运算', + icon: '➕', + img: '/assets/mathEntrance/practice-addition.png', + }, + { + id: 'practice-subtraction', + page: 'calculationPractice', + title: '减法运算', + desc: '练习10/20/50/100以内减法运算', + icon: '➖', + img: '/assets/mathEntrance/practice-subtraction.png', + }, + { + id: 'practice-mixed', + page: 'calculationPractice', + title: '混合运算', + desc: '练习10/20/50/100以内加减法混合运算', + icon: '±', + img: '/assets/mathEntrance/practice-mixed.png', + }, + // 九九乘法表 + { + id: 'multiplication-table', + page: 'multiplicationTable', + title: '九九乘法表', + desc: '学习九九乘法口诀', + icon: '✖️', + img: '/assets/mathEntrance/multiplication-table.png', + }, ]; diff --git a/miniprogram/mathPages/calculationPractice/calculationPractice.json b/miniprogram/mathPages/calculationPractice/calculationPractice.json new file mode 100644 index 0000000..8a1135a --- /dev/null +++ b/miniprogram/mathPages/calculationPractice/calculationPractice.json @@ -0,0 +1,14 @@ +{ + "navigationBarTitleText": "计算练习题", + "navigationBarBackgroundColor": "#FFD719", + "homeButton": true, + "backgroundColor": "#F6F6F6", + "enablePullDownRefresh": false, + "usingComponents": { + "toy-button": "../../ui/button/button", + "share-guide-popup": "../../components/share-guide-popup/share-guide-popup", + "math-bottom-buttons": "../../components/math-bottom-buttons/math-bottom-buttons", + "math-type-selector": "../../components/math-type-selector/math-type-selector", + "draw-ad": "../../components/draw-ad/draw-ad" + } +} diff --git a/miniprogram/mathPages/calculationPractice/calculationPractice.less b/miniprogram/mathPages/calculationPractice/calculationPractice.less new file mode 100644 index 0000000..64dc649 --- /dev/null +++ b/miniprogram/mathPages/calculationPractice/calculationPractice.less @@ -0,0 +1,2 @@ +// 计算练习题页面样式 +@import '../../base/baseDrawPage.wxss'; \ No newline at end of file diff --git a/miniprogram/mathPages/calculationPractice/calculationPractice.ts b/miniprogram/mathPages/calculationPractice/calculationPractice.ts new file mode 100644 index 0000000..dffe5a7 --- /dev/null +++ b/miniprogram/mathPages/calculationPractice/calculationPractice.ts @@ -0,0 +1,208 @@ +import CalculationPracticeDraw from '../shared/service/calculationPracticeDraw'; +import { + createMathPage, + CanvasDataState, +} from '../shared/common/mathPageMixin'; + +type OperationType = 'addition' | 'subtraction' | 'mixed'; + +createMathPage({ + canvas: null as Canvas | null, + ctx: null as RenderingContext | null, + boxHeight: 0, + boxWidth: 0, + drawService: null as CalculationPracticeDraw | null, + calculationPracticeData: null as { + problems: Array<{ + left: number; + operator: '+' | '-'; + right: number; + result: number; + }>; + } | null, + + data: { + pageTitle: '计算练习题', + functionId: '', + hasContent: false, + showShareDialog: false, + operationType: 'addition' as OperationType, // 运算类型:加法、减法、混合 + currentMode: 'within-10', // 默认10以内 + currentModeName: '10以内', + typeActions: [ + { name: '10以内', value: 'within-10' }, + { name: '20以内', value: 'within-20' }, + { name: '50以内', value: 'within-50' }, + { name: '100以内', value: 'within-100' }, + ], + } as CanvasDataState & { + operationType: OperationType; + currentMode: string; + currentModeName: string; + typeActions: Array<{ name: string; value: string }>; + }, + + onLoad(options: { id?: string; type?: string }) { + const functionId = options.id || 'practice-addition'; + + // 根据 functionId 确定运算类型 + let operationType: OperationType = 'addition'; + if (functionId === 'practice-subtraction') { + operationType = 'subtraction'; + } else if (functionId === 'practice-mixed') { + operationType = 'mixed'; + } else if (options.type) { + operationType = options.type as OperationType; + } + + let pageTitle = '计算练习题'; + if (operationType === 'addition') { + pageTitle = '加法运算'; + } else if (operationType === 'subtraction') { + pageTitle = '减法运算'; + } else if (operationType === 'mixed') { + pageTitle = '混合运算'; + } + + this.setData({ + operationType, + pageTitle, + }); + this.initPageInfo(functionId, pageTitle); + }, + + onReady() { + this.initCanvas({ + createDrawService: ( + canvas: Canvas, + ctx: RenderingContext, + options?: Record, + ) => { + return new CalculationPracticeDraw(canvas, ctx, options); + }, + drawServiceOptions: {}, + onCanvasReady: () => { + // 初始随机生成 + this.onRandom(); + }, + }); + }, + + /** + * 绘制Canvas内容 + */ + async drawCanvas() { + if (!this.ctx || !this.drawService || !this.calculationPracticeData) { + return; + } + + try { + await this.drawService.draw(this.calculationPracticeData); + this.setData({ hasContent: true }); + } catch (error) { + console.error('绘制失败:', error); + this.setData({ hasContent: false }); + } + }, + + /** + * 随机生成 + */ + onRandom() { + // 根据当前模式确定最大值 + let maxValue = 10; + if (this.data.currentMode === 'within-20') { + maxValue = 20; + } else if (this.data.currentMode === 'within-50') { + maxValue = 50; + } else if (this.data.currentMode === 'within-100') { + maxValue = 100; + } + + const problems: Array<{ + left: number; + operator: '+' | '-'; + right: number; + result: number; + }> = []; + const usedProblems = new Set(); + let attempts = 0; + const maxAttempts = 2000; + + const targetCount = 11 * 3; // 12行3列 = 36道题 + + while (problems.length < targetCount && attempts < maxAttempts) { + attempts++; + + let left: number; + let right: number; + let operator: '+' | '-'; + let result: number; + + // 根据运算类型生成题目 + if (this.data.operationType === 'addition') { + // 加法:left + right <= maxValue + left = Math.floor(Math.random() * (maxValue - 1)) + 1; // 1 到 maxValue-1 + const maxRight = maxValue - left; + right = Math.floor(Math.random() * maxRight) + 1; // 1 到 maxRight + operator = '+'; + result = left + right; + } else if (this.data.operationType === 'subtraction') { + // 减法:left - right >= 0, left <= maxValue + left = Math.floor(Math.random() * maxValue) + 1; // 1 到 maxValue + right = Math.floor(Math.random() * left) + 1; // 1 到 left + operator = '-'; + result = left - right; + } else { + // 混合运算:随机选择加法或减法 + const isAddition = Math.random() < 0.5; + if (isAddition) { + left = Math.floor(Math.random() * (maxValue - 1)) + 1; + const maxRight = maxValue - left; + right = Math.floor(Math.random() * maxRight) + 1; + operator = '+'; + result = left + right; + } else { + left = Math.floor(Math.random() * maxValue) + 1; + right = Math.floor(Math.random() * left) + 1; + operator = '-'; + result = left - right; + } + } + + // 使用 "left,operator,right" 作为唯一标识,避免重复 + const problemKey = `${left},${operator},${right}`; + if (usedProblems.has(problemKey)) { + continue; + } + + usedProblems.add(problemKey); + problems.push({ + left, + operator, + right, + result, + }); + } + + if (problems.length < targetCount) { + console.warn( + `只生成了 ${problems.length} 道题目,可能符合条件的题目组合不足`, + ); + } + + this.calculationPracticeData = { problems }; + this.drawCanvas(); + }, + + /** 选择类型 */ + onSelectType(event: any) { + const { name, value } = event.detail; + this.setData({ + currentMode: value, + currentModeName: name, + }); + // 重新生成数据 + this.onRandom(); + }, +}); diff --git a/miniprogram/mathPages/calculationPractice/calculationPractice.wxml b/miniprogram/mathPages/calculationPractice/calculationPractice.wxml new file mode 100644 index 0000000..fbf44f9 --- /dev/null +++ b/miniprogram/mathPages/calculationPractice/calculationPractice.wxml @@ -0,0 +1,6 @@ + + + +