credTpl.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <!-- 强制让文档与设备的宽度保持1:1 -->
  7. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  9. <script type="text/javascript" src="http://cdn.webfont.youziku.com/wwwroot/js/wf/youziku.api.min.js"></script>
  10. <script type="text/javascript">
  11. $youziku.load(".title span", "94d4ba0acbef4c97b7abfecaa9a3e1a8", "cyjianxk");
  12. $youziku.draw();
  13. </script>
  14. <style type="text/css">
  15. * {
  16. margin: 0;
  17. padding: 0;
  18. border: 0;
  19. }
  20. .ui-absolute {
  21. position: absolute;
  22. top: 0;
  23. bottom: 0;
  24. left: 0;
  25. right: 0;
  26. margin: auto;
  27. }
  28. .ui-relative {
  29. position: relative;
  30. }
  31. .cred {
  32. background: url(bg.png) no-repeat center center;
  33. background-size: 100% 100%;
  34. width: calc(908px/1.5);
  35. height: calc(1304px/1.5);
  36. font-size: calc(908px/1.5*0.11);
  37. margin: 0 auto;
  38. }
  39. .cred .logo,
  40. .cred .QR-code {
  41. bottom: auto;
  42. padding-top: 20%;
  43. width: 20%;
  44. border-radius: 50%;
  45. overflow: hidden;
  46. left: 50%;
  47. right: auto;
  48. transform: translateX(-50%);
  49. }
  50. .cred .logo {
  51. top: 6%;
  52. background: url(logo.png) no-repeat center center;
  53. background-size: 100% 100%;
  54. }
  55. .cred .QR-code {
  56. top: 68%;
  57. background: url(code.png) no-repeat center center;
  58. background-size: 100% 100%;
  59. border-radius: 0;
  60. }
  61. .cred .title {
  62. font-size: .40em;
  63. top: 19%;
  64. bottom: auto;
  65. text-align: center;
  66. line-height: 1.5em;
  67. color: #00984C;
  68. }
  69. .cred .number {
  70. top: 29%;
  71. bottom: auto;
  72. font-size: .28em;
  73. text-align: center;
  74. line-height: 1em;
  75. color: #000;
  76. }
  77. .cred .content {
  78. top: 33%;
  79. bottom: auto;
  80. font-size: .32em;
  81. color: #333333;
  82. margin: auto 12% auto 13%;
  83. font-weight: 300;
  84. }
  85. .cred .content p {
  86. text-indent: 2em;
  87. line-height: 2em;
  88. letter-spacing: .05em;
  89. word-wrap: break-word;
  90. word-break: break-all;
  91. }
  92. .cred .content .name {
  93. text-indent: 0;
  94. }
  95. .cred .content p span {
  96. border-bottom: 2px solid #010101;
  97. overflow: hidden;
  98. }
  99. .cred .seal-1,
  100. .cred .seal-2 {
  101. top: 72%;
  102. bottom: auto;
  103. width: 26.22%;
  104. padding-top: 26.22%;
  105. border-radius: 50%;
  106. }
  107. .cred .seal-1 {
  108. background: url(z1.png) no-repeat center center;
  109. background-size: 100% 100%;
  110. left: 20%;
  111. right: auto;
  112. }
  113. .cred .seal-2 {
  114. background: url(z2.png) no-repeat center center;
  115. background-size: 100% 100%;
  116. right: 20%;
  117. left: auto;
  118. }
  119. .cred .seal-1-text {
  120. top: 84%;
  121. padding-top: 0;
  122. background: none;
  123. font-size: .25em;
  124. bottom: auto;
  125. line-height: 1em;
  126. color: #000;
  127. display: flex;
  128. text-align: center;
  129. width: 60%;
  130. left: 10%;
  131. right: 10%;
  132. }
  133. .cred .seal-1-text span {
  134. flex: 1;
  135. }
  136. .cred .seal-1-text.time {
  137. top: 90%;
  138. right: 0;
  139. left: 0;
  140. margin: auto;
  141. text-align: center;
  142. }
  143. .cred .foot-text {
  144. top: auto;
  145. bottom: 6.82%;
  146. font-size: .23em;
  147. line-height: 1.5em;
  148. left: 13.43%;
  149. right: 13.43%;
  150. color: #595656;
  151. text-indent: 2em;
  152. letter-spacing: .1em;
  153. }
  154. </style>
  155. </head>
  156. <body>
  157. <div class="ui-relative cred" id="cred">
  158. <div class="ui-absolute logo"></div>
  159. <div class="ui-absolute QR-code"></div>
  160. <div class='ui-absolute title'>
  161. <p><span>重庆</span>"<span>碳汇</span>+"<span>生态产品价值实现</span></p>
  162. <p><span>碳信用证书</span></p>
  163. </div>
  164. <div class="ui-absolute number">
  165. <!-- 证书编号:G18G0000001 -->
  166. </div>
  167. <div class="ui-absolute content">
  168. <!-- <p class="name">
  169. 尊敬的
  170. <span>雷</span><span>电</span>:</p>
  171. <p>感谢您对贵州省单株碳汇精准扶贫的支持。您购买了
  172. <span>2018</span>年度单株碳汇
  173. <span>100</span>株,碳汇签发量
  174. <span>1000</span>千克二氧化碳当量,帮助了来自
  175. <span>贵</span>
  176. <span>州</span>
  177. <span>省</span>
  178. <span>安</span>
  179. <span>顺</span>
  180. <span>市</span>
  181. <span>平</span>
  182. <span>坝</span>
  183. <span>区</span>深度贫困村
  184. <span>关口村</span>的
  185. <span>刘兴莲</span>等
  186. <span>15</span>户贫困户。您购碳资金
  187. <span>30000</span>元,已全额转入
  188. <span>刘兴莲</span>等
  189. <span>15</span>户贫困户的个人银行账户。</p>
  190. <p>※该笔碳汇可用于抵消您个人碳排放,为应对全球气候变化做出贡献。</p> -->
  191. </div>
  192. <div class="ui-absolute seal-1-text">
  193. <span>重庆市生态环境局</span>
  194. <span>中国质量认证中心</span>
  195. </div>
  196. <div class="ui-absolute seal-1-text time">
  197. <!-- <span>2018年8月10日</span> -->
  198. </div>
  199. <!-- <div class="ui-absolute seal-1"></div> -->
  200. <!-- <div class="ui-absolute seal-2"></div> -->
  201. <!-- <div class="ui-absolute foot-text">※实名认购记录可作为个人(企业)优良信息,归集到全国信用信息共享平台(贵州)个人(企业)名下。</div> -->
  202. </div>
  203. </body>
  204. <script src="html2canvas.js" type="text/javascript" charset="utf-8"></script>
  205. <script type="text/javascript">
  206. //下载图片
  207. let downloadImg = function(obj) {
  208. obj = obj || {};
  209. this.imgData = obj.data.toDataURL((obj.format || 'image/jpg')) || null;
  210. this.src = '';
  211. this.init();
  212. };
  213. downloadImg.prototype.init = function() {
  214. this.downloadImgFile(this.imgData);
  215. };
  216. //下载
  217. downloadImg.prototype.downloadImgFile = function(content) {
  218. var _this = this;
  219. var blob = this.base64ToBlob(content);
  220. this.src = URL.createObjectURL(blob);
  221. };
  222. downloadImg.prototype.base64ToBlob = function(code) {
  223. let parts = code.split(';base64,');
  224. let contentType = parts[0].split(':')[1];
  225. let raw = window.atob(parts[1]);
  226. let rawLength = raw.length;
  227. let uInt8Array = new Uint8Array(rawLength);
  228. for (let i = 0; i < rawLength; ++i) {
  229. uInt8Array[i] = raw.charCodeAt(i);
  230. }
  231. return new Blob([uInt8Array], {
  232. type: contentType
  233. });
  234. };
  235. window.certificate = function(obj) {
  236. var _this = this;
  237. _this.obj = obj || {
  238. elem: 'cred'
  239. };
  240. _this.contentData = obj.data || {};
  241. _this.content();
  242. _this.elem = _this.obj.elem || 'cred'; //要绘制的页面
  243. _this.elemObj = document.getElementById(_this.elem);
  244. _this.format = _this.obj.format || "jpg"; //下载格式
  245. _this.success = obj.success || function(url, data) {
  246. console.log("没有配置success接收函数");
  247. };
  248. _this.type = null;
  249. _this.A0 = {
  250. width: '1080px',
  251. height: '1551px',
  252. 'font-size': '118.8px'
  253. };
  254. _this.A3 = {
  255. width: '3058px',
  256. 'height': '4961px',
  257. 'font-size': '336.38px'
  258. };
  259. _this.A4 = {
  260. 'width': '2048px',
  261. 'height': '3508px',
  262. 'font-size': '225.28px'
  263. };
  264. // _this.down('A0');
  265. };
  266. certificate.prototype.content = function(obj) {
  267. var _this = this;
  268. this.contentData = obj || this.contentData;
  269. let span = function(name, bool) {
  270. let html = '';
  271. let arr = (typeof(_this.contentData[name]) == 'undefined' ? [] : _this.contentData[name]) + '';
  272. for (let i in arr) {
  273. html += bool ? '<span>' + arr[i] + '</span>' : arr[i];
  274. }
  275. return html;
  276. };
  277. document.getElementsByClassName('number')[0].innerHTML = this.contentData.code == '0' ? '' : '普惠证书编号:' + this.contentData
  278. .code;
  279. document.getElementsByClassName('content')[0].innerHTML = '<p class="name">尊敬的' + span('name', true) +
  280. ':</p>\
  281. <p>欢迎参与重庆“碳汇+”生态产品价值实现试点示范,您此单购买“碳汇+”生态产品' + span('co2') + 'kgCO2减排量,\
  282. 资金支出' + span('money') +
  283. '元,生成碳信用额' + span('credit') + '个,可等量累计“碳汇+”积分' + span('integral') + '分。</p>\
  284. <p>感谢您为生态文明建设做出的贡献!</p>';
  285. document.getElementsByClassName('time')[0].innerHTML = "<span>" + this.contentData.date + "</span>";
  286. };
  287. certificate.prototype.generate = function() {
  288. var _this = this;
  289. _this.style(_this.elemObj, _this[_this.type]);
  290. return _this;
  291. };
  292. certificate.prototype.style = function(elem, styleObj) {
  293. for (let i in styleObj) {
  294. elem.style[i] = styleObj[i];
  295. }
  296. return elem;
  297. };
  298. certificate.prototype.down = function(type) {
  299. if (this.type == type) {
  300. this.aLink.dispatchEvent(this.evt);
  301. return -1;
  302. } else {
  303. this.type = type;
  304. return this.generate().html2canvas();
  305. }
  306. };
  307. certificate.prototype.html2canvas = function() {
  308. var _this = this;
  309. html2canvas(_this.elemObj).then(function(canvas) {
  310. let img = new downloadImg({
  311. data: canvas,
  312. format: 'image/' + (_this.format || 'jpg'),
  313. });
  314. if (img.src) {
  315. _this.src = img.src;
  316. if (_this.success) {
  317. _this.data = canvas.toDataURL('image/' + (_this.format || 'jpg'));
  318. _this.aLink = document.createElement('a');
  319. _this.evt = document.createEvent("MouseEvents");
  320. _this.evt.initEvent("click", true, true);
  321. _this.aLink.download = new Date().getTime() + '.' + (_this.format || 'jpg');
  322. _this.aLink.href = _this.src;
  323. _this.success(function(type) {
  324. switch (type) {
  325. case 'down':
  326. _this.aLink.dispatchEvent(_this.evt);
  327. return _this.src;
  328. break;
  329. case 'url':
  330. return _this.src;
  331. break;
  332. case 'data':
  333. return _this.data;
  334. break;
  335. default:
  336. return _this.src;
  337. }
  338. }, _this.data);
  339. }
  340. }
  341. });
  342. return _this;
  343. };
  344. </script>
  345. </html>