feat:架构代码优化
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { BaseDrawService } from '../../../service/baseDraw';
|
||||
import { drawAdditionContent } from './additionContentDraw';
|
||||
|
||||
/**
|
||||
* 加减法计算绘制服务
|
||||
* 组合使用基础绘制服务和内容区域绘制服务
|
||||
*/
|
||||
class AdditionDraw extends BaseDrawService {
|
||||
calculationData: {
|
||||
problems: Array<{
|
||||
type: 'addition' | 'subtraction';
|
||||
left: number;
|
||||
right: number;
|
||||
result: number;
|
||||
}>;
|
||||
} | null;
|
||||
|
||||
constructor(
|
||||
canvas: Canvas,
|
||||
ctx: RenderingContext,
|
||||
options?: Record<string, any>,
|
||||
) {
|
||||
super(canvas, ctx, options);
|
||||
this.calculationData = null;
|
||||
}
|
||||
|
||||
async draw(
|
||||
calculationData: {
|
||||
problems: Array<{
|
||||
type: 'addition' | 'subtraction';
|
||||
left: number;
|
||||
right: number;
|
||||
result: number;
|
||||
}>;
|
||||
},
|
||||
_calculationType: string = 'addition-5', // 保留参数以保持接口兼容性
|
||||
_imageType?: string, // 可选,不再使用,每个运算会随机选择图片类型
|
||||
) {
|
||||
if (!calculationData || !calculationData.problems) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setPrintConfig();
|
||||
this.calculationData = calculationData;
|
||||
this.clear();
|
||||
this.setPaper();
|
||||
|
||||
// 绘制Header
|
||||
if (this.headerType !== 'minimal') {
|
||||
await this.drawHeader();
|
||||
} else {
|
||||
this.drawMiniHeader();
|
||||
}
|
||||
|
||||
// 绘制内容区域(加减法计算)
|
||||
this.drawDivider();
|
||||
await drawAdditionContent({
|
||||
canvas: this.canvas,
|
||||
ctx: this.ctx,
|
||||
problems: this.calculationData.problems,
|
||||
canvasWidth: this.canvasWidth,
|
||||
startY: this.currentY,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default AdditionDraw;
|
||||
Reference in New Issue
Block a user