海鲜小程序

index.html 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta content="yes" name="apple-mobile-web-app-capable">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,minimum-scale=1.0,user-scalable=0" />
  7. <title>海鲜阿嫂</title>
  8. <link rel="stylesheet" href="../public/public_css.css">
  9. <script src="../public/jquery-2.1.0.js"></script>
  10. <script src="../public/html2canvas.js"></script>
  11. <script type="text/javascript">
  12. document.documentElement.style.fontSize = 100 * (document.documentElement.clientWidth/375) + "px";
  13. window.onresize = function(){
  14. document.documentElement.style.fontSize = 100 * (document.documentElement.clientWidth/375) + "px";
  15. }
  16. </script>
  17. <style>
  18. #curTpl{
  19. display: none;
  20. }
  21. #leaveImg{
  22. position: relative;
  23. display: none;
  24. }
  25. .applet_evm{
  26. position: absolute;
  27. top: 2.6rem;
  28. left: 0;
  29. right: 0;
  30. margin: auto;
  31. width: 1.7rem;
  32. }
  33. .seafood{
  34. font-size: 0.12rem;
  35. text-align: center;
  36. color: #666;
  37. }
  38. .seafood input{
  39. border: 0.01rem solid #999999;
  40. font-size: 0.14rem;
  41. padding-left: 0.1rem;
  42. border-radius: 0.05rem;
  43. height: 0.3rem;
  44. background: transparent;
  45. }
  46. .seafood label{
  47. display: inline-block;
  48. width: 0.9rem;
  49. text-align: right;
  50. }
  51. .content{
  52. border-bottom: 0.01rem solid #ccc;
  53. }
  54. .content .title{
  55. font-size: 0.18rem;
  56. font-weight: bold;
  57. text-align: center;
  58. padding-top: 0.4rem;
  59. padding-bottom: 0.5rem;
  60. }
  61. .buttonDiv{
  62. width: 100%;
  63. display: flex;
  64. align-items: center;
  65. justify-content: space-around;
  66. margin: 0.8rem auto;
  67. }
  68. .seafoodButton{
  69. color: #ffffff;
  70. background: #5eb95e;
  71. border: none;
  72. width: 1.6rem;
  73. height: 0.4rem;
  74. border-radius: 0.4rem;
  75. font-size: 0.15rem;
  76. }
  77. #evmImg{
  78. display: none
  79. }
  80. #evmImg .evm2{
  81. width: 80%;
  82. margin: 0.6rem auto 0.2rem;
  83. }
  84. #evmImg .hint{
  85. text-align: center;
  86. font-size: 0.14rem;
  87. color: #666;
  88. }
  89. </style>
  90. </head>
  91. <body>
  92. <div class="content">
  93. <div class="title">生成直播间二维码</div>
  94. <div class="seafood">
  95. <label>海鲜销售账号:</label>
  96. <input type="text" id="accountNumber" placeholder="请输入海鲜销售账号">
  97. </div>
  98. <div class="seafood" style="margin-top: 0.2rem;">
  99. <label>直播间房间号:</label>
  100. <input type="number" id="liveNum" placeholder="请输入直播间房间号">
  101. </div>
  102. <div class="buttonDiv">
  103. <button onclick="createQrcode('evm')" class="seafoodButton">点击生成二维码</button>
  104. </div>
  105. </div>
  106. <div class="content">
  107. <div class="title">生成活动二维码</div>
  108. <div class="seafood">
  109. <label>海鲜销售账号:</label>
  110. <input type="text" id="activity_accountNumber" placeholder="请输入海鲜销售账号">
  111. </div>
  112. <div class="seafood" style="margin-top: 0.2rem;">
  113. <label>活动ID:</label>
  114. <input type="number" disabled value="1" placeholder="请输入直播间房间号">
  115. </div>
  116. <div class="buttonDiv">
  117. <button onclick="createQrcode('activity_evm')" class="seafoodButton">点击生成二维码</button>
  118. </div>
  119. </div>
  120. <div id="evmImg">
  121. <img src="" class="evm2" alt="">
  122. <p class="hint">长按二维码分享</p>
  123. </div>
  124. <div id="leaveImg">
  125. <img src="./img/bgImg.png" alt="" style="width: 100%;">
  126. <img class="applet_evm" src="" alt="">
  127. </div>
  128. <img src="" id="curTpl" style=" display: none;width:100%">
  129. <div class="alert-info" style="display: none;">
  130. <!-- tip提示,3s后消失 -->
  131. <p>请在浏览器中打开</p>
  132. </div>
  133. <!-- loading -->
  134. <div class="loading">
  135. <img src="../public/loading.gif" />
  136. </div>
  137. </body>
  138. </html>
  139. <script>
  140. $().ready(function() {
  141. })
  142. function generateImg (){//生成图片
  143. var dom=$("#leaveImg"); //你要转变的dom
  144. var width = dom.width();
  145. var height = dom.height();
  146. var scaleBy = 5; //缩放比例
  147. var canvas = document.createElement('canvas');
  148. canvas.width = width * scaleBy;
  149. canvas.height = height * scaleBy;
  150. canvas.style.width = width * scaleBy + 'px';
  151. canvas.style.height = height * scaleBy + 'px';
  152. var context = canvas.getContext('2d');
  153. context.scale(scaleBy, scaleBy);
  154. html2canvas(dom, {
  155. // logging: false, //日志开关
  156. // useOverflow: true,
  157. useCORS: true,
  158. canvas:canvas,
  159. onrendered: function (canvas) {
  160. var url = canvas.toDataURL();//图片地址
  161. $(".loading").hide()
  162. $("#curTpl").attr('src',url)
  163. $("#curTpl").css("display","block")
  164. $("#leaveImg").css({
  165. "display":"none",
  166. "z-index":"-11"
  167. });
  168. showMsg('长按分享图片')
  169. }
  170. });
  171. }
  172. function createQrcode(create_type){//生成二维码
  173. var data = {};
  174. if(create_type == 'evm'){
  175. if(($('#accountNumber').val()).replace(/(^\s*)|(\s*$)/g, "") == ''){
  176. showMsg('请输入海鲜销售账号')
  177. return
  178. }
  179. if(($('#liveNum').val()).replace(/(^\s*)|(\s*$)/g, "") == ''){
  180. showMsg('请输入直播间房间号')
  181. return
  182. }
  183. data = {
  184. account:($('#accountNumber').val()).replace(/(^\s*)|(\s*$)/g, ""),
  185. scene:'room_id='+($('#liveNum').val()).replace(/(^\s*)|(\s*$)/g, ""),
  186. page:'pages/index/index'
  187. }
  188. }
  189. if(create_type == 'activity_evm'){
  190. if(($('#activity_accountNumber').val()).replace(/(^\s*)|(\s*$)/g, "") == ''){
  191. showMsg('请输入海鲜销售账号')
  192. return
  193. }
  194. data = {
  195. account:($('#activity_accountNumber').val()).replace(/(^\s*)|(\s*$)/g, ""),
  196. page:'pages/activity/selfHelpActivity/index',
  197. scene:'activity_id=1'
  198. }
  199. }
  200. $(".loading").show()
  201. $.ajax({
  202. type:"post",
  203. url:"/api/wx/createQrcode",
  204. dataType:"json",
  205. data:data,
  206. success: function (res) {
  207. $(".loading").hide()
  208. if(res && res.errno == 200){
  209. $(".content").hide()
  210. $("#evmImg").show();
  211. $(".evm2").attr('src',res.rst.qrcode)
  212. // if(create_type == 'evm'){
  213. // $(".content").hide()
  214. // $("#evmImg").show();
  215. // $(".evm2").attr('src',res.rst.qrcode)
  216. // }
  217. // else{
  218. // $(".applet_evm").attr('src',res.rst.qrcode)
  219. // $('.applet_evm').each(function() {
  220. // $(this).load(function(){
  221. // $(".content").hide()
  222. // $("#leaveImg").show()
  223. // $(".loading").show()
  224. // generateImg()
  225. // });
  226. // });
  227. // }
  228. }else{
  229. showMsg(res.err)
  230. }
  231. },
  232. error:function(err){
  233. $(".loading").hide()
  234. showMsg('服务器错误,请稍后')
  235. }
  236. })
  237. }
  238. // 展示错误提示信息
  239. function showMsg(msg) {
  240. var msgBox = document.getElementsByClassName('alert-info')[0];
  241. msgBox.getElementsByTagName("p")[0].innerHTML=msg;
  242. msgBox.style.display="block";
  243. setTimeout(function() {
  244. msgBox.style.display="none";
  245. }, 2000);
  246. }
  247. //获取地址栏参数
  248. function parseQueryString(url) {
  249. var urlObj = {};
  250. var reg = /([^?=&]+)=([^?=&]+)/g;
  251. url.replace(reg, function($0, $1, $2) {
  252. urlObj[$1] = decodeURIComponent($2);
  253. })
  254. return urlObj;
  255. }
  256. </script>