Browse Source

feat(KIP-7159): 登录之后,获取用户 vipcode 失败。H5 跳转 到 CRM小程序的积分商城。

John-Hong 2 years ago
parent
commit
49d85fa774
2 changed files with 96 additions and 17 deletions
  1. 13 10
      src/pages/login/login.vue
  2. 83 7
      src/pages/parkingFee/parkingFeeCoupon.vue

+ 13 - 10
src/pages/login/login.vue

@@ -313,7 +313,7 @@ export default {
         },
       });
     },
-    queryMember: function () {
+    queryMember: function (callback) {
       let _this = this;
       uni.showLoading({
         title: '正在加载',
@@ -328,7 +328,7 @@ export default {
             const member = result.data;
             console.log(326, member);
             if (member) {
-              _this.getKipMemberInfoAfter(member);
+              _this.getKipMemberInfoAfter(member, callback);
             } else {
               MemberCacheTool.cleanMemberCache(app);
               uni.showToast({
@@ -419,13 +419,15 @@ export default {
               //   uni.setStorageSync('comfirKerryOn', true);
               // }
               _this.saveAgreementAction();
-              _this.queryMember();
-              // 返回首页
-              window.location.href = `${
-                window.location.origin
-              }/tparking/${uni.getStorageSync('groupId')}/${uni.getStorageSync(
-                'mallId'
-              )}/`;
+              _this.queryMember(() => {
+                // 返回首页
+                window.location.href = `${
+                  window.location.origin
+                }/tparking/${uni.getStorageSync(
+                  'groupId'
+                )}/${uni.getStorageSync('mallId')}/`;
+              });
+
               // _this.$router.push({ path: 'home' });
               // setTimeout(() => {
               //   window.location.reload();
@@ -560,7 +562,7 @@ export default {
           console.error(err);
         });
     },
-    getKipMemberInfoAfter(kipMemberInfo) {
+    getKipMemberInfoAfter(kipMemberInfo, callback) {
       console.log(550, kipMemberInfo);
       MemberCacheTool.setKipMember(app, kipMemberInfo);
 
@@ -593,6 +595,7 @@ export default {
               );
               this.$store.commit('SET_USER_INFO', member);
               this.$store.commit('SET_MEMBER', member);
+              callback && callback();
               // TODO: 埋点公共属性重新赋值
               // _this.$sensors.registerApp({
               //   $open_id: _this.globalData?.member?.openId || '',

+ 83 - 7
src/pages/parkingFee/parkingFeeCoupon.vue

@@ -42,18 +42,32 @@
             <span class="message">您还没有卡券</span>
           </div>
         </van-checkbox-group>
+        <!-- 为避免冲突,小程序 和 H5 跳转 CRM小程序:积分商城 的逻辑分开处理 -->
         <div
           :class="['guide-box', 'mgb-110', !list?.length && 'flex-bottom']"
           v-if="platform === 'miniprogram'"
         >
           <div class="guide-title">优惠券兑换指导</div>
           <div class="guide-desc" @click="navigateToMiniProgram">
+            停车优惠券可直接使用,若您还没有兑换或继续兑换,可前往
+            <span class="guide-mini">嘉里中心小程序>积分商城</span>
+            进行兑换
+          </div>
+        </div>
+        <div
+          :class="['guide-box', 'mgb-110', !list?.length && 'flex-bottom']"
+          v-if="platform === 'micromessenger'"
+        >
+          <div class="guide-title">优惠券兑换指导</div>
+          <div class="guide-desc">
             停车优惠券可直接使用,若您还没有兑换或继续兑换,可前往
             <wx-open-launch-weapp
-              username=""
-              path=""
-              env-version=""
+              username="gh_0bd6a97b6d38"
+              :path="launchPath"
+              :env-version="window.env === 'qa' ? 'trial' : 'release'"
               class="wx-open-launch-weapp"
+              @launch="launchFn"
+              @error="launchErrorFn"
               ><span class="guide-mini"
                 >嘉里中心小程序>积分商城</span
               ></wx-open-launch-weapp
@@ -95,8 +109,8 @@ import { mapState } from 'vuex';
 import uni from '@/utils/uniHooks';
 // import { initWxJsSdkConfig } from '@/utils/login';
 import { Toast } from 'vant';
-import { getPlatform } from '@/utils/index';
-
+import { getPlatform, getAppIdByGroupIdAndMallId, isInWeixinH5 } from '@/utils';
+import { initWxJsSdkConfig } from '@/utils/login';
 export default {
   created() {
     // 纸质优惠券
@@ -122,12 +136,18 @@ export default {
     // JSON.parse(uni.getStorageSync('checkedCouponList')) || [];
   },
   mounted() {
-    // initWxJsSdkConfig([], ['wx-open-launch-weapp']);
+    if (isInWeixinH5()) {
+      initWxJsSdkConfig(
+        ['checkJsApi', 'chooseImage'],
+        ['wx-open-launch-weapp']
+      );
+    }
     setTimeout(() => {
       uni.setNavigationBarTitle({
         title: '优惠券',
       });
     }, 300);
+    this.launchPathInit();
     // console.log('查看结果', uni.getStorageSync('list'));
     const list = uni.getStorageSync('list');
     this.parkFee = JSON.parse(uni.getStorageSync('parkFee'));
@@ -231,6 +251,7 @@ export default {
       parkMallCode: 1, // 0静安 1浦东 2杭州 3北京 4沈阳 5深圳
       paperCouponFee: 0, // 纸质优惠金额
       platform: getPlatform(),
+      launchPath: '', // H5跳转CRM微信小程序
     };
   },
   computed: {
@@ -434,10 +455,48 @@ export default {
     // 跳转小程序
     navigateToMiniProgram() {
       if (this.platform === 'miniprogram') {
+        const { projectId } = getAppIdByGroupIdAndMallId({
+          groupId: this.$route.params.groupId,
+          mallId: this.$route.params.mallId,
+          type: 'all',
+        });
         window.toWXSendMsg({
           type: 'navigateToMiniProgram',
-          options: {},
+          options: {
+            launchPath: this.launchPath,
+          },
         });
+        setTimeout(() => {
+          this.$router.go(-2);
+        }, 200);
+      }
+      if (isInWeixinH5()) {
+        // this.$wx.chooseWXPay({
+        //   timestamp: params?.timeStamp,
+        //   nonceStr: params?.nonceStr,
+        //   package: params?.package,
+        //   signType: params?.signType,
+        //   paySign: params?.paySign,
+        //   success: function (res) {
+        //     // alert('success: ' + JSON.stringify(res));
+        //     // res: {"errMsg":"chooseWXPay:cancel"}
+        //     if (res.errMsg === 'chooseWXPay:ok') {
+        //       resolve({ errMsg: 'requestPayment:ok' });
+        //     } else {
+        //       reject(res);
+        //     }
+        //   },
+        //   cancel: function (res) {
+        //     // alert('cancel: ' + JSON.stringify(res));
+        //     // res: {"errMsg":"chooseWXPay:cancel"}
+        //     resolve({ errMsg: 'requestPayment:cancel' });
+        //   },
+        //   fail: function (err) {
+        //     // eslint-disable-next-line no-console
+        //     console.error(err);
+        //     reject(err);
+        //   },
+        // });
       }
     },
     // 超限提示
@@ -497,6 +556,22 @@ export default {
       });
       this.$router.back();
     },
+    launchPathInit() {
+      const { projectId } = getAppIdByGroupIdAndMallId({
+        groupId: this.$route.params.groupId,
+        mallId: this.$route.params.mallId,
+        type: 'all',
+      });
+      this.launchPath = `?trackSourceType=运营位&trackSourceName=功能球&projectId=${projectId}&groupId=${this.$route.params.groupId}&mallId=${this.$route.params.mallId}&source=tparkingH5`;
+    },
+    // H5 跳转到小程序
+    launchFn() {
+      this.$router.go(-2);
+      console.log('H5 跳转到 嘉里中心小程序: success');
+    },
+    launchErrorFn() {
+      console.log('H5 跳转到 嘉里中心小程序: fail');
+    },
   },
 };
 </script>
@@ -718,6 +793,7 @@ export default {
     line-height: 42px;
 
     .guide-mini {
+      display: inline-block;
       color: #064c8a;
       text-decoration: underline;
       margin: 0 5px;