瀏覽代碼

fix(SCRM-5535): 增加关键字段的校验,和获取不到重新获取的逻辑

john 1 年之前
父節點
當前提交
83834047d7

+ 13 - 2
src/api/request.js

@@ -10,7 +10,7 @@ import { md } from '@/utils/common'
 import { Toast, Dialog, Switch } from 'vant';
 // import vue from 'vue';
 import store from '@/store';
-import { backLbsHome, getsTheCurrentTopic, toLogin } from "@/utils";
+import { backLbsHome, getsTheCurrentTopic, toLogin, isEmpty } from "@/utils";
 import kipTheme from '@/kui/theme/theme'
 // import { v4 as uuidv4 } from 'uuid';
 // import { wxToLoginCallback } from '@/utils/index.js'
@@ -110,7 +110,18 @@ function XUser(config) {
     delete params.userId
     delete params.phoneNumber
   }
-  if (params.isLogin && (!params.vipCode || !params.userId || params.userId == 'undefined') && config.url.indexOf('/parking-lots/') < -1 || !params.sourceId) {
+  // 非登录接口,并且 sourceId、cid 为空,提示用户账户信息异常
+  if (!params.isLogin && (isEmpty(params, 'sourceId') || isEmpty(params, 'cid'))  && config.url.indexOf('/parking-lots/') < -1) {
+    throw {
+      response: {
+        data: {
+          message: '当前参数异常,请重新登录',
+          code: 'BAD_USER_INFO_2'
+        }
+      }
+    };
+  }
+   if (params.isLogin && (!params.vipCode || !params.userId || params.userId == 'undefined') && config.url.indexOf('/parking-lots/') < -1 || !params.sourceId) {
     throw {
       response: {
         data: {

+ 7 - 1
src/pages/parkingFee/mixins/parkingFeeDetail.js

@@ -5,6 +5,7 @@ import { compare } from '@/utils/location.js';
 import uni from '@/utils/uniHooks';
 import { initWxJsSdkConfig } from '@/utils/login';
 import {
+  toLogin,
   backLbsHome,
   getPlatform,
   getsTheCurrentTopic,
@@ -403,7 +404,12 @@ export default {
       const platform = getPlatform();
       // console.log('platform:::', platform)
       let appId = uni.getStorageSync('appid');
-      let openId = uni.getStorageSync('openid') || this.openid;
+      let openId = this.$store.state.openid;
+      // 如果 openId 丢失的话,提示用户回到首页重新进入
+      if (openId && openId === 'undefined' || !openId) {
+        toLogin()
+        return
+      }
       if (platform === 'miniprogram') {
         // appId = 'wx92c3e55fbef6b2af';
         // appId = 'wxd830fe4d1e04988e';

+ 8 - 1
src/pages/parkingFeeV2/mixins/parkingFeeDetail.js

@@ -1,6 +1,7 @@
 import { mapState } from 'vuex';
 import uni from '@/utils/uniHooks';
 import {
+  toLogin,
   backLbsHome,
   getPlatform,
   isAlipay,
@@ -472,7 +473,13 @@ export default {
       const platform = getPlatform();
       // console.log('platform:::', platform)
       let appId = uni.getStorageSync('appid');
-      let openId = uni.getStorageSync('openid') || this.openid;
+      // let openId = uni.getStorageSync('openid') || this.openid;
+      let openId = this.$store.state.openid;
+      // 如果 openId 丢失的话,提示用户回到首页重新进入
+      if (openId && openId === 'undefined' || !openId) {
+        toLogin()
+        return
+      }
       if (platform === 'miniprogram') {
         // appId = 'wx92c3e55fbef6b2af';
         // appId = 'wxd830fe4d1e04988e';

+ 27 - 4
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 {backLbsHome, getGroupIdAndMallIdByLsbId} from '@/utils';
+import {backLbsHome, getGroupIdAndMallIdByLsbId, toLogin} from '@/utils';
 // import { parkingLots } from '@/utils/api-crm-ms';
 
 Vue.use(Vuex);
@@ -342,26 +342,37 @@ const store = new Vuex.Store({
         commit('SET_CUST_TYPE_ID', custTypeId);
         commit('SET_GROUP_ID', groupId);
         commit('SET_MALL_ID', mallId);
-        commit('SET_OPENID', openId || uni.getStorageSync('openid'));
         commit('SET_ACCESS_TOKEN', accessToken);
         commit('SET_KIP_USER_ID', kipUserId);
         commit('SET_MOBILE', mobile);
         if (unionId) {
           commit('SET_SOURCE_ID', unionId);
         }
+        if (openId) {
+          commit('SET_OPENID', openId);
+        }
         if(isLogin) {
           commit('SET_IS_LOGIN', isLogin);
         }
+        if(!unionId || unionId ==='undefined') {
+          toLogin()
+          return
+        }
+        // 已经登录
         if(isLogin === 'haveLoggedIn') {
+          // 如果 openId,为空或者是 undefined ,重新获取 openId
+          if(!openId || openId ==='undefined') {
+            dispatch('getOpenId')
+          }
           dispatch('memberInit', {
-            openid: openId || uni.getStorageSync('openid'),
+            openid: openId,
             unionId,
             isError: true
           });
         } else {
           dispatch('updateUnionIdActive', {
             unionId: unionId,
-            openId: openId || uni.getStorageSync('openid')
+            openId: openId
           })
         }
         callback && callback();
@@ -402,6 +413,18 @@ const store = new Vuex.Store({
       const member = uni.getStorageSync('member')
       return JSON.stringify(member) === '{}'
     },
+    async getOpenId({commit}, callback) {
+      try {
+        const res = await kipGetUserDetail()
+        console.log('416 kipGetUserDetail ', res);
+        openId = res.data.openId
+        commit('SET_OPENID', res.data.openId)
+        callback(res.data.openId)
+      } catch (err) {
+        toLogin()
+        return
+      }
+    },
     // updateUnionId
     async updateUnionIdActive({ commit }, { openId, unionId, vipCode = null }) {
       try {

+ 11 - 0
src/utils/common/function.js

@@ -33,4 +33,15 @@ export function waitByTime(settime = 100) {
       resolve()
     }, settime)
   })
+}
+
+// 判读是否为空
+export function isEmpty(obj, key) {
+  if(!obj.hasOwnProperty(key)){
+    return true
+  }
+  if(obj.hasOwnProperty(key) && (obj[key] === '' || obj[key] === 'undefined' || !obj[key])){
+    return true
+  }
+  return false
 }

+ 8 - 8
src/utils/index.js

@@ -183,14 +183,14 @@ export function initEnv() {
   const origin = window.location.origin;
   console.log('当前页面的url地址  ',origin);
   if ( origin.indexOf('https://dev-') > -1  || origin.indexOf('http://127.0.0.1') > -1 || origin.indexOf('http://localhost:') > -1) {
-    // window.env = 'qa';
-    // window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
-    // window.cmrApi = 'https://qa-crm.kerryplus.com/xcrm-api/api';
-    // window.api = 'qaApi';
-    window.env = 'dev';
-    window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
-    window.cmrApi = 'https://dev-crm.kerryplus.com/xcrm-api/api';
-    window.api = 'devApi';
+    window.env = 'qa';
+    window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
+    window.cmrApi = 'https://qa-crm.kerryplus.com/xcrm-api/api';
+    window.api = 'qaApi';
+    // window.env = 'dev';
+    // window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
+    // window.cmrApi = 'https://dev-crm.kerryplus.com/xcrm-api/api';
+    // window.api = 'devApi';
     // window.env = 'prod';
     // window.profileApi = 'https://sl-apim.kerryplus.com/c/api';
     // window.cmrApi = 'https://sl-crm.kerryplus.com/xcrm-api/api';