jump.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <html>
  2. <head>
  3. <title>打开小程序</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
  6. <script>
  7. function docReady(fn) {
  8. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  9. fn()
  10. } else {
  11. document.addEventListener('DOMContentLoaded', fn);
  12. }
  13. }
  14. docReady(async function () {
  15. var ua = navigator.userAgent.toLowerCase()
  16. var isWXWork = ua.match(/wxwork/i) == 'wxwork'
  17. var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
  18. var isMobile = false
  19. var isDesktop = false
  20. if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
  21. isMobile = true
  22. } else {
  23. isDesktop = true
  24. }
  25. var container = document.getElementById('container')
  26. var wx = document.getElementById('container-wx')
  27. var tip = document.getElementById('container-tip')
  28. if (isWeixin) {
  29. container.innerHTML = '打开微信小程序'
  30. tip.innerHTML = '点击以下按钮打开 “盲票小程序”'
  31. wx.style.display = "none";
  32. } else {
  33. container.style.display = "none";
  34. wx.style.display = "inline";
  35. wx.innerHTML = '打开微信'
  36. tip.innerHTML = '请使用微信扫描当前二维码'
  37. }
  38. })
  39. //获取当前URL
  40. var url = document.location.href;
  41. //声明一个对象
  42. var getRequest = new Object();
  43. //获取?的位置
  44. var index = url.indexOf("?")
  45. if (index != -1) {
  46. //截取出?后面的字符串
  47. var str = url.substr(index + 1);
  48. //将截取出来的字符串按照&变成数组
  49. strs = str.split("&");
  50. //将get传参存入对象中
  51. for (var i = 0; i < strs.length; i++) {
  52. getRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  53. }
  54. }
  55. console.log('getRequest', getRequest)
  56. function ajax(options) {
  57. return new Promise((resolve, reject) => {
  58. if (!options.url) {
  59. return;
  60. }
  61. let method = options.method || 'GET';
  62. let async = options.async || true;
  63. let xhr = new XMLHttpRequest();
  64. if (method === 'GET') {
  65. // url后面添加随机数防止请求缓存
  66. xhr.open(method, options.url + "?" + Math.random(), async);
  67. xhr.send(null);
  68. } else if (method === 'POST') {
  69. xhr.open(method, options.url, async);
  70. xhr.setRequestHeader('Content-type', 'application/json;charset=utf-8');
  71. xhr.send(JSON.stringify(options.data));
  72. }
  73. xhr.onreadystatechange = () => {
  74. if (xhr.responseText) {
  75. resolve(xhr.responseText);
  76. }
  77. };
  78. xhr.onerror = (e) => {
  79. reject(e);
  80. }
  81. }).catch(e => {
  82. });
  83. }
  84. function openWeapp() {
  85. let req = ajax({
  86. method: 'POST',
  87. url: 'https://test-mp-adm.quanshu123.com/test-api/api/v1/mp/wx/urlschema/generate',
  88. data: {
  89. path: '/pages/bills/detail',
  90. query: `id=${ getRequest.id }`
  91. }
  92. })
  93. req.then(data => {
  94. let resData = JSON.parse(data)
  95. if(resData.code == 0){
  96. window.location.href = resData.data;
  97. }
  98. })
  99. }
  100. function openWx() {
  101. window.location.href = "weixin://";
  102. }
  103. </script>
  104. <style>
  105. .skip-wrap {
  106. width: 100%;
  107. height: 100%;
  108. position: relative;
  109. }
  110. .skip-theme {
  111. display: flex;
  112. align-items: center;
  113. flex-direction: column;
  114. padding: 200px 0 0;
  115. }
  116. .skip-theme-iamge {
  117. width: 60px;
  118. height: 60px;
  119. line-height: 60px;
  120. text-align: center;
  121. color: #fff;
  122. background-color: #e96737;
  123. border-radius: 50%;
  124. margin-bottom: 10px;
  125. }
  126. .skip-theme-txt {
  127. color: rgb(194, 184, 184);
  128. text-align: center;
  129. }
  130. .skip-btn {
  131. position: absolute;
  132. bottom: 50px;
  133. width: 100%;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. }
  138. .skip-btn p {
  139. height: 30px;
  140. width: 200px;
  141. background-color: rgb(7, 192, 88);
  142. border-radius: 8px;
  143. line-height: 30px;
  144. color: #fff;
  145. text-align: center;
  146. }
  147. </style>
  148. </head>
  149. <body>
  150. <div class="skip-wrap">
  151. <div class="skip-theme" id="container-tip"></div>
  152. <div class="skip-btn">
  153. <p onclick="openWeapp()" id="container"></p>
  154. <p onclick="openWeapp()" id="container-wx"></p>
  155. </div>
  156. </div>
  157. </body>
  158. </html>