qrcode.html 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <div class="row">
  4. <div class="col-sm-12">
  5. <div class="ibox float-e-margins">
  6. <div class="ibox-content">
  7. <div class="text-center">
  8. <div id="printer" class="text-center" style="width: 350px;height: 350px;padding-top:20px;margin: 0 auto;text-align: center;">
  9. <img src="{:url('Qrcode/qrcode',[],'')}?code={$code}" width="300" alt="">
  10. <p>{$info.title}</p>
  11. <p><br></p>
  12. </div>
  13. <div style="opacity: 0;position: fixed">
  14. <div id="printer1" class="text-center" style="width:530px;height:720px;margin: 0 auto;text-align: center;">
  15. <img style="
  16. position: absolute;
  17. top: 28%;
  18. left: 21%; " src="{:url('Qrcode/qrcode',[],'')}?code={$code}" width="300" alt="">
  19. <img src="/admin/img/addr.png" width="530" alt="">
  20. <p style="
  21. position: relative;
  22. font-size: 34px;
  23. top: -200px;
  24. color: #0a2c40;
  25. ">{$info.title}</p>
  26. <p><br></p>
  27. </div>
  28. </div>
  29. <a href="javascript:;" class="btn btn-sm btn-primary" onclick="print()">
  30. <i class="glyphicon glyphicon-print">打印</i>
  31. </a>
  32. <a href="javascript:;" class="btn btn-sm btn-primary" onclick="down()">
  33. <i class="fa fa-cloud-download">下载</i>
  34. </a>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. {/block}
  41. {block name="script"}
  42. <script src="/static/browser.js"></script>
  43. <script src="/static/jquery.jqprint-0.3.js"></script>
  44. <script src="/static/html2canvas.min.js"></script>
  45. <script>
  46. function print(){
  47. $("#printer").jqprint();
  48. }
  49. function down() {
  50. var canvas2 = document.createElement("canvas");
  51. let _canvas = document.querySelector('#printer1');
  52. var w = parseInt(window.getComputedStyle(_canvas).width);
  53. var h = parseInt(window.getComputedStyle(_canvas).height);
  54. //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
  55. canvas2.width = w * 4;
  56. canvas2.height = h * 4;
  57. canvas2.style.width = w * 4 + "px";
  58. canvas2.style.height = h * 4 + "px";
  59. //可以按照自己的需求,对context的参数修改,translate指的是偏移量
  60. // var context = canvas.getContext("2d");
  61. // context.translate(0,0);
  62. var rect = $('#printer1').get(0).getBoundingClientRect();//获取元素相对于视察的偏移量
  63. var context = canvas2.getContext("2d");
  64. context.scale(4, 4);
  65. // context.translate(rect.left, -rect.top);
  66. html2canvas(document.querySelector('#printer1'), {
  67. // canvas: canvas2,
  68. //allowTaint : false,
  69. taintTest: true,
  70. useCORS: true,
  71. }).then(function (canvas) {
  72. var saveFile = function (data, filename) {
  73. var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
  74. save_link.href = data;
  75. save_link.download = filename;
  76. var event = document.createEvent('MouseEvents');
  77. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  78. save_link.dispatchEvent(event);
  79. };
  80. //最终文件名
  81. var filename = '{$info.title}.png';
  82. saveFile(canvas.toDataURL(), filename);
  83. });
  84. }
  85. </script>
  86. {/block}