qrcode.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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: 300px;padding-top:10px;padding-bottom:10px;margin: 0 auto;text-align: center;">-->
  9. <!-- &lt;!&ndash;<img src="{:url('Qrcode/qrcode',[],'')}?code={$code}" width="300" alt="">&ndash;&gt;-->
  10. <!-- <img src="/admin/img/goods_card.jpg" width="300" alt="">-->
  11. <!-- <img style="position: absolute;margin-top: 49px;margin-left: -283px" src="{:url('Qrcode/qrcode',[],'')}?code={$code}" width="96" alt="">-->
  12. <!-- <h5 style="position: absolute;font-weight:bold;margin-left: 200px;margin-top: -89px;text-align: center">{$info.title}</h5>-->
  13. <!-- <h5 style="position: absolute;font-weight:bold;margin-left: 200px;margin-top: -68px;text-align: center">{$info.brand}</h5>-->
  14. <!-- <h5 style="position: absolute;font-weight:bold;margin-left: 200px;margin-top: -44px;text-align: center">{$info.spec}</h5>-->
  15. <!-- </div>-->
  16. <div id="printer" class="text-center" style="width: 300px;padding-top:10px;padding-bottom:10px;margin: 0 auto;text-align: center;">
  17. <style>
  18. .pbox{
  19. width: 300px;
  20. height: 157px;
  21. position: relative;
  22. }
  23. .pbox .qrimg{
  24. display: inline-block;
  25. position: absolute;
  26. top: 48px;
  27. left: 18px;
  28. width: 96px;
  29. height: 96px;
  30. z-index: 10;
  31. }
  32. .pbox .ptitle{
  33. position: absolute;
  34. top: 54px;
  35. left: 156px;
  36. width: 126px;
  37. height: 25px;
  38. line-height: 25px;
  39. overflow: hidden;
  40. }
  41. .pbox .pbrand{
  42. position: absolute;
  43. top: 75px;
  44. left: 156px;
  45. width: 126px;
  46. height: 25px;
  47. line-height: 25px;
  48. overflow: hidden;
  49. }
  50. .pbox .pspec{
  51. position: absolute;
  52. top: 98px;
  53. left: 156px;
  54. width: 126px;
  55. height: 25px;
  56. line-height: 25px;
  57. overflow: hidden;
  58. }
  59. </style>
  60. <div class="pbox">
  61. <img src="/admin/img/goods_card.jpg" width="300" alt="">
  62. <img class="qrimg" src="{:url('Qrcode/qrcode',[],'')}?code={$code}" alt="">
  63. <h5 class="ptitle">{$info.title}</h5>
  64. <h5 class="pbrand">{$info.brand}</h5>
  65. <h5 class="pspec">{$info.spec}</h5>
  66. </div>
  67. </div>
  68. <a href="javascript:;" class="btn btn-sm btn-primary" onclick="print()">
  69. <i class="glyphicon glyphicon-print">打印</i>
  70. </a>
  71. <a href="javascript:;" class="btn btn-sm btn-primary" onclick="down()">
  72. <i class="fa fa-cloud-download">下载</i>
  73. </a>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. {/block}
  80. {block name="script"}
  81. <script src="/static/browser.js"></script>
  82. <script src="/static/jquery.jqprint-0.3.js"></script>
  83. <script src="/static/html2canvas.min.js"></script>
  84. <script>
  85. function print(){
  86. $("#printer").jqprint();
  87. } function down() {
  88. var canvas2 = document.createElement("canvas");
  89. let _canvas = document.querySelector('#printer');
  90. var w = parseInt(window.getComputedStyle(_canvas).width);
  91. var h = parseInt(window.getComputedStyle(_canvas).height);
  92. //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
  93. canvas2.width = w * 4;
  94. canvas2.height = h * 4;
  95. canvas2.style.width = w * 4 + "px";
  96. canvas2.style.height = h * 4 + "px";
  97. //可以按照自己的需求,对context的参数修改,translate指的是偏移量
  98. // var context = canvas.getContext("2d");
  99. // context.translate(0,0);
  100. var rect = $('#printer').get(0).getBoundingClientRect();//获取元素相对于视察的偏移量
  101. var context = canvas2.getContext("2d");
  102. context.scale(4, 4);
  103. // context.translate(rect.left, -rect.top);
  104. html2canvas(document.querySelector('#printer'), {
  105. // canvas: canvas2,
  106. //allowTaint : false,
  107. taintTest: true,
  108. useCORS: true,
  109. }).then(function (canvas) {
  110. var saveFile = function (data, filename) {
  111. var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
  112. save_link.href = data;
  113. save_link.download = filename;
  114. var event = document.createEvent('MouseEvents');
  115. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  116. save_link.dispatchEvent(event);
  117. };
  118. //最终文件名
  119. var filename = '{$info.title}.png';
  120. saveFile(canvas.toDataURL(), filename);
  121. });
  122. }
  123. </script>
  124. {/block}