index.js 562 B

123456789101112131415161718192021222324
  1. const barcode = require('./barcode');
  2. const qrcode = require('./qrcode');
  3. function convert_length(length) {
  4. return Math.round(my.getSystemInfoSync().windowWidth * length / 750);
  5. }
  6. function barc(id, code, width, height) {
  7. barcode.code128(my.createCanvasContext(id), code, convert_length(width), convert_length(height));
  8. }
  9. function qrc(id, code, width, height) {
  10. qrcode.api.draw(code, {
  11. ctx: my.createCanvasContext(id),
  12. width: convert_length(width),
  13. height: convert_length(height)
  14. });
  15. }
  16. module.exports = {
  17. barcode: barc,
  18. qrcode: qrc
  19. };