poster.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. <link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
  11. <link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">
  12. <title>海报</title>
  13. </head>
  14. <body>
  15. <div class="wrapper">
  16. <!-- swiper -->
  17. <div class="swiper-container">
  18. <div class="swiper-wrapper" id="swiper-wrapper"></div>
  19. <!-- 分页器 -->
  20. <div class="swiper-pagination"></div>
  21. </div>
  22. <!-- swiper end -->
  23. <!-- 底部按钮操作 -->
  24. <div class="footer-box">
  25. <div class="download" id="use-item">
  26. <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>
  27. <p>保存到相册</p>
  28. </div>
  29. <p class="cancel-btn" id="cancel-btn">取消</p>
  30. </div>
  31. <!-- 底部按钮操作 end -->
  32. <!-- 使用海报 弹框 -->
  33. <div class="zy-h5-fix-z" id="zy-h5-fix-z"></div>
  34. <div class="zy-h5-modal" id="zy-h5-modal">
  35. <div class="zy-h5-modal-content">
  36. <img src="#" class="poster-pic" id="poster-img" />
  37. <p class="save-txt" id="save-txt">长按保存海报图片</p>
  38. </div>
  39. </div>
  40. </div>
  41. </body>
  42. <style>
  43. *{
  44. margin: 0;
  45. padding: 0;
  46. }
  47. html,body{
  48. width: 100%;
  49. height: 100%;
  50. }
  51. .wrapper{
  52. width: 100%;
  53. height: 100%;
  54. position: relative;
  55. }
  56. .swiper-container{
  57. width: 100%;
  58. height: 100%;
  59. --swiper-theme-color: #ebedf0;
  60. --swiper-pagination-color: #fff;/* 两种都可以 */
  61. }
  62. .swiper-container-horizontal>.swiper-pagination-bullets, .swiper-pagination-custom, .swiper-pagination-fraction{
  63. bottom: 140px;
  64. }
  65. .poster-con{
  66. position: relative;
  67. width: 100%;
  68. height: 100%;
  69. background-color: #fff;
  70. display: flex;
  71. align-items: center;
  72. }
  73. .qrcode{
  74. position: absolute;
  75. bottom: 5%;
  76. right: 20px;
  77. margin-left: -64px;
  78. border: 5px solid #fff;
  79. }
  80. .poster-pic{
  81. display: block;
  82. width: 100%;
  83. }
  84. .footer-box{
  85. position: absolute;
  86. bottom: 0;
  87. left: 0;
  88. width: 100%;
  89. text-align: center;
  90. z-index: 1;
  91. }
  92. .footer-box > .download{
  93. background-color: #ededed;
  94. padding: 3% 0;
  95. }
  96. .download > img{
  97. display: inline-block;
  98. width: 40px;
  99. margin-bottom: 4px;
  100. }
  101. .download > p{
  102. margin: 0;
  103. font-size: 13px;
  104. }
  105. .footer-box > .cancel-btn{
  106. background-color: #fff;
  107. margin: 0;
  108. padding: 2% 0;
  109. }
  110. /*弹框样式*/
  111. .zy-h5-fix-z{
  112. width: 100%;
  113. height: 100%;
  114. position: fixed;
  115. top: 0;
  116. left: 0;
  117. background: rgba(0,0,0,0.5);
  118. display: none;
  119. z-index: 5000;
  120. }
  121. .zy-h5-modal{
  122. background: #fff;
  123. border-radius: 5px;
  124. overflow: hidden;
  125. position: fixed;
  126. z-index: 10000;
  127. width: 70%;
  128. top: 30%;
  129. left: 50%;
  130. margin-left: -35%;
  131. margin-top: -140px;
  132. border: 1px solid #eee;
  133. display: none;
  134. }
  135. .save-txt{
  136. font-size: 12px;
  137. text-align: center;
  138. line-height: 36px;
  139. }
  140. </style>
  141. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  142. <script src="https://unpkg.com/swiper/js/swiper.js"> </script>
  143. <script src="https://unpkg.com/swiper/js/swiper.min.js"> </script>
  144. <!-- 生成二维码 -->
  145. <script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
  146. <!-- html转canvas base64图片 -->
  147. <script src="https://cdn.bootcdn.net/ajax/libs/html2canvas/0.5.0-beta3/html2canvas.min.js"></script>
  148. <script>
  149. function getQueryVariable(variable)
  150. {
  151. var query = window.location.search.substring(1);
  152. var vars = query.split("&");
  153. for (var i=0;i<vars.length;i++) {
  154. var pair = vars[i].split("=");
  155. if(pair[0] == variable){return pair[1];}
  156. }
  157. return(false);
  158. }
  159. var bitmap = null;
  160. if(window.plus){
  161. plusReady();
  162. }else{
  163. document.addEventListener("plusready",plusReady,false);
  164. }
  165. function plusReady(){
  166. bitmap = new plus.nativeObj.Bitmap();
  167. document.getElementById("save-txt").display = "none"
  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. var acitveId = getQueryVariable("id")
  192. var reqUrl = getQueryVariable("reqUrl")
  193. window.onclose = function(){
  194. bitmap.clear()
  195. }
  196. window.onload = function(){
  197. // swiper当前下标
  198. var swiperInd = 0
  199. // 获取活动信息 (海报和门店二维码)
  200. $.ajax({
  201. url: reqUrl + 'active/findActiveAttach/' + acitveId,
  202. type: 'get',
  203. header: {
  204. contentType: 'application/json;charset=UTF-8',
  205. },
  206. // 设置的是请求参数
  207. data: {},
  208. dataType: 'json',
  209. success: function (res) {
  210. if(res.status == 200){
  211. const data = res.data
  212. if(data.activeAttachList){
  213. let html = ''
  214. for(let i = 0; i < data.activeAttachList.length; i++){
  215. html += `<div class="swiper-slide">
  216. <div class="poster-con" id="poster-con${i}">
  217. <div class="qrcode" id="qrcode${i}"></div>
  218. <img src="${data.activeAttachList[i].attachPath}" class="poster-pic" style="pointer-events: none;" />
  219. </div>
  220. </div>`
  221. }
  222. document.getElementById("swiper-wrapper").innerHTML = html
  223. for(let i = 0; i < data.activeAttachList.length; i++){
  224. // 生成二维码
  225. new QRCode(document.getElementById("qrcode" + i ), {
  226. text: data.staticHtmlPath,
  227. width: 100,
  228. height: 100,
  229. colorDark : "#000000",
  230. colorLight : "#ffffff",
  231. correctLevel : QRCode.CorrectLevel.H
  232. })
  233. }
  234. // swiper
  235. var mySwiper = new Swiper ('.swiper-container', {
  236. // loop: true, // 循环模式选项
  237. // 如果需要分页器
  238. pagination: {
  239. el: '.swiper-pagination',
  240. },
  241. on: {
  242. slideChange: function(){
  243. swiperInd = this.activeIndex
  244. },
  245. }
  246. })
  247. // 打开 海报弹框
  248. document.getElementById("use-item").onclick = function(){
  249. // 合并图片和二维码
  250. html2canvas(document.getElementById('poster-con' + swiperInd), {
  251. backgroundColor: "transparent",
  252. allowTaint: true,
  253. useCORS: true
  254. }).then(canvas => {
  255. let dataURL = canvas.toDataURL("image/png")
  256. document.getElementById('poster-img').src = dataURL
  257. if (dataURL !== "") {
  258. // 打开弹框
  259. document.getElementById("zy-h5-modal").style.display = 'block'
  260. document.getElementById("zy-h5-fix-z").style.display = 'block'
  261. // 保存到相册
  262. savePhoto(dataURL)
  263. }else{
  264. alert('海报生成失败,请重试')
  265. }
  266. })
  267. }
  268. document.getElementById("zy-h5-fix-z").onclick = function(){
  269. document.getElementById("zy-h5-modal").style.display = 'none'
  270. document.getElementById("zy-h5-fix-z").style.display = 'none'
  271. }
  272. // 取消
  273. document.getElementById('cancel-btn').onclick = function(){
  274. history.go(-1)
  275. }
  276. }
  277. }else{
  278. alert(res.message)
  279. }
  280. }
  281. })
  282. }
  283. </script>
  284. </html>