瀏覽代碼

增加流量页面需要微信客户端打开;

loop 11 月之前
父節點
當前提交
525f2b0b32
共有 3 個文件被更改,包括 67 次插入0 次删除
  1. 7 0
      src/pages.json
  2. 18 0
      src/pages/pay/index.vue
  3. 42 0
      src/pages/weixin/index.vue

+ 7 - 0
src/pages.json

@@ -214,6 +214,13 @@
       "style": {
         "navigationStyle": "custom"
       }
+    },
+    {
+      // 微信浏览器检测
+      "path": "pages/weixin/index",
+      "style": {
+        "navigationStyle": "custom"
+      }
     }
   ]
 }

+ 18 - 0
src/pages/pay/index.vue

@@ -173,6 +173,7 @@ wechatPay,
 export default {
   data() {
     return {
+      isWeixin: false,
       type: "center",
       msgType: "success",
       messageText: "这是一条成功提示",
@@ -203,6 +204,14 @@ export default {
   },
 
   onLoad(e) {
+    this.detectWeixin();
+    if (!this.isWeixin){
+      // 跳转到微信页面
+      uni.navigateTo({
+        url: `/pages/weixin/index`,
+      });
+    }
+
     this.state = e.state;
     this.getOpenId(e);
     this.getDetail();
@@ -211,6 +220,15 @@ export default {
     this.getNewAcitivityDetail();
   },
   methods: {
+    detectWeixin() {
+      let userAgent = navigator.userAgent;
+      if (userAgent.includes("MicroMessenger")) {
+        this.isWeixin = true
+        e.preventDefault();
+      } else {
+        this.isWeixin = false
+      }
+    },
     // 联通流量详细信息
     getNewAcitivityDetail() {
       newAcitivityDetail({

+ 42 - 0
src/pages/weixin/index.vue

@@ -0,0 +1,42 @@
+<template>
+  <view style="background-color: white;height: 100%;width: 100%">
+    <!-- 如果不是微信环境,则显示错误提示 -->
+    <view v-if="!isWeixin" class="weui_msg">
+      <div class="weui_icon_area">
+        <i class="weui_icon_info weui_icon_msg"></i>
+      </div>
+      <div class="weui_text_area">
+        <h4 class="weui_msg_title">请在微信客户端打开链接</h4>
+      </div>
+    </view>
+  </view>
+</template>
+
+<script>
+export default {
+  data() {
+    return {
+      isWeixin: false
+    };
+  },
+  onLoad() {
+    this.detectWeixin();
+  },
+  methods: {
+    detectWeixin() {
+      let userAgent = navigator.userAgent;
+      if (userAgent.includes("MicroMessenger")) {
+        this.isWeixin = true
+        e.preventDefault();
+      } else {
+        this.isWeixin = false
+      }
+    }
+  }
+}
+</script>
+
+<style scoped>
+/* 引入 WeUI 的样式 */
+@import 'https://res.wx.qq.com/open/libs/weui/0.4.1/weui.css';
+</style>