poster_show.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container"}
  11. {block name='title'}拼团海报{/block}
  12. {block name="head"}
  13. <style>
  14. body {
  15. background-color: rgba(0, 0, 0, .6);
  16. font-size: .24rem;
  17. text-align: center;
  18. color: #cecece;
  19. }
  20. img {
  21. width: 6rem;
  22. margin-top: 1.92rem;
  23. margin-bottom: .5rem;
  24. vertical-align: middle;
  25. }
  26. </style>
  27. {/block}
  28. {block name="content"}
  29. <div v-cloak id="app">
  30. <img :src="imgSrc">
  31. <div v-show="imgSrc">长按图片,保存至手机</div>
  32. </div>
  33. <script>
  34. require([
  35. 'vue',
  36. 'helper',
  37. 'qrcode'
  38. ], function (Vue, $h) {
  39. var url = '{$url}',
  40. special = {$special},
  41. vm = new Vue({
  42. el: '#app',
  43. data: {
  44. loading: false,
  45. imgSrc: ''
  46. },
  47. created: function () {
  48. this.createPoster();
  49. },
  50. methods: {
  51. createPoster: function () {
  52. $h.loadFFF();
  53. var imagePromise = new Promise(function (resolve, reject) {
  54. var image = new Image();
  55. image.crossOrigin = 'anonymous';
  56. image.src = special.image + '?' + new Date().getTime();
  57. image.onload = function () {
  58. resolve(image);
  59. },
  60. image.onerror = function () {
  61. reject('error-image');
  62. };
  63. }),
  64. qrcodePromise = new Promise(function (resolve, reject) {
  65. resolve(new QRCode(document.createElement('canvas'), url));
  66. });
  67. Promise.all([
  68. imagePromise,
  69. qrcodePromise
  70. ]).then(function (sources) {
  71. var canvas = document.createElement('canvas'),
  72. context = canvas.getContext('2d'),
  73. money = '¥' + special.money,
  74. i = Math.ceil(special.title.length / 18),
  75. pinkWidth;
  76. canvas.width = 600;
  77. canvas.height = 723;
  78. context.fillStyle = '#FFFFFF';
  79. context.fillRect(0, 0, 600, 723);
  80. context.fillStyle = '#F7F7F7';
  81. context.fillRect(0, 553, 600, 170);
  82. context.drawImage(sources[0], 30, 30, 540, 304);
  83. context.drawImage(sources[1]._el.firstElementChild, 64, 576, 126, 126);
  84. context.font = 'bold 26px sans-serif';
  85. context.fillStyle = '#FF6B00';
  86. context.fillText('¥', 35, 406);
  87. context.font = 'bold 42px sans-serif';
  88. context.fillText(special.pink_money, 56, 406);
  89. pinkWidth = Math.ceil(context.measureText(special.pink_money).width);
  90. context.font = '26px sans-serif';
  91. context.fillStyle = '#999999';
  92. context.fillText(money, pinkWidth + 65, 406);
  93. context.moveTo(pinkWidth + 65, 397);
  94. context.lineTo(Math.ceil(context.measureText(money).width) + pinkWidth + 65, 397);
  95. context.stroke();
  96. context.font = '22px sans-serif';
  97. context.fillText('邀您参与拼团课程', 226, 622);
  98. context.fillText('长按识别参与拼团', 226, 662);
  99. context.font = '28px sans-serif';
  100. context.fillStyle = '#282828';
  101. for (; i--;) {
  102. context.fillText(special.title.substr(i * 18, 18), 35, i * 41 + 472);
  103. }
  104. vm.imgSrc = canvas.toDataURL('image/jpeg');
  105. $h.loadClear();
  106. canvas = null;
  107. }).catch(function (err) {
  108. $h.loadClear();
  109. $h.pushMsg(err);
  110. });
  111. }
  112. }
  113. });
  114. });
  115. </script>
  116. {/block}