jump.html 3.8 KB

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