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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| <script> import JsBarcode from 'JsBarcode'; import qrcode from 'qrcode'; export default { name: 'test', data() { return { printInfo: [ { barCodeData: '21312313213', qrCodeData: '测试二维码测试二维码测试二维码', time: '2019-09-09 12:12:00', sapNo: '123456', mName: '测试名字', sDate: '2019-09-09', bDate: '12月', spec: '袋装25公斤', gys: '测试测试', cctj: '冷藏', dkc: '1000', dq: '12', is: '否', gmy: '' } ] } }, methods:{ printpage(id){ var printIframe = this.$refs.printIframe; var newstr = this.$refs.odiv.innerHTML; printIframe.setAttribute('srcdoc',newstr); printIframe.onload = function () { console.log(printIframe.contentWindow); printIframe.contentWindow.document.body.style.padding = '0px'; printIframe.contentWindow.document.body.style.margin = '0px'; printIframe.contentWindow.focus(); printIframe.contentWindow.print(); }; } }, filters: { creatBarCode(barCodeData){ let canvas = document.createElement("canvas"); JsBarcode(canvas, barCodeData, { format: "CODE128", displayValue: true, margin: 0, height: 40, width: 1.5, fontSize: 12, textMargin: 0 }); return canvas.toDataURL("image/png"); }, creatQrCode(qrCodeData){ let typeNumber = 10; let errorCorrectionLevel = 'L'; qrcode.stringToBytes = qrcode.stringToBytesFuncs['UTF-8']; let qr = qrcode(typeNumber, errorCorrectionLevel); qr.addData(qrCodeData,'Byte'); qr.make(); return qr.createDataURL(2,0); } }, } </script>
|