index.js
769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var barcode = require('./barcode');
var qrcode = require('./qrcode');
function convert_length(length) {
  return Math.round(wx.getSystemInfoSync().windowWidth * length / 750);
}
function barc(id, code, width, height,ob) {
  var ctx=null;
  if(ob){
    ctx= wx.createCanvasContext(id,ob)
  }else{
    ctx=wx.createCanvasContext(id)
  }
  barcode.code128(ctx, code, convert_length(width), convert_length(height))
  return ctx;
}
function qrc(id, code, width, height,ob) {
  var ctx=null;
  if(ob) {
    ctx= wx.createCanvasContext(id,ob);
  }else{
    ctx=wx.createCanvasContext(id)
  }
  qrcode.api.draw(code, {
    ctx:ctx,
    width: convert_length(width),
    height: convert_length(height)
  })
  return ctx;
}
module.exports = {
  barcode: barc,
  qrcode: qrc
}