68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { BaseMathDrawService } from './baseMathDraw';
|
|
import { drawNumberDecomposeContent } from './numberDecomposeContentDraw';
|
|
|
|
/**
|
|
* 10以内数的分与合绘制服务
|
|
* 组合使用基础绘制服务和内容区域绘制服务
|
|
*/
|
|
class NumberDecomposeDraw extends BaseMathDrawService {
|
|
decomposeData: {
|
|
problems: Array<{
|
|
whole: number | null;
|
|
part1: number | null;
|
|
part2: number | null;
|
|
imageIndex?: number;
|
|
imageType?: 'fruits' | 'twelve-animals';
|
|
}>;
|
|
mode: 'with-image' | 'decompose' | 'compose';
|
|
} | null;
|
|
|
|
constructor(
|
|
canvas: Canvas,
|
|
ctx: RenderingContext,
|
|
options?: Record<string, any>,
|
|
) {
|
|
super(canvas, ctx, options);
|
|
this.decomposeData = null;
|
|
}
|
|
|
|
async draw(decomposeData: {
|
|
problems: Array<{
|
|
whole: number | null;
|
|
part1: number | null;
|
|
part2: number | null;
|
|
imageIndex?: number;
|
|
imageType?: 'fruits' | 'twelve-animals';
|
|
}>;
|
|
mode: 'with-image' | 'decompose' | 'compose';
|
|
}) {
|
|
if (!decomposeData || !decomposeData.problems) {
|
|
return;
|
|
}
|
|
|
|
this.setPrintConfig();
|
|
this.decomposeData = decomposeData;
|
|
this.clear();
|
|
this.setPaper();
|
|
|
|
// 绘制Header
|
|
if (this.headerType !== 'minimal') {
|
|
await this.drawHeader();
|
|
} else {
|
|
this.drawMiniHeader();
|
|
}
|
|
|
|
// 绘制内容区域
|
|
this.drawDivider();
|
|
await drawNumberDecomposeContent({
|
|
canvas: this.canvas,
|
|
ctx: this.ctx,
|
|
decomposeData: this.decomposeData,
|
|
canvasWidth: this.canvasWidth,
|
|
startY: this.currentY,
|
|
});
|
|
}
|
|
}
|
|
|
|
export default NumberDecomposeDraw;
|