Parcourir la source

fix(KIP-11250): Temp parking frontend | 已登录状态 |parking-user 校验

john il y a 2 ans
Parent
commit
b11b8c1b6e
4 fichiers modifiés avec 70 ajouts et 27 suppressions
  1. 22 1
      src/api/request.js
  2. 9 25
      src/pages/parkingFee/mixins/parkingFeeDetail.js
  3. 9 1
      src/store/index.js
  4. 30 0
      src/utils/index.js

+ 22 - 1
src/api/request.js

@@ -7,9 +7,11 @@ import {md} from '@/utils/common'
 // import { Loading } from 'element-ui';
 // import { ElLoadingComponent } from 'element-ui/types/loading';
 // import vm from "@/main";
-import { Toast } from 'vant';
+import { Toast, Dialog } from 'vant';
 // import vue from 'vue';
 import store from '@/store';
+import {backLbsHome, getsTheCurrentTopic} from "@/utils";
+import kipTheme from '@/kui/theme/theme'
 // import { v4 as uuidv4 } from 'uuid';
 // import { wxToLoginCallback } from '@/utils/index.js'
 let loadingInstance = null;
@@ -102,6 +104,20 @@ function XUser(config) {
     // isLogin: store.state?.member?.vipcode ? true : false
     isLogin: store.state?.isLogin === 'haveLoggedIn'
   };
+  if(!params.isLogin) {
+    delete params.vipCode
+    delete params.userId
+    delete params.phoneNumber
+  }
+  if(params.isLogin && (!params.vipCode || !params.userId) && config.url.indexOf('/parking-lots/') < -1) {
+    throw {
+      response: {
+        data: {
+          code:'BAD_USER_INFO'
+        }
+      }
+    };
+  }
   // params = {"userId": "8aaa809d835ba76d018378bc57180006","sourceType": "WECHAT","phoneNumber": "18521563898","projectId": "paroject1","buildingId": "QHKC-P1","brandId":"8a84853b7c91ac5b017c962dab55030e","cid": "oIUfO5XAVleJ88z13i1_08DCKIhQ","vipCode":"KERRY100200040","lbsId":"8aaa81cb7c836c6b017c83e46b110001"}
   if (/orders-and-prepay|calculate-discount|unlicensed-car-check-in|unlicensed-car-checkout|paper-coupon/g.test(config.url)) {
     params.buildingId = window.localStorage.getItem('buildingId');
@@ -156,6 +172,7 @@ export const createAxiosByinterceptors = (config) => {
       return config;
     },
     function (error) {
+      console.log('167167', error)
       // 对请求错误做些什么
       return Promise.reject(error);
     }
@@ -203,6 +220,10 @@ export const createAxiosByinterceptors = (config) => {
       if (codeList.indexOf(code) > -1) {
         uni.showToast({ title: langMessage || message, duration: 3000, icon: 'fail' });
       }
+      // 如果必填参数校验失败的话
+      if (['BAD_USER_INFO'].indexOf(code) > -1) {
+        backLbsHome()
+      }
       if ( status === 500 ) {
         uni.showToast({ title: error.response.data.error, duration: 3000, icon: 'fail' });
       }

+ 9 - 25
src/pages/parkingFee/mixins/parkingFeeDetail.js

@@ -4,7 +4,13 @@ import log from '@/utils/log.js';
 import { compare } from '@/utils/location.js';
 import uni from '@/utils/uniHooks';
 import { initWxJsSdkConfig } from '@/utils/login';
-import {getPlatform, getsTheCurrentTopic, isAlipay, theCommunicationBetweenWechatAndH5IsNormal} from '@/utils';
+import {
+  backLbsHome,
+  getPlatform,
+  getsTheCurrentTopic,
+  isAlipay,
+  theCommunicationBetweenWechatAndH5IsNormal
+} from '@/utils';
 import { Dialog, Toast } from 'vant';
 import { ordersAndPrepay } from '@/api/parking';
 // import checkOutResponse from '@/api/mockData/checkout.hz.response'
@@ -53,36 +59,14 @@ export default {
     }, 500)
     setTimeout(async () => {
       // 如果从小程序来的用户已经登录。但是本地的 member 数据是空的,则从后端重新获取,如果获取失败则提示用户
-      if(this.isLogin === 'haveLoggedIn' && this.isNoLogin) {
+      if(this.isLogin === 'haveLoggedIn' && (this.isNoLogin || !this.member?.vipcode)) {
         const res = await this.$store.dispatch('memberInit',{
           unionId: this.$store.state.sourceId,
           openid:  this.$store.state.openid,
           isError: true
         })
         if(res) {
-          const { theme } = getsTheCurrentTopic();
-          const dialog = this.$dialog.alert({
-            title: '温馨提示',
-            message: '当前网络异常,请返回首页重试',
-            confirmButtonColor: this.$theme[theme].primaryColor,
-            beforeClose: async (action, done) => {
-              try {
-                if(window?.__wxjs_environment === 'miniprogram') {
-                  wx?.miniProgram?.reLaunch({
-                    url: '/pages/automatic/automaticIndex'
-                  })
-                }
-                if (isAlipayClient) {
-                  my?.reLaunch({
-                    url: '/pages/automatic/automaticIndex'
-                  })
-                }
-              } catch (e) {
-                console.log('90909090', e)
-              }
-              done()
-            }
-          });
+          backLbsHome()
           return;
         }
       }

+ 9 - 1
src/store/index.js

@@ -9,7 +9,7 @@ import order from './order/index';
 import invoice from './invoice';
 import { lbsDictionary } from '@/common/js/BaseDictionary';
 import { updateUnionId } from '@/api/parking/index'
-import { getGroupIdAndMallIdByLsbId } from '@/utils';
+import {backLbsHome, getGroupIdAndMallIdByLsbId} from '@/utils';
 // import { parkingLots } from '@/utils/api-crm-ms';
 
 Vue.use(Vuex);
@@ -265,6 +265,10 @@ const store = new Vuex.Store({
          }*/
         commit('SET_OPENID', openid || uni.getStorageSync('openid'));
         if (isLogin) {
+          if(!kipUserId) {
+            backLbsHome()
+            return
+          }
           commit('SET_ACCESS_TOKEN', accessToken);
           commit('SET_KIP_USER_ID', kipUserId);
           commit('SET_MOBILE', mobile);
@@ -300,6 +304,10 @@ const store = new Vuex.Store({
     async memberInit({ commit, dispatch },{unionId, openid, isError = true}) {
       try {
         const memberRes = await getVIPIntegral()
+        if(!memberRes?.vipcode) {
+          backLbsHome()
+          return 
+        }
         if (memberRes && isError) {
           await dispatch('updateUnionIdActive', {
             unionId: unionId,

+ 30 - 0
src/utils/index.js

@@ -5,6 +5,8 @@ import SockJS from "@/utils/sockjs";
 import qs from 'qs';
 import { lbsDictionary } from '@/common/js/BaseDictionary';
 import uni from './uniHooks';
+import {Dialog} from "vant";
+import kipTheme from "@/kui/theme/theme";
 
 export function getMobileOperatingSystem() {
   // #ifdef H5
@@ -372,6 +374,34 @@ export function getsTheCurrentTopic() {
 export function setToken() {
   window.token = `${window.location.href}`.replace(/.*wx\/(.*)\/.*/g, '$1');
 }
+
+// 如果用户的 vipcode 或者 userid 不存在提示用户返回首页重新进入
+export function backLbsHome() {
+  const { theme } = getsTheCurrentTopic();
+  const dialog = Dialog.alert({
+    title: '温馨提示',
+    message: '当前网络异常,请返回首页重试',
+    confirmButtonColor: kipTheme[theme].primaryColor,
+    beforeClose: async (action, done) => {
+      const source = uni.getStorageSync('source')
+      try {
+        if(window?.__wxjs_environment === 'miniprogram') {
+          wx?.miniProgram?.reLaunch({
+            url: source === 'KIP' ? '/pages/tabbar/home/home' : '/pages/automatic/automaticIndex'
+          })
+        }
+        if (isAlipayClient) {
+          my?.reLaunch({
+            url: '/pages/automatic/automaticIndex'
+          })
+        }
+      } catch (e) {
+        console.log('90909090', e)
+      }
+      done()
+    }
+  });
+}
 export * from './common/websocket.js'
 export * from './common/localStorage.js'
 export * from './alipayClient/index.js'