jump.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. function ajax(options) {
  40. return new Promise((resolve, reject) => {
  41. if (!options.url) {
  42. alert("确认你的url");
  43. return;
  44. }
  45. let method = options.method || 'GET';
  46. let async = options.async || true;
  47. let xhr = new XMLHttpRequest();
  48. if (method === 'GET') {
  49. // url后面添加随机数防止请求缓存
  50. xhr.open(method, options.url + "?" + Math.random(), async);
  51. xhr.send(null);
  52. } else if (method === 'POST') {
  53. xhr.open(method, options.url, async);
  54. xhr.setRequestHeader('Content-type', 'application/json;charset=utf-8');
  55. xhr.send(JSON.stringify(options.data));
  56. }
  57. xhr.onreadystatechange = () => {
  58. if (xhr.responseText) {
  59. resolve(xhr.responseText);
  60. }
  61. };
  62. xhr.onerror = (e) => {
  63. reject(e);
  64. }
  65. }).catch(e => {
  66. });
  67. }
  68. function openWeapp() {
  69. let req = ajax({
  70. method: 'POST',
  71. async: false,
  72. url: 'https://test-mp-adm.quanshu123.com/test-api/api/v1/mp/wx/urlschema/generate',
  73. data: {
  74. path: '/pages/index/index',
  75. query: 'id=3847838'
  76. }
  77. })
  78. req.then(data => {
  79. console.log(data)
  80. window.location.href = "weixin://";
  81. })
  82. }
  83. function openWx() {
  84. window.location.href = "weixin://";
  85. }
  86. </script>
  87. <style>
  88. .skip-wrap {
  89. width: 100%;
  90. height: 100%;
  91. position: relative;
  92. }
  93. .skip-theme {
  94. display: flex;
  95. align-items: center;
  96. flex-direction: column;
  97. padding: 200px 0 0;
  98. }
  99. .skip-theme-iamge {
  100. width: 60px;
  101. height: 60px;
  102. line-height: 60px;
  103. text-align: center;
  104. color: #fff;
  105. background-color: #e96737;
  106. border-radius: 50%;
  107. margin-bottom: 10px;
  108. }
  109. .skip-theme-txt {
  110. color: rgb(194, 184, 184);
  111. text-align: center;
  112. }
  113. .skip-btn {
  114. position: absolute;
  115. bottom: 50px;
  116. width: 100%;
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. }
  121. .skip-btn p {
  122. height: 30px;
  123. width: 200px;
  124. background-color: rgb(7, 192, 88);
  125. border-radius: 8px;
  126. line-height: 30px;
  127. color: #fff;
  128. text-align: center;
  129. }
  130. </style>
  131. </head>
  132. <body>
  133. <div class="skip-wrap">
  134. <div class="skip-theme" id="container-tip"></div>
  135. <div class="skip-btn">
  136. <p onclick="openWeapp()" id="container"></p>
  137. <p onclick="openWx()" id="container-wx"></p>
  138. </div>
  139. </div>
  140. </body>
  141. </html>