Files
doodle-mini/miniprogram/canvasService/utils.ts
T
2025-03-27 17:45:24 +08:00

38 lines
1.2 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 getMiniCodeImagePath() {
return getImagePath('/assets/imgs/mini-code.jpg');
}
export async function getImagePath(path: string) {
return new Promise((resolve) => {
// 如果是网络图片,需配置downloadFile域名
wx.getImageInfo({
src: path, // 本地图片路径
success: (res) => {
resolve(res.path);
},
fail: (err) => {
console.error('图片加载失败:', err);
resolve(''); // 可设置默认占位图
},
});
});
}