index.js 545 B

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