35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { PAPER_SIZE } from './constant';
|
|
|
|
export function setCanvasSize(canvas: Canvas, paperSize: PaperSize) {
|
|
const sizeObj = PAPER_SIZE[paperSize];
|
|
// const { pixelRatio: dpr, windowWidth, windowHeight } = wx.getWindowInfo();
|
|
// const printWidth = A4.width;
|
|
// const printHeight = A4.height;
|
|
// @ts-ignore
|
|
// const originWidth = canvas._width || windowWidth;
|
|
// // @ts-ignore
|
|
// const originHeight = canvas._height || windowHeight;
|
|
|
|
canvas.width = sizeObj.width;
|
|
canvas.height = sizeObj.height;
|
|
console.log('canvas----:', canvas);
|
|
return canvas;
|
|
}
|
|
|
|
export async function getMiniCodeImage(canvas: Canvas) {
|
|
return getImage(canvas, '/assets/imgs/doodle-mini-code.jpg');
|
|
}
|
|
|
|
export async function getImage(canvas: Canvas, path: string) {
|
|
return new Promise((resolve, reject) => {
|
|
const image = canvas.createImage();
|
|
image.onload = () => {
|
|
resolve(image);
|
|
};
|
|
image.onerror = () => {
|
|
reject('图片加载异常');
|
|
};
|
|
image.src = path;
|
|
});
|
|
}
|