Ei kuvausta

index.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //获取地址栏参数
  2. function parseQueryString(url) {
  3. var urlObj = {};
  4. var reg = /([^?=&]+)=([^?=&]+)/g;
  5. url.replace(reg, ($0, $1, $2) => {
  6. urlObj[$1] = decodeURIComponent($2);
  7. })
  8. return urlObj;
  9. }
  10. var qs = parseQueryString(window.location.href);
  11. var tkl = '';
  12. var serverTime = 1000; //服务器时间,毫秒数
  13. $().ready(function() {
  14. todayTbkPassword()
  15. writeLogH5({'action':qs.appName,channel:'H5',url:window.location.href});//H5页面埋点
  16. })
  17. //获取淘口令
  18. function todayTbkPassword () {
  19. $.ajax({
  20. type:"post",
  21. url:"/api/v2/goods/tbkPassWordToActive",
  22. typeData:'json',
  23. success: function (res){
  24. if(res && res.errno == 0){
  25. if(res.rst.password){
  26. tkl = res.rst.password;
  27. }
  28. }
  29. $("#taokouling").text(tkl);
  30. count_down('2018-10-20 00:00:00');
  31. }
  32. });
  33. }
  34. function copyPassword() {
  35. var data=document.getElementById("taokouling").innerHTML;
  36. copy_2.innerHTML = data;
  37. copy_1.value = data;
  38. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  39. //区分iPhone设备
  40. window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
  41. var Url2=document.getElementById("copy_2");//要复制文字的节点
  42. var range = document.createRange();
  43. // 选中需要复制的节点
  44. range.selectNode(Url2);
  45. // 执行选中元素
  46. window.getSelection().addRange(range);
  47. // 执行 copy 操作
  48. var successful = document.execCommand('copy');
  49. // 移除选中的元素
  50. window.getSelection().removeAllRanges();
  51. }else{
  52. var Url2=document.getElementById("copy_1");//要复制文字的节点
  53. Url2.select(); // 选择对象
  54. document.execCommand("Copy"); // 执行浏览器复制命令
  55. }
  56. showMsg('口令复制成功,打开淘宝领取吧!')
  57. }
  58. //提示弹框
  59. function showMsg(msg) {
  60. var msgBox = $('.alert-info');
  61. msgBox.children('p').text(msg);
  62. msgBox.show();
  63. setTimeout(function() {
  64. msgBox.hide();
  65. }, 3000);
  66. }
  67. //倒计时
  68. function count_down(o){
  69. var html = null;//页面
  70. var time = null;
  71. time = setTimeout(function(){count_down(o)},1000);
  72. var datatime=/^[\d]{4}-[\d]{1,2}-[\d]{1,2}( [\d]{1,2}:[\d]{1,2}(:[\d]{1,2})?)?$/ig,str='',conn,s;
  73. if(!o.match(datatime)){
  74. // alert('参数格式为2020-01-01[ 01:01[:01]].\r其中[]内的内容可省略');
  75. return false;
  76. }
  77. var sec=(new Date(o.replace(/-/ig,'/')).getTime() - new Date().getTime())/1000;
  78. // if(sec > 0){
  79. // conn='';
  80. // }else{
  81. // conn='已过去';
  82. // sec*=-1;
  83. // }
  84. if(sec == 0 || sec < 0){
  85. //倒计时结束时----都为0
  86. html = `<img class="img" src="https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/chaojihongbao/yure_hongbao.png" />`
  87. $('.daojishi').html(html);
  88. $(".button").addClass('buttonActive');
  89. $(".button").click(function () {
  90. copyPassword();
  91. })
  92. clearTimeout(time);
  93. }else{
  94. s={'天':sec/24/3600,'时':Math.floor(sec/3600%24),'分':Math.floor(sec/60%60),'秒':Math.floor(sec%60)};
  95. for(i in s){
  96. if(s[i] < 10){s[i] = '0' + s[i]};
  97. if(i != '天'){
  98. str += '<span>' + s[i] + '</span>' + i;
  99. }
  100. }
  101. html = `<div class="count_down"><img src="https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/chaojihongbao/daojishi.png" alt="" /></div>
  102. <div id="endtime">${str}</div>`;
  103. $('.daojishi').html(html);
  104. $(".button").removeClass('buttonActive');
  105. $(".button").click(function () {
  106. showMsg('今晚0点再来领取哦~')
  107. })
  108. }
  109. }
  110. //H5页面埋点
  111. function writeLogH5 (data) {
  112. $.ajax({
  113. type:'post',
  114. url:'/api/v2/channel/writeLogH5',
  115. dataType:'json',
  116. data:data,
  117. success:function (res) {
  118. // console.log(res)
  119. }
  120. })
  121. }