index.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <script type="text/javascript">
  7. /**
  8. * URL参数转换为对象
  9. */
  10. Location.prototype.searchObj = function(url) {
  11. var obj = {};
  12. var arr = (url || this.search).match(/[?&][^?&]+=[^?&]+/g);
  13. if (arr) {
  14. arr.forEach(function(item) {
  15. var tempArr = item.substring(1).split('=');
  16. obj[decodeURIComponent(tempArr[0])] = decodeURIComponent(tempArr[1]);
  17. length++;
  18. });
  19. }
  20. return obj;
  21. }
  22. </script>
  23. <style type="text/css">
  24. #credTpl {
  25. overflow: hidden;
  26. position: fixed;
  27. padding: 0;
  28. margin: 0;
  29. border: 0;
  30. height: 0;
  31. width: 0;
  32. top: 0;
  33. left: 0;
  34. }
  35. .showImg{
  36. position: fixed;
  37. padding: 0;
  38. margin: 0;
  39. border: 0;
  40. top: 1%;
  41. left: 5%;
  42. bottom: 18%;
  43. right: 5%;
  44. }
  45. #showImg {
  46. position: absolute;
  47. padding: 0;
  48. margin: 0;
  49. border: 0;
  50. top: 0;
  51. left: 0;
  52. bottom: 0;
  53. right: 0;
  54. width: 100%;
  55. height: 100%;
  56. }
  57. #loading{
  58. display:none;
  59. position:absolute;
  60. width:7em;
  61. height:7em;
  62. transition: 1s;
  63. left:50%;
  64. top:28%;
  65. margin-left:-4.2em;
  66. background:rgba(0,0,0,0.5);
  67. color:#fff;
  68. padding:15px 10px 2px 10px;
  69. text-align:center;
  70. font-size:12px;
  71. border-radius:6px;
  72. opacity:0;
  73. }
  74. #loading img{
  75. width:4em;
  76. height:4em;
  77. }
  78. #loading p{
  79. margin:0;
  80. }
  81. .noticeButton{
  82. display: none;
  83. position:fixed;
  84. bottom:10px;
  85. left:20px;
  86. right:20px;
  87. height: 40px;
  88. text-align:center;
  89. line-height:40px;
  90. background: #26D18B;
  91. font-size:14px;
  92. color:#fff;
  93. border-radius: 8px;
  94. }
  95. </style>
  96. </head>
  97. <body>
  98. <div class="showImg">
  99. <img src="bg.png" id="showImg">
  100. </div>
  101. <div class="noticeButton">长按证书保存</div>
  102. <div id="loading">
  103. <img src="./loading.gif">
  104. <p>证书生成中</p>
  105. </div>
  106. <iframe id="credTpl" name="credTpl" src="credTpl.html"></iframe>
  107. </body>
  108. <script type="text/javascript">
  109. let loadEle = document.getElementById("loading");
  110. let h5btn = document.getElementsByClassName('noticeButton')[0]
  111. loadEle.style.display = 'block'
  112. setTimeout(function () {
  113. loadEle.style.opacity = 1;
  114. },.1);
  115. let imgSrcFun = function() {};
  116. let iframeOnload = function() {
  117. //取得证书信息缓存
  118. let obj = location.searchObj();
  119. // alert(obj.toString())
  120. // alert(JSON.stringify(obj))
  121. // console.log(obj.isH5 == 'true')
  122. // console.log(obj.isH5)
  123. //是否是小程序端使用
  124. if(obj.isH5 == 'true'){
  125. h5btn.style.display = 'block';
  126. }else{
  127. h5btn.style.display = 'none';
  128. }
  129. let credTpl = window.frames['credTpl'].window; //获取证书框架window
  130. let mycertificate = new credTpl.certificate({ //生成图片
  131. format: 'jpg',
  132. data: {
  133. code: obj.credentialNo || '', //编号
  134. name: obj.certName || '匿名用户', //购买者名字
  135. co2: obj.carbonAmount || 0, //碳汇量
  136. money: obj.orderAmount || 0, //购买多少钱
  137. date: obj.buyDate || '', //购买日期
  138. year:obj.year, //购买年度
  139. farmerName:obj.farmerName //农户姓名
  140. },
  141. success: function(_function) {
  142. imgSrcFun = _function('data');
  143. document.getElementById('showImg').src = imgSrcFun; //预览图片
  144. loadEle.style.opacity = 0;
  145. setTimeout(function () {
  146. loadEle.style.display = 'block'
  147. },900);
  148. }
  149. });
  150. mycertificate.down('A0');
  151. };
  152. /**
  153. * 证书框架加载完毕开始生成
  154. */
  155. let iframe = document.getElementById("credTpl");
  156. if (iframe.attachEvent) {
  157. iframe.attachEvent("onload", iframeOnload);
  158. } else {
  159. iframe.onload = iframeOnload;
  160. }
  161. </script>
  162. </html>