feat:架构代码优化
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { BaseDrawService } from '../../../service/baseDraw';
|
||||
import { drawCompareContent } from './compareContentDraw';
|
||||
|
||||
/**
|
||||
* 数一数比大小绘制服务
|
||||
* 组合使用基础绘制服务和内容区域绘制服务
|
||||
*/
|
||||
class CompareDraw extends BaseDrawService {
|
||||
compareData: {
|
||||
problems: Array<{
|
||||
leftCount: number;
|
||||
rightCount: number;
|
||||
leftImageIndex: number;
|
||||
rightImageIndex: number;
|
||||
imageType: 'fruits' | 'twelve-animals';
|
||||
}>;
|
||||
} | null;
|
||||
|
||||
constructor(
|
||||
canvas: Canvas,
|
||||
ctx: RenderingContext,
|
||||
options?: Record<string, any>,
|
||||
) {
|
||||
super(canvas, ctx, options);
|
||||
this.compareData = null;
|
||||
}
|
||||
|
||||
async draw(compareData: {
|
||||
problems: Array<{
|
||||
leftCount: number;
|
||||
rightCount: number;
|
||||
leftImageIndex: number;
|
||||
rightImageIndex: number;
|
||||
imageType: 'fruits' | 'twelve-animals';
|
||||
}>;
|
||||
}) {
|
||||
if (!compareData || !compareData.problems) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setPrintConfig();
|
||||
this.compareData = compareData;
|
||||
this.clear();
|
||||
this.setPaper();
|
||||
|
||||
// 绘制Header
|
||||
if (this.headerType !== 'minimal') {
|
||||
await this.drawHeader();
|
||||
} else {
|
||||
this.drawMiniHeader();
|
||||
}
|
||||
|
||||
// 绘制内容区域(数一数比大小)
|
||||
this.drawDivider();
|
||||
await drawCompareContent({
|
||||
canvas: this.canvas,
|
||||
ctx: this.ctx,
|
||||
compareData: this.compareData,
|
||||
canvasWidth: this.canvasWidth,
|
||||
startY: this.currentY,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default CompareDraw;
|
||||
Reference in New Issue
Block a user