certificate_detail.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. .poster {
  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" class="poster">
  31. <div v-show="imgSrc">长按图片,保存至手机</div>
  32. <quick-menu></quick-menu>
  33. </div>
  34. <script>
  35. require([
  36. 'vue',
  37. 'helper',
  38. 'store',
  39. 'moment',
  40. 'quick'
  41. ], function (Vue, $h, $http, moment) {
  42. var vm = new Vue({
  43. el: '#app',
  44. data: {
  45. nickname: "{$userInfo['realname'] ? $userInfo['realname'] : $userInfo['nickname']}",
  46. loading: false,
  47. certificate: null,
  48. imgSrc: ''
  49. },
  50. watch: {
  51. loading: function (loading) {
  52. loading ? $h.loadFFF() : $h.loadClear();
  53. },
  54. certificate: function (certificate) {
  55. this.createCertificate(certificate);
  56. }
  57. },
  58. created: function () {
  59. this.getCertificateDetail();
  60. },
  61. methods: {
  62. getCertificateDetail: function () {
  63. this.loading = true;
  64. $http.baseGet($h.U({
  65. c: 'topic',
  66. a: 'viewCertificate',
  67. q: {
  68. id: $h.getParmas('id'),
  69. obtain: $h.getParmas('obtain')
  70. }
  71. }), function (res) {
  72. vm.loading = false;
  73. vm.certificate = res.data.data;
  74. }, function (err) {
  75. $h.pushMsg(err, function () {
  76. history.back();
  77. });
  78. });
  79. },
  80. createCertificate: function (certificate) {
  81. this.loading = true;
  82. var promiseArr = [];
  83. for (var key in certificate.certificate) {
  84. if (Object.hasOwnProperty.call(certificate.certificate, key)) {
  85. switch (key) {
  86. case 'background':
  87. case 'qr_code':
  88. promiseArr.push(new Promise(function (resolve, reject) {
  89. var image = new Image();
  90. image.crossOrigin = 'anonymous';
  91. image.src = certificate.certificate[key] + '?' + new Date().getTime();
  92. image.onload = function () {
  93. resolve(image);
  94. };
  95. image.onerror = function () {
  96. reject('error-' + key);
  97. }
  98. }));
  99. break;
  100. }
  101. }
  102. }
  103. Promise.all(promiseArr).then(function (imageArr) {
  104. var canvas = document.createElement('canvas'),
  105. context = canvas.getContext('2d');
  106. canvas.width = imageArr[0].width;
  107. canvas.height = imageArr[0].height;
  108. context.drawImage(imageArr[0], 0, 0);
  109. context.drawImage(imageArr[1], 220, 557, 160, 160);
  110. context.fillStyle = 'rgba(255, 255, 255, 0.8)';
  111. context.fillRect(220, 724, 160, 36);
  112. context.font = 'bold 34px sans-serif';
  113. context.textAlign = 'center';
  114. context.fillStyle = '#29466D';
  115. context.fillText(vm.nickname, 300, 296);
  116. context.font = '24px sans-serif';
  117. context.fillText('颁发时间:' + moment(vm.certificate.add_time * 1000).format('YYYY.MM.DD'), 300, 490);
  118. context.font = '20px sans-serif';
  119. context.fillStyle = '#666666';
  120. context.fillText('长按二维码查看', 300, 748);
  121. context.font = '28px sans-serif';
  122. context.textAlign = 'start';
  123. context.fillStyle = '#333333';
  124. var lineWidth = 0;
  125. var substringFrom = 0;
  126. var offsetTop = 364;
  127. for (var i = 0; i < vm.certificate.certificate.explain.length; i++) {
  128. lineWidth += context.measureText(vm.certificate.certificate.explain[i]).width;
  129. if (lineWidth > 434) {
  130. context.fillText(vm.certificate.certificate.explain.substring(substringFrom, i), 83, offsetTop);
  131. lineWidth = 0;
  132. substringFrom = i;
  133. offsetTop += 50;
  134. }
  135. if (i == vm.certificate.certificate.explain.length - 1) {
  136. context.fillText(vm.certificate.certificate.explain.substring(substringFrom, i), 83, offsetTop);
  137. }
  138. }
  139. vm.imgSrc = canvas.toDataURL('image/jpeg');
  140. vm.loading = false;
  141. canvas = null;
  142. }).catch(function (err) {
  143. vm.loading = false;
  144. $h.pushMsg(err);
  145. });
  146. }
  147. }
  148. });
  149. });
  150. </script>
  151. {/block}