Browse Source

feat(KIP-6765): KERRY+小程序临停缴费功能未登录身份使用流程

John-Hong 2 years ago
parent
commit
4c8fafa274

+ 27 - 18
src/App.vue

@@ -279,27 +279,36 @@ export default {
       uni.setStorageSync('appid', appid);
       // 如果用户没有openid
       const openid = uni.getStorageSync('openid');
-      this.isInit = true;
+
       const query = getUrlParams();
+      console.log(284, query, groupId, mallId);
+      // return;
       // 设置openid
-      if (openid && openid !== 'undefined') {
-        this.$store.commit('SET_OPENID', openid);
-        // 用户选择不登录
-        if (this.passLogin !== '3') {
-          // 判断用户是否需要登录
-          this.checkIsLogin(() => {
-            window.location.reload();
-          });
-        }
-      } else {
-        // 前往授权页面
-        if (this.$route.path.indexOf('openWx') < 0) {
-          this.$router.push({
-            path: 'openWx',
-            query,
-          });
+      this.$nextTick(() => {
+        this.isInit = true;
+        if (openid && openid !== 'undefined') {
+          this.$store.commit('SET_OPENID', openid);
+          // 用户选择不登录
+          if (this.isLogin !== '3') {
+            // 判断用户是否需要登录
+            this.checkIsLogin(() => {
+              // window.location.reload();
+            });
+          }
+        } else {
+          // 前往授权页面
+          if (this.$route.path.indexOf('openWx') < 0) {
+            let openWxPath = 'openWx';
+            if (this.$route.fullPath === '/') {
+              openWxPath = `/${groupId}/${mallId}/openWx`;
+            }
+            this.$router.push({
+              path: openWxPath,
+              query,
+            });
+          }
         }
-      }
+      });
       // 获取openid
       // openid 在本地存在的话,走登录验证
       // openid 不存在的话

+ 9 - 2
src/mixins/login.js

@@ -18,7 +18,6 @@ export default {
       const kipAccessToken = uni.getStorageSync('kipAccessToken');
       if (!kipAccessToken) {
         // 如果用户不选择登录,则不走登录逻辑
-        this.isInit = true;
         await this.$router.replace({
           path: 'login',
         });
@@ -26,12 +25,18 @@ export default {
       }
       // 用户二次登录,本地存在 kipAccessToken 检查 token 是否需要登录
       const [stopCallBack] = await this.checkKipToken(kipAccessToken);
-      if (stopCallBack) return stopCallBack();
+      console.log(30, stopCallBack);
+      if (stopCallBack) {
+        // console.log(return stopCallBack();)
+        console.log(32, stopCallBack);
+        return;
+      }
       if (callback) {
         callback();
       }
     },
     checkKipToken(kipAccessToken) {
+      debugger;
       return new Promise(async (resolve) => {
         try {
           const resp = await kipCheckToken(kipAccessToken);
@@ -72,9 +77,11 @@ export default {
       });
     },
     toLogin() {
+      debugger;
       console.warn('===>清除所有缓存1');
       log.info(`清除所有缓存1`);
       this.cleanAll();
+
       this.$router.replace({
         path: 'login',
       });

+ 1 - 1
src/pages/login/login.vue

@@ -421,7 +421,7 @@ export default {
               _this.saveAgreementAction();
               _this.queryMember();
               // 返回首页
-              _this.$router.replace({ path: '/' });
+              _this.$router.replace({ path: 'home' });
             } else {
               log.warn(`手机号登录请求成功: 未获取到授权信息`);
               uni.showModal({

+ 31 - 16
src/pages/login/openWx.vue

@@ -43,7 +43,7 @@ export default {
       // 初始化微信
       // initWxJsSdkConfig(['chooseWXPay', 'scanQRCode', 'checkJsApi']);
       // 如果用户不选择登录,则不走登录逻辑
-      this.isInit = true;
+      const query = getUrlParams();
       this.$router.replace({
         path: 'login',
         query: query,
@@ -53,6 +53,8 @@ export default {
   },
   methods: {
     getCode() {
+      console.log(56, this.$route);
+      debugger;
       const { code = '' } = getUrlParams(); // 截取路径中的code,如果没有就去微信授权,如果已经获取到了就直接传code给后台获取openId
       const local = `${window.location.href}`.replace(/openWx/g, '');
       // return;
@@ -77,27 +79,40 @@ export default {
       }
     },
     async getOpenId(code) {
-      // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
-      const { appid, secret } = getAppIdByGroupIdAndMallId({
-        groupId: this.$route.params.groupId,
-        mallId: this.$route.params.mallId,
-        type: 'all',
-      });
-      // ?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
-      const res = await WxJsOpenId({
-        appid,
-        secret,
-        code,
-        grant_type: 'authorization_code',
-      });
-      if (res?.expires_in && res?.openid) {
-        this.$store.commit('SET_OPENID', res.openid);
+      try {
+        this.$store.commit('SET_OPENID', 'odJnI0-Y6ZJap-Ow9nmJH-4WyxhU');
         // 判断用户是否需要登录,
         await this.checkIsLogin(() => {
           this.$router.replace({
             path: 'home',
           });
         });
+        /*// 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
+        const { appid, secret } = getAppIdByGroupIdAndMallId({
+          groupId: this.$route.params.groupId,
+          mallId: this.$route.params.mallId,
+          type: 'all',
+        });
+        console.log(86, appid, secret, code);
+        // return;
+        // ?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
+        const res = await WxJsOpenId({
+          appid,
+          secret,
+          code,
+          grant_type: 'authorization_code',
+        });
+        if (res?.expires_in && res?.openid) {
+          this.$store.commit('SET_OPENID', res.openid);
+          // 判断用户是否需要登录,
+          await this.checkIsLogin(() => {
+            this.$router.replace({
+              path: 'home',
+            });
+          });
+        }*/
+      } catch (err) {
+        console.log(106, err);
       }
     },
   },

+ 12 - 1
src/pages/parkingFee/parkingFee.vue

@@ -706,7 +706,10 @@ export default {
     // },
     // 缴费记录
     doRouter: function () {
-      uni.removeStorageSync('passLogin');
+      if (this.$store.state.isLogin === '3') {
+        this.$router.push({ path: 'login' });
+        return;
+      }
       this.$router.push({ path: 'parkingFeeList' });
       this.sensorsClick('$ClickParkRouter', {
         cta_itemno: '',
@@ -716,6 +719,10 @@ export default {
     },
     // 车牌管理
     doRouter2: function () {
+      if (this.$store.state.isLogin === '3') {
+        this.$router.push({ path: 'login' });
+        return;
+      }
       uni.removeStorageSync('passLogin');
       this.$router.push({ path: 'vehicleManagement' });
       this.sensorsClick('$ClickParkRouter', {
@@ -726,6 +733,10 @@ export default {
     },
     //停车发票
     doRouter1: function () {
+      if (this.$store.state.isLogin === '3') {
+        this.$router.push({ path: 'login' });
+        return;
+      }
       // uni.removeStorageSync('passLogin');
       // 北京停车场开票
       // if (this.parkInfoEntity.parkMallCode === 3) {

+ 25 - 5
src/pages/parkingFee/parkingFeeDetail.vue

@@ -2,6 +2,7 @@
   <div>
     <scroll-view class="scroll-Y">
       <div>
+        <div @click="scan">扫一扫</div>
         <div class="warp">
           <div
             :class="{
@@ -471,18 +472,19 @@ export default {
     }),
   },
   async created() {
-    console.log('469 我终于知道为什么了', uni.getStorageSync('isReload'));
+    // console.log('469 我终于知道为什么了', uni.getStorageSync('isReload'));
     // if (uni.getStorageSync('isReload') === '4') {
     //   return;
     // }
     // uni.setStorageSync('isReload', '2');
     const platform = getPlatform();
     if (platform === 'micromessenger') {
-      initWxJsSdkConfig(['chooseWXPay']);
+      await initWxJsSdkConfig(['chooseWXPay', 'scanQRCode']);
       try {
-        if (window.wxJsSdkConfigInitPromise) {
-          await window.wxJsSdkConfigInitPromise;
-        }
+        // if (window.wxJsSdkConfigInitPromise) {
+        //   // console.log(window.wxJsSdkConfigInitPromise);
+        //   // window.wxJsSdkConfigInitPromise;
+        // }
       } catch (e) {
         console.log(487, e);
       }
@@ -600,6 +602,7 @@ export default {
 
     // 创建订单
     async createParkOrder() {
+      console.log(603);
       try {
         uni.showLoading({
           title: '加载中',
@@ -1933,6 +1936,23 @@ export default {
         });
       });
     },
+    scan() {
+      this.$wx.scanQRCode({
+        desc: 'scanQRCode desc',
+        needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
+        // scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
+        success: (res) => {
+          debugger;
+          console.log(1945, res);
+          // runScanFn(res);
+          // this.formMsg.deviceCode = res.resultStr;
+        },
+        error: (res) => {
+          debugger;
+          console.log(1950, res);
+        },
+      });
+    },
   },
 };
 </script>

+ 11 - 4
src/pages/parkingFee/parkingFeePaperCoupon.vue

@@ -146,10 +146,13 @@ export default {
       parkInfo: {},
     };
   },
-  mounted() {
+  async mounted() {
     const platform = getPlatform();
     if (platform === 'micromessenger') {
-      initWxJsSdkConfig(['scanQRCode']);
+      await initWxJsSdkConfig(['checkJsApi', 'scanQRCode']);
+      // if (window.wxJsSdkConfigInitPromise) {
+      //   await window.wxJsSdkConfigInitPromise;
+      // }
     }
     setTimeout(() => {
       uni.setNavigationBarTitle({
@@ -227,13 +230,17 @@ export default {
         });
       } else {
         this.$wx.scanQRCode({
+          desc: 'scanQRCode desc',
           needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
-          scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
+          // scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
           success: (res) => {
-            // console.log(187, res);
+            console.log(237, res);
             runScanFn(res);
             // this.formMsg.deviceCode = res.resultStr;
           },
+          error: (res) => {
+            console.log(242, res);
+          },
         });
       }
 

+ 14 - 5
src/utils/login.js

@@ -125,7 +125,10 @@ export function logout() {
  }>
  */
 export function WxJsOpenId(param) {
-  return request.get(`/sns/oauth2/access_token`, param);
+  return request.get(
+    `https://qa-tparking.kerryplus.com/sns/oauth2/access_token`,
+    param
+  );
 }
 
 // H5获取微信签名信息Api - 需要登录
@@ -155,14 +158,19 @@ function WxJsSdkSignature(param) {
 
 
  */
-export function initWxJsSdkConfig(jsApiList = [], openTagList = []) {
-  let url = location.href;
+export async function initWxJsSdkConfig(jsApiList = [], openTagList = []) {
+  let url = `${location.origin}`;
   // https://developers.weixin.qq.com/community/develop/doc/000ae2cb950808f90d8bc415551800
   if (getMobileOperatingSystem() === 'iOS' && window.H5_LAUNCH_URL) {
     url = window.H5_LAUNCH_URL;
   }
+  url = url.replace(/http(s)?:\/\//g, '');
   window.wxJsSdkConfigInitPromise = null;
-  window.wxJsSdkConfigInitPromise = WxJsSdkConfig(jsApiList, url, openTagList);
+  window.wxJsSdkConfigInitPromise = await WxJsSdkConfig(
+    jsApiList,
+    url,
+    openTagList
+  );
 }
 
 /*
@@ -174,9 +182,10 @@ async function WxJsSdkConfig(jsApiList = [], url = '', openTagList = []) {
   const res = await WxJsSdkSignature({ url: url ? url : location.href }); // 这个接口需要登录!
   let debug = false;
   try {
-    debug = uni.getStorageSync('WX_JSSDK_DEBUG');
+    debug = uni.getStorageSync('WX_JSSDK_DEBUG') || false;
   } catch {}
   return new Promise((resolve, reject) => {
+    console.log(184, wx);
     wx.config({
       debug,
       appId: res.data.appId,

+ 1 - 1
src/utils/member-cache-tool.js

@@ -81,7 +81,7 @@ export default {
       // app.globalData.kipMember = kipMember
       // app.globalData.openId = kipMember.openId;
       uni.setStorageSync('kipMember', kipMember);
-      uni.setStorageSync('openid', kipMember.openId);
+      // uni.setStorageSync('openid', kipMember.openId);
       // Monitor.setConfig({
       // 	c1: kipMember.id
       // })