poster.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0">
  7. <meta http-equiv="pragram" content="no-cache">
  8. <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
  9. <meta http-equiv="expires" content="0">
  10. <title>海报</title>
  11. </head>
  12. <body>
  13. <div class="wrapper">
  14. <!-- swiper -->
  15. <div class="swiper-container">
  16. <div class="swiper-wrapper" id="swiper-wrapper"></div>
  17. <!-- 分页器 -->
  18. <div class="swiper-pagination"></div>
  19. </div>
  20. <!-- swiper end -->
  21. <!-- 底部按钮操作 -->
  22. <div class="footer-box">
  23. <div class="download" id="use-item">
  24. <svg t="1589188673344" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5245" width="24" height="24"><path d="M1.948098 12.487805h999.02439v999.02439h-999.02439z" fill="#FFFFFF" fill-opacity=".01" p-id="5246"></path><path d="M331.326439 674.341463l125.827122 115.337366a49.95122 49.95122 0 0 0 67.509073 0L650.46478 674.341463h215.064976a49.95122 49.95122 0 0 1 49.95122 49.95122v118.109658a49.95122 49.95122 0 0 1-49.95122 49.95122h-724.292683a49.95122 49.95122 0 0 1-49.951219-49.95122V724.292683a49.95122 49.95122 0 0 1 49.951219-49.95122h190.089366z" fill="#8AB6FE" p-id="5247"></path><path d="M590.798049 472.213854h135.617561a24.97561 24.97561 0 0 1 16.858536 43.407609l-235.52 215.864196a24.97561 24.97561 0 0 1-33.717073 0l-235.52-215.864196a24.97561 24.97561 0 0 1 16.883512-43.407609h135.617561V193.061463a49.95122 49.95122 0 0 1 49.95122-49.951219h99.902439a49.95122 49.95122 0 0 1 49.951219 49.951219v279.177366z" fill="#3C85FD" p-id="5248"></path></svg>
  25. <p>保存到相册</p>
  26. </div>
  27. <p class="cancel-btn" id="cancel-btn">取消</p>
  28. </div>
  29. <!-- 底部按钮操作 end -->
  30. <!-- 使用海报 弹框 -->
  31. <div class="zy-h5-fix-z" id="zy-h5-fix-z"></div>
  32. <div class="zy-h5-modal" id="zy-h5-modal">
  33. <div class="zy-h5-modal-content">
  34. <img src="#" class="poster-pic" id="poster-img" />
  35. <p class="save-txt" id="save-txt">长按保存海报图片</p>
  36. </div>
  37. </div>
  38. </div>
  39. </body>
  40. <style>
  41. *{
  42. margin: 0;
  43. padding: 0;
  44. }
  45. html,body{
  46. width: 100%;
  47. height: 100%;
  48. }
  49. .wrapper{
  50. width: 100%;
  51. height: 100%;
  52. position: relative;
  53. }
  54. .swiper-container{
  55. width: 100%;
  56. height: 100%;
  57. --swiper-theme-color: #ebedf0;
  58. --swiper-pagination-color: #fff;/* 两种都可以 */
  59. }
  60. .swiper-container-horizontal>.swiper-pagination-bullets, .swiper-pagination-custom, .swiper-pagination-fraction{
  61. bottom: 140px;
  62. }
  63. .poster-con{
  64. position: relative;
  65. width: 100%;
  66. height: 100%;
  67. background-color: #fff;
  68. display: flex;
  69. align-items: center;
  70. }
  71. .qrcode{
  72. position: absolute;
  73. bottom: 5%;
  74. right: 20px;
  75. margin-left: -64px;
  76. border: 5px solid #fff;
  77. }
  78. .poster-pic{
  79. display: block;
  80. width: 100%;
  81. }
  82. .footer-box{
  83. position: absolute;
  84. bottom: 0;
  85. left: 0;
  86. width: 100%;
  87. text-align: center;
  88. z-index: 1;
  89. }
  90. .footer-box > .download{
  91. background-color: #ededed;
  92. padding: 3% 0;
  93. }
  94. .download > img{
  95. display: inline-block;
  96. width: 40px;
  97. margin-bottom: 4px;
  98. }
  99. .download > p{
  100. margin: 0;
  101. font-size: 13px;
  102. }
  103. .footer-box > .cancel-btn{
  104. background-color: #fff;
  105. margin: 0;
  106. padding: 2% 0;
  107. }
  108. /*弹框样式*/
  109. .zy-h5-fix-z{
  110. width: 100%;
  111. height: 100%;
  112. position: fixed;
  113. top: 0;
  114. left: 0;
  115. background: rgba(0,0,0,0.5);
  116. display: none;
  117. z-index: 5000;
  118. }
  119. .zy-h5-modal{
  120. background: #fff;
  121. border-radius: 5px;
  122. overflow: hidden;
  123. position: fixed;
  124. z-index: 10000;
  125. width: 70%;
  126. top: 30%;
  127. left: 50%;
  128. margin-left: -35%;
  129. margin-top: -140px;
  130. border: 1px solid #eee;
  131. display: none;
  132. }
  133. .save-txt{
  134. font-size: 12px;
  135. text-align: center;
  136. line-height: 36px;
  137. }
  138. </style>
  139. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  140. <link rel="stylesheet" href="http://static.chelingzhu.com/active/swiper.min.css">
  141. <script src="http://static.chelingzhu.com/active/swiper.min.js"></script>
  142. <!-- 生成二维码 -->
  143. <script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
  144. <!-- html转canvas base64图片 -->
  145. <script src="https://cdn.bootcdn.net/ajax/libs/html2canvas/0.5.0-beta3/html2canvas.min.js"></script>
  146. <script>
  147. function getQueryVariable(variable)
  148. {
  149. var query = window.location.search.substring(1);
  150. var vars = query.split("&");
  151. for (var i=0;i<vars.length;i++) {
  152. var pair = vars[i].split("=");
  153. if(pair[0] == variable){return pair[1];}
  154. }
  155. return(false);
  156. }
  157. // app 中点击保存图片到手机
  158. var bitmap = null;
  159. if(window.plus){
  160. plusReady();
  161. }else{
  162. document.addEventListener("plusready",plusReady,false);
  163. }
  164. function plusReady(){
  165. bitmap = new plus.nativeObj.Bitmap();
  166. document.getElementById("save-txt").display = "none"
  167. $("#cancel-btn").hide()
  168. }
  169. // 保存到相册
  170. function savePhoto(dataURL){
  171. if(window.plus){
  172. // 加载海报图片
  173. bitmap.loadBase64Data(dataURL, function() {
  174. var itemId = new Date().getTime()
  175. //保存到系统相册
  176. bitmap.save("_doc/poster_"+itemId+".jpg", {
  177. overwrite: true, //是否覆盖已有图片, true 是
  178. quality: 100 //图片质量,1-100 默认50, 100质量最高
  179. }, function(e) {
  180. plus.gallery.save(e.target, function () {
  181. alert( "保存图片到相册成功" );
  182. });
  183. }, function(e) {
  184. alert("图片保存失败")
  185. });
  186. }, function(e) {
  187. alert("图片保存失败")
  188. });
  189. }
  190. }
  191. // 加载海报
  192. var acitveId = getQueryVariable("id")
  193. var reqUrl = getQueryVariable("reqUrl")
  194. window.onclose = function(){
  195. bitmap.clear()
  196. }
  197. window.onload = function(){
  198. // swiper当前下标
  199. var swiperInd = 0
  200. // 获取活动信息 (海报和门店二维码)
  201. $.ajax({
  202. url: reqUrl + 'active/findActiveAttach/' + acitveId,
  203. type: 'get',
  204. header: {
  205. contentType: 'application/json;charset=UTF-8',
  206. },
  207. // 设置的是请求参数
  208. data: {},
  209. dataType: 'json',
  210. success: function (res) {
  211. if(res.status == 200){
  212. const data = res.data
  213. if(data.activeAttachList){
  214. let html = ''
  215. for(let i = 0; i < data.activeAttachList.length; i++){
  216. html += `<div class="swiper-slide">
  217. <div class="poster-con" id="poster-con${i}">
  218. <div class="qrcode" id="qrcode${i}"></div>
  219. <img src="${data.activeAttachList[i].attachPath}" class="poster-pic" style="pointer-events: none;" />
  220. </div>
  221. </div>`
  222. }
  223. document.getElementById("swiper-wrapper").innerHTML = html
  224. for(let i = 0; i < data.activeAttachList.length; i++){
  225. // 生成二维码
  226. new QRCode(document.getElementById("qrcode" + i ), {
  227. text: getQueryVariable("orgId") ? data.staticHtmlPath + '?orgId=' + getQueryVariable("orgId") : data.staticHtmlPath,
  228. width: 100,
  229. height: 100,
  230. colorDark : "#000000",
  231. colorLight : "#ffffff",
  232. correctLevel : QRCode.CorrectLevel.H
  233. })
  234. }
  235. // swiper
  236. var mySwiper = new Swiper ('.swiper-container', {
  237. // loop: true, // 循环模式选项
  238. // 如果需要分页器
  239. pagination: {
  240. el: '.swiper-pagination',
  241. },
  242. on: {
  243. slideChange: function(){
  244. swiperInd = this.activeIndex
  245. },
  246. }
  247. })
  248. // 打开 海报弹框
  249. document.getElementById("use-item").onclick = function(){
  250. // 合并图片和二维码
  251. html2canvas(document.getElementById('poster-con' + swiperInd), {
  252. backgroundColor: "transparent",
  253. allowTaint: true,
  254. useCORS: true
  255. }).then(canvas => {
  256. let dataURL = canvas.toDataURL("image/png")
  257. document.getElementById('poster-img').src = dataURL
  258. if (dataURL !== "") {
  259. // 打开弹框
  260. document.getElementById("zy-h5-modal").style.display = 'block'
  261. document.getElementById("zy-h5-fix-z").style.display = 'block'
  262. // 保存到相册
  263. savePhoto(dataURL)
  264. }else{
  265. alert('海报生成失败,请重试')
  266. }
  267. })
  268. }
  269. document.getElementById("zy-h5-fix-z").onclick = function(){
  270. document.getElementById("zy-h5-modal").style.display = 'none'
  271. document.getElementById("zy-h5-fix-z").style.display = 'none'
  272. }
  273. // 取消
  274. document.getElementById('cancel-btn').onclick = function(){
  275. history.go(-1)
  276. }
  277. }
  278. }else{
  279. alert(res.message)
  280. }
  281. }
  282. })
  283. }
  284. </script>
  285. </html>