20190512.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>妈妈的三行情书</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" type="text/css" href="css/mui.min.css" />
  10. <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  11. <link rel="stylesheet" type="text/css" href="css/style.css" />
  12. <style>
  13. /*loading*/
  14. .loading{width: 100%;height:100%;position: fixed;top: 0;padding-top: 50%; left: 0;background: rgba(0,0,0,0.8);z-index: 999;}
  15. .loading-bj{background: url(images/loading.png);width: 20px;height: 20px;background-size: 20px;margin: 0.3rem auto 0;animation:rotateIn 1s .2s linear infinite;-moz-animation:rotateIn 1s .2s linear infinite;-webkit-animation:rotateIn 1s .2s linear infinite;}
  16. .loading p{color:#fff;opacity: .7; font-size: 12px;text-align: center;margin-top: 0.1rem;}
  17. .message-box {position: relative;}
  18. .message-box.box-shadow{padding: 15px;background: #f9e6ec;}
  19. .message-box>img {width: 100%;}
  20. #textarea {position: absolute;top: 38%;width: 58%;left: 21%;line-height: 2.2;padding: 0 1%;border: 0;margin-bottom: 0; background-color: transparent;font-size: 1rem;word-break: break-all;overflow: hidden;}
  21. #textarea::-webkit-input-placeholder {color: #ccc;font-size: 0.8rem;}
  22. .user-middle {position: absolute;left: 16%;top: 7.6%;width: 84%;text-align: left;}
  23. .message-box .user-middle img {width: 18%;display: block;}
  24. .message-box .user-name {overflow: hidden;white-space: nowrap;font-size: 1rem;}
  25. .my-btn-save {background: #dd6a8c;color: #fff;width: 200px;height: 50px;border: 0;line-height: 50px;border-radius: 50px;top: 0 !important; padding:0 12px !important; font-size: 1rem;display: none;}
  26. .my-btn-save:active {color: #fff;}
  27. .my-nav-l {position: absolute;left: 0;top: 22.4%;width: 15%;background: rgba(255,255,255,.7);padding:1rem .5rem;}
  28. .my-nav-l>li {border: 2px solid transparent;border-radius: 5px;overflow: hidden;margin: 1px 0;}
  29. .my-nav-l>li.active {border: 2px solid #dd6a8c;}
  30. .my-nav-l>li img {width: 100%;display: block;}
  31. .btn-nav {position: absolute;left: 4%;top: 73%;color: #dd6a8c;}
  32. .txt-tips{text-align: right;position: absolute;top: 65%;right:20%;font-size: .8rem;}
  33. </style>
  34. <script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
  35. <script>
  36. //屏蔽分享
  37. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  38. WeixinJSBridge.call('hideOptionMenu');
  39. });
  40. </script>
  41. </head>
  42. <body style="background: #fff;">
  43. <div class="loading covers">
  44. <div class="loading-bj"></div>
  45. <p>正在加载...</p>
  46. </div>
  47. <div class="mui-content" style="background: #fff;">
  48. <div class="message-box">
  49. <img id="bg-p" src="images/2019050703.jpg" />
  50. <div class="user-middle">
  51. <div class="user-head">
  52. <!--头像-->
  53. <img id="headDiv" src="https://img.zcool.cn/community/01460b57e4a6fa0000012e7ed75e83.png@1280w_1l_2o_100sh.webp">
  54. </div>
  55. <div class="user-name" id="userNickname"></div>
  56. </div>
  57. <div class="btn-nav">
  58. <span class="iconfont icon-shouqi"></span>
  59. </div>
  60. <ul class="my-nav-l">
  61. <li name="1">
  62. <img src="images/2019050701.png" />
  63. </li>
  64. <li name="2">
  65. <img src="images/2019050702.png" />
  66. </li>
  67. <li name="3" class="active">
  68. <img src="images/2019050703.png" />
  69. </li>
  70. <li name="4">
  71. <img src="images/2019050704.png" />
  72. </li>
  73. <li name="5">
  74. <img src="images/2019050705.png" />
  75. </li>
  76. </ul>
  77. <textarea placeholder="“当我变成了你的那天,你的付出,我才终于懂了”" rows="4" maxlength="104" id="textarea"></textarea>
  78. <div class="txt-tips">还可输入52字</div>
  79. </div>
  80. </div>
  81. <nav class="mui-bar mui-bar-tab mui-text-center" style="background: transparent;border: 0;box-shadow: 0 0 0 0;height: 65px;">
  82. <button class="mui-btn my-btn-save">生成专属情书</button>
  83. </nav>
  84. <script src="js/mui.min.js"></script>
  85. <script src="js/jquery-2.1.1.min.js"></script>
  86. <script src="js/main.js"></script>
  87. </body>
  88. <script>
  89. //ajax loading
  90. $(window).ajaxStart(function(){
  91. $(".covers").show();
  92. });
  93. $(window).ajaxStop(function(){
  94. $(".covers").hide();
  95. });
  96. $(document).on('tap', '.btn-nav', function() {
  97. if($(this).find(".icon-zhankai").length > 0) {
  98. $(this).html('<span class="iconfont icon-shouqi"></span>');
  99. $(".my-nav-l").show();
  100. } else {
  101. $(this).html('<span class="iconfont icon-zhankai"></span>');
  102. $(".my-nav-l").hide();
  103. }
  104. });
  105. $(document).on('tap', '.my-nav-l>li', function() {
  106. $(this).addClass("active").siblings().removeClass("active");
  107. $("#bg-p").prop("src", 'images/201905070' + $(this).attr("name") + '.jpg');
  108. });
  109. //保存
  110. $(document).on('tap', '.my-btn-save', function() {
  111. var texts = $("#textarea").val(),
  112. bg = $(".my-nav-l .active").attr("name");
  113. if(!/^[A-Za-z0-9_\[\]\【\】\{\}\{\}\(\)\(\)\《\》\<\>\,\,/\s\.\`\。\、\!\!\~\·\@\#\¥\$\%\^\…\&\—\/\_\:\:\;\;\‘\’\'\'\"\"\“\”\?\?\-\=\|\*\+\-\u4e00-\u9fa5]{1,104}$/.test(texts)) {
  114. if($("#textarea").val().replace(/[ \r\n]/g, "") == '') {
  115. mui.alert("请填写文字,不能全部为空!");
  116. } else {
  117. mui.alert("仅支持中文、英文、数字、标点符号!");
  118. }
  119. } else {
  120. if($("#textarea").val().replace(/[ \r\n]/g, "") == '') {
  121. mui.alert("请填写文字,不能全部为空!");
  122. } else {
  123. if(strlen(texts) > 104) {
  124. mui.alert("文字长度不能超过52个!");
  125. } else {
  126. var btnArray = ['取消', '确认'];
  127. mui.confirm('每个ID仅限参与一次,请再次确认', '温馨提示', btnArray, function(e) {
  128. if (e.index == 1) {
  129. $(".covers p").text("生成中,请稍候...");
  130. $(".loading").css("opacity", "1").show();
  131. $.ajax(base_path + '/moth_movable/save_movable?dates=' + new Date().getTime(), {
  132. data: {
  133. mothMovaText: texts,
  134. mothMovaBackType: bg
  135. },
  136. dataType: 'json',
  137. xhrFields: {
  138. withCredentials: true
  139. },
  140. crossDomain: true,
  141. type: 'post',
  142. async: false,
  143. timeout: 15000,
  144. success: function(dt) {
  145. if(dt.isRedirect) {
  146. location.href = dt.redirectURL;
  147. } else {
  148. console.log(dt)
  149. if(dt.resultCode == "200") {
  150. $(".loading").hide().css("opacity", "0");
  151. location.reload();
  152. } else {
  153. $(".loading").hide().css("opacity", "0");
  154. mui.alert(dt.message);
  155. }
  156. }
  157. },
  158. error: function(xhr, type, errorThrown) {
  159. console.log(xhr);
  160. $(".loading").hide().css("opacity", "0");
  161. mui.alert("保存数据失败!网络错误");
  162. }
  163. });
  164. } else {
  165. //取消
  166. $(".loading").hide().css("opacity", "0");
  167. }
  168. })
  169. }
  170. }
  171. }
  172. });
  173. //用中文分号替换英文分号、中英文逗号或者回车
  174. function ReplaceSeperator(mobiles) {
  175. var i;
  176. var result = "";
  177. var c;
  178. for(i = 0; i < mobiles.length; i++) {
  179. c = mobiles.substr(i, 1);
  180. if(c == ";" || c == "," || c == "," || c == "\n")
  181. result = result + "\n";
  182. else if(c != "\r")
  183. result = result + c;
  184. }
  185. return result;
  186. }
  187. function strlen(str) {
  188. var len = 0;
  189. for(var i = 0; i < str.length; i++) {
  190. var c = str.charCodeAt(i);
  191. //单字节加1
  192. if((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
  193. len++;
  194. } else {
  195. len += 2;
  196. }
  197. }
  198. return len;
  199. }
  200. //实时监听文本框字数
  201. document.getElementById("textarea").addEventListener("input", function() {
  202. if(strlen(this.value) > 0) {
  203. $(".my-btn-save").show();
  204. if(strlen(this.value)<=104){
  205. $('.txt-tips').css("color","#333").text('还可输入'+parseInt((104-strlen(this.value))/2)+'字');
  206. }else{
  207. $('.txt-tips').css("color","#f00").text('超出'+parseInt((strlen(this.value)-104)/2)+'字');
  208. }
  209. //mui.alert("字符长度不能超过104字节!");
  210. }else{
  211. $(".my-btn-save").hide();
  212. }
  213. });
  214. function get_moth(){
  215. $.ajax(base_path + '/moth_movable/get_moth?dates=' + new Date().getTime(), {
  216. data: {},
  217. dataType: 'json',
  218. xhrFields: {
  219. withCredentials: true
  220. },
  221. crossDomain: true,
  222. type: 'post',
  223. async: false,
  224. timeout: 15000,
  225. success: function(dt) {
  226. if(dt.isRedirect) {
  227. location.href = dt.redirectURL;
  228. } else {
  229. if(dt.resultCode == "200") {
  230. if(dt.status) {
  231. $("body").css("background","#f9e6ec");
  232. $(".message-box").addClass("box-shadow").html('<img src="http://w.iamberry.com/watero/' + dt.data.mothMovaImgUrl + '"><div class="mui-text-center mui-content-padded" style="color: #da4b79;">长按图片保存分享</div><h6 class="mui-text-center">在法律许可范围内本次活动最终解释权归爱贝源所有</h6>');
  233. }
  234. } else {
  235. if(dt.status == false) {
  236. $("#headDiv").prop('src', dt.data.userHead);
  237. $("#userNickname").text(decodeURI(dt.data.userNickname));
  238. }
  239. }
  240. }
  241. },
  242. error: function(xhr, type, errorThrown) {
  243. console.log(xhr);
  244. mui.alert("读取数据失败!网络错误");
  245. }
  246. });
  247. }
  248. mui.ready(function() {
  249. $("#textarea").css({
  250. "font-size": ".95rem",
  251. "line-height": $("#textarea").width() / 7.0 + "px"
  252. });
  253. get_moth();
  254. $(".loading").hide().css("opacity", "0"); //隐藏(正在加载...)
  255. });
  256. </script>
  257. </html>