Selaa lähdekoodia

跳转微信小程序

hwb0 3 vuotta sitten
vanhempi
commit
b8acb67373
1 muutettua tiedostoa jossa 38 lisäystä ja 35 poistoa
  1. 38 35
      public/jump.html

+ 38 - 35
public/jump.html

@@ -7,38 +7,40 @@
 
   <script>
     function docReady(fn) {
-        if (document.readyState === 'complete' || document.readyState === 'interactive') {
-          fn()
-        } else {
-          document.addEventListener('DOMContentLoaded', fn);
-        }
+      if (document.readyState === 'complete' || document.readyState === 'interactive') {
+        fn()
+      } else {
+        document.addEventListener('DOMContentLoaded', fn);
       }
+    }
 
-      docReady(async function() {
-        var ua = navigator.userAgent.toLowerCase()
-        var isWXWork = ua.match(/wxwork/i) == 'wxwork'
-        var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
-        var isMobile = false
-        var isDesktop = false
-        if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
-          isMobile = true
-        } else {
-          isDesktop = true
-        }
+    docReady(async function () {
+      var ua = navigator.userAgent.toLowerCase()
+      var isWXWork = ua.match(/wxwork/i) == 'wxwork'
+      var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
+      var isMobile = false
+      var isDesktop = false
+      if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
+        isMobile = true
+      } else {
+        isDesktop = true
+      }
 
-        var containerEl = document.getElementById('container')
-
-        if (isWeixin) {
-          console.log('111', 111)
-          containerEl.innerHTML = '微信'
-        } else if (isDesktop) {
-         console.log('222', 222)
-         containerEl.innerHTML = '电脑'
-        }  else {
-          console.log('333', 333)
-          containerEl.innerHTML = '其他'
-        }
-      })
+      var container = document.getElementById('container')
+      var wx = document.getElementById('container-wx')
+      var tip = document.getElementById('container-tip')
+
+      if (isWeixin) {
+        container.innerHTML = '打开微信小程序'
+        tip.innerHTML = '点击以下按钮打开 “盲票小程序”'
+        wx.style.display = "none";
+      } else {
+        container.style.display = "none";
+        wx.style.display = "inline";
+        wx.innerHTML = '打开微信'
+        tip.innerHTML = '请使用微信扫描当前二维码'
+      }
+    })
 
     function ajax(options) {
       return new Promise((resolve, reject) => {
@@ -86,13 +88,16 @@
         console.log(data)
         window.location.href = "weixin://";
       })
+    }
 
+    function openWx() {
+      window.location.href = "weixin://";
     }
   </script>
   <style>
     .skip-wrap {
-      height: 100vh;
       width: 100%;
+      height: 100%;
       position: relative;
     }
 
@@ -142,12 +147,10 @@
 
 <body>
   <div class="skip-wrap">
-    <div class="skip-theme">
-      <div class="skip-theme-iamge">logo</div>
-      <div class="skip-theme-txt">小程序</div>
-    </div>
+    <div class="skip-theme" id="container-tip"></div>
     <div class="skip-btn">
-      <p onclick="openWeapp()" id="container">打开微信小程序</p>
+      <p onclick="openWeapp()" id="container"></p>
+      <p onclick="openWx()" id="container-wx"></p>
     </div>
   </div>
 </body>