posterQbyc.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. position: relative;
  52. }
  53. .swiper-container{
  54. width: 100%;
  55. height: 100%;
  56. --swiper-theme-color: #ebedf0;
  57. --swiper-pagination-color: #fff;/* 两种都可以 */
  58. }
  59. .swiper-container-horizontal>.swiper-pagination-bullets, .swiper-pagination-custom, .swiper-pagination-fraction{
  60. bottom: 140px;
  61. }
  62. .poster-con{
  63. position: relative;
  64. width: 100%;
  65. padding-bottom: 100px;
  66. background-color: #fff;
  67. }
  68. .qrcode{
  69. border: 5px solid #fff;
  70. position: absolute;
  71. right: 10px;
  72. bottom: 10px;
  73. z-index: 10000;
  74. }
  75. .poster-pic{
  76. display: block;
  77. width: 100%;
  78. }
  79. .footer-box{
  80. position: fixed;
  81. bottom: 0;
  82. left: 0;
  83. width: 100%;
  84. text-align: center;
  85. z-index: 1;
  86. }
  87. .footer-box > .download{
  88. background-color: #ededed;
  89. padding: 3% 0;
  90. }
  91. .download > img{
  92. display: inline-block;
  93. width: 40px;
  94. margin-bottom: 4px;
  95. }
  96. .download > p{
  97. margin: 0;
  98. font-size: 13px;
  99. }
  100. .footer-box > .cancel-btn{
  101. background-color: #fff;
  102. margin: 0;
  103. padding: 2% 0;
  104. }
  105. /*弹框样式*/
  106. .zy-h5-fix-z{
  107. width: 100%;
  108. height: 100%;
  109. position: fixed;
  110. top: 0;
  111. left: 0;
  112. background: rgba(0,0,0,0.5);
  113. display: none;
  114. z-index: 5000;
  115. }
  116. .zy-h5-modal{
  117. background: #fff;
  118. border-radius: 5px;
  119. overflow: hidden;
  120. position: fixed;
  121. z-index: 10000;
  122. width: 80%;
  123. top: 10%;
  124. left: 50%;
  125. margin-left: -40%;
  126. margin-top: -40px;
  127. border: 1px solid #eee;
  128. display: none;
  129. }
  130. .save-txt{
  131. font-size: 12px;
  132. text-align: center;
  133. line-height: 36px;
  134. }
  135. </style>
  136. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  137. <link rel="stylesheet" href="https://static.qiubcar.com/active/swiper.min.css">
  138. <script src="https://static.qiubcar.com/active/swiper.min.js"></script>
  139. <!-- 生成二维码 -->
  140. <script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
  141. <!-- html转canvas base64图片 -->
  142. <script src="https://static.qiubcar.com/active/html2canvas.js"></script>
  143. <script>
  144. function getQueryVariable(variable)
  145. {
  146. var query = window.location.search.substring(1);
  147. var vars = query.split("&");
  148. for (var i=0;i<vars.length;i++) {
  149. var pair = vars[i].split("=");
  150. if(pair[0] == variable){return pair[1];}
  151. }
  152. return(false);
  153. }
  154. // app 中点击保存图片到手机
  155. var bitmap = null;
  156. if(window.plus){
  157. plusReady();
  158. }else{
  159. document.addEventListener("plusready",plusReady,false);
  160. }
  161. function plusReady(){
  162. bitmap = new plus.nativeObj.Bitmap();
  163. document.getElementById("save-txt").display = "none"
  164. $("#cancel-btn").hide()
  165. }
  166. // 保存到相册
  167. function savePhoto(dataURL){
  168. if(window.plus){
  169. // 加载海报图片
  170. bitmap.loadBase64Data(dataURL, function() {
  171. var itemId = new Date().getTime()
  172. //保存到系统相册
  173. bitmap.save("_doc/poster_"+itemId+".jpg", {
  174. overwrite: true, //是否覆盖已有图片, true 是
  175. quality: 100 //图片质量,1-100 默认50, 100质量最高
  176. }, function(e) {
  177. plus.gallery.save(e.target, function () {
  178. alert( "保存图片到相册成功" );
  179. });
  180. }, function(e) {
  181. alert("图片保存失败")
  182. });
  183. }, function(e) {
  184. alert("图片保存失败")
  185. });
  186. }
  187. }
  188. // 加载海报
  189. var acitveId = getQueryVariable("id")
  190. var reqUrl = getQueryVariable("reqUrl")
  191. window.onclose = function(){
  192. bitmap.clear()
  193. }
  194. window.onload = function(){
  195. // swiper当前下标
  196. var swiperInd = 0
  197. // 获取活动信息 (海报和门店二维码)
  198. $.ajax({
  199. url: reqUrl + 'active/findActiveAttach/' + acitveId,
  200. type: 'get',
  201. header: {
  202. contentType: 'application/json;charset=UTF-8',
  203. },
  204. // 设置的是请求参数
  205. data: {},
  206. dataType: 'json',
  207. success: function (res) {
  208. if(res.status == 200){
  209. const data = res.data
  210. if(data.activeAttachList){
  211. var html = ''
  212. for(var i = 0; i < data.activeAttachList.length; i++){
  213. html += `<div class="swiper-slide">
  214. <div class="poster-con" id="poster-con${i}">
  215. <div class="qrcode" id="qrcode${i}"></div>
  216. <img src="${data.activeAttachList[i].attachPath}" class="poster-pic" style="pointer-events: none;" />
  217. </div>
  218. </div>`
  219. }
  220. document.getElementById("swiper-wrapper").innerHTML = html
  221. for(var i = 0; i < data.activeAttachList.length; i++){
  222. // 生成二维码
  223. new QRCode(document.getElementById("qrcode" + i ), {
  224. text: getQueryVariable("orgId") ? data.staticHtmlPath + '?orgId=' + getQueryVariable("orgId") : data.staticHtmlPath,
  225. width: 80,
  226. height: 80,
  227. colorDark : "#000000",
  228. colorLight : "#ffffff",
  229. correctLevel : QRCode.CorrectLevel.H
  230. })
  231. }
  232. // swiper
  233. var mySwiper = new Swiper ('.swiper-container', {
  234. // loop: true, // 循环模式选项
  235. // 如果需要分页器
  236. pagination: {
  237. el: '.swiper-pagination',
  238. },
  239. on: {
  240. slideChange: function(){
  241. swiperInd = this.activeIndex
  242. },
  243. }
  244. })
  245. // 打开 海报弹框
  246. document.getElementById("use-item").onclick = function(){
  247. var dom = document.getElementById('poster-con' + swiperInd)
  248. var width = dom.clientWidth
  249. var height = dom.clientHeight
  250. // 合并图片和二维码
  251. html2canvas(dom, {
  252. width:width,
  253. height:height,
  254. backgroundColor: "#ffffff",
  255. allowTaint: true,
  256. useCORS: true,
  257. scale: 2
  258. }).then(canvas => {
  259. var dataURL = canvas.toDataURL("image/png")
  260. document.getElementById('poster-img').src = dataURL
  261. if (dataURL !== "") {
  262. // 打开弹框
  263. document.getElementById("zy-h5-modal").style.display = 'block'
  264. document.getElementById("zy-h5-fix-z").style.display = 'block'
  265. // 保存到相册
  266. savePhoto(dataURL)
  267. }else{
  268. alert('海报生成失败,请重试')
  269. }
  270. })
  271. }
  272. document.getElementById("zy-h5-fix-z").onclick = function(){
  273. document.getElementById("zy-h5-modal").style.display = 'none'
  274. document.getElementById("zy-h5-fix-z").style.display = 'none'
  275. }
  276. // 取消
  277. document.getElementById('cancel-btn').onclick = function(){
  278. history.go(-1)
  279. }
  280. }
  281. }else{
  282. alert(res.message)
  283. }
  284. }
  285. })
  286. }
  287. </script>
  288. </html>