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 }