poster.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. }
  168. // 保存到相册
  169. function savePhoto(dataURL){
  170. if(window.plus){
  171. // 加载海报图片
  172. bitmap.loadBase64Data(dataURL, function() {
  173. var itemId = new Date().getTime()
  174. //保存到系统相册
  175. bitmap.save("_doc/poster_"+itemId+".jpg", {
  176. overwrite: true, //是否覆盖已有图片, true 是
  177. quality: 100 //图片质量,1-100 默认50, 100质量最高
  178. }, function(e) {
  179. plus.gallery.save(e.target, function () {
  180. alert( "保存图片到相册成功" );
  181. });
  182. }, function(e) {
  183. alert("图片保存失败")
  184. });
  185. }, function(e) {
  186. alert("图片保存失败")
  187. });
  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. if(window.plus){
  276. uni.navigateBack()
  277. }
  278. }
  279. }
  280. }else{
  281. alert(res.message)
  282. }
  283. }
  284. })
  285. }
  286. </script>
  287. </html>