Quellcode durchsuchen

Merge pull request #207 from John-Hong/John/release-2.13.0/SCRM-4300

fix(SCRM-4300): Incident - 停车缴费不能及时支付
Tron vor 2 Jahren
Ursprung
Commit
45c9e672e6

+ 16 - 6
src/App.vue

@@ -24,7 +24,7 @@
 </template>
 <script>
 import loginMinix from '@/mixins/login';
-import { getIsMin,getIsWxh5,getUrlParams,initEnv,requestInit,wssInit } from '@/utils/index.js';
+import { getIsMin, getIsWxh5, getUrlParams, initEnv, requestInit, wssInit, theCommunicationBetweenWechatAndH5IsNormal, isReloadBefore, getsTheCurrentTopic } from '@/utils/index.js';
 import uni from '@/utils/uniHooks';
 import { getAppIdByGroupIdAndMallId } from '@/utils/index.js';
 import sensorsFn from '@/plugins/sensors';
@@ -74,8 +74,22 @@ export default {
       uni.setStorageSync('env', window.env);
       // 如果是微信小程序。初始化wss
       if (getIsMin()) {
+        // 如果刷新之后没有与微信小程序建立链接则提示用户,关闭小程序重新进入
+        const isReloadLoop = await isReloadBefore();
+        if (isReloadLoop) {
+          const isReload = await theCommunicationBetweenWechatAndH5IsNormal();
+          if (isReload) {
+            const { theme } = getsTheCurrentTopic();
+            this.$dialog({
+              title: '温馨提示',
+              message: '当前网络异常,请重新进入小程序',
+              confirmButtonColor: this.$theme[theme].primaryColor,
+            });
+            return;
+          }
+        }
         if (window.location.href.indexOf('cryptojs') > -1) {
-          return
+          return;
         }
         // 保留 carList
         const carList = uni.getStorageSync('carList');
@@ -85,16 +99,12 @@ export default {
           uni.setStorageSync('carList', JSON.parse(carList));
         }
         this.$store.commit('SET_IS_INIT', false);
-        console.log('platform====>88');
         window.token = `${window.location.href}`.replace(/.*wx\/(.*)\/.*/g, '$1');
-        console.log('platform====>90');
         try {
           const options = await wssInit();
-          console.log('platform====>93');
           this.$store.dispatch('baseInit', {
             options,
             callback: () => {
-              console.log('platform====>96');
               this.$store.commit('SET_IS_INIT', true);
               // 无感积分逻辑
               // this.wxEasyPointsCommitStatusInit();

+ 1 - 0
src/pages/parkingFee/mixins/base.js

@@ -1,4 +1,5 @@
 import { mapState } from "vuex";
+import {getsTheCurrentTopic} from '@/utils/index'
 
 export default {
   data() {

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

@@ -4,7 +4,7 @@ import log from '@/utils/log.js';
 import { compare } from '@/utils/location.js';
 import uni from '@/utils/uniHooks';
 import { initWxJsSdkConfig } from '@/utils/login';
-import { getAppIdByGroupIdAndMallId, getIsWxh5, getPlatform, isAlipay } from '@/utils';
+import { getPlatform, isAlipay, theCommunicationBetweenWechatAndH5IsNormal } from '@/utils';
 import { Dialog, Toast } from 'vant';
 import { ordersAndPrepay } from '@/api/parking';
 // import checkOutResponse from '@/api/mockData/checkout.hz.response'
@@ -145,6 +145,12 @@ export default {
   methods: {
     // 前往支付
     async toPay() {
+      // 判断微信小程序与 h5 是否正常通信
+      const isReload = await theCommunicationBetweenWechatAndH5IsNormal()
+      if(!isReload) {
+        uni.setStorageSync('isReload', 1)
+        window.location.reload()
+      }
       if (this.btnLoading) return
       this.btnLoading = true
       setTimeout(() => {
@@ -286,7 +292,7 @@ export default {
     },
     kerryPayment(session = '011cad54-735f-4e92-8f1b-f22bdfe073cd', payParams) {
       const platform = getPlatform();
-      console.log('platform:::', platform)
+      // console.log('platform:::', platform)
       let appId = uni.getStorageSync('appid');
       let openId = uni.getStorageSync('openid') || this.openid;
       if (platform === 'miniprogram') {
@@ -294,7 +300,7 @@ export default {
         // appId = 'wxd830fe4d1e04988e';
         appId = this.appId;
       }
-      console.log('支付宝::', isAlipay())
+      // console.log('支付宝::', isAlipay())
       const params = {
         region: 'cn',
         payChannel: isAlipay() ? 'MINI_PROGRAM' : 'OFFICIAL_ACCOUNT',

+ 37 - 0
src/utils/common/websocket.js

@@ -0,0 +1,37 @@
+import uni from '@/utils/uniHooks';
+// 判断小程序与H5保持通信
+export function theCommunicationBetweenWechatAndH5IsNormal() {
+    return new Promise(resolve => {
+        try {
+            // 请求 projectId
+            const projectId = setTimeout(() => {
+                resolve(false);
+            }, 5000)
+            window.toWXSendMsg({
+                type: 'getProjectId',
+                options: {},
+            });
+            window.subscribe('projectId', (options) => {
+                clearTimeout(projectId)
+                resolve(options);
+            });
+        } catch (err) {
+            resolve(false);
+            console.log('=====>theCommunicationBetweenWechatAndH5IsNormal', err);
+        }
+    })
+}
+// 判断是否触发提示
+export function isReloadBefore() {
+    return new Promise(resolve => {
+        try {
+            if (Number.parseInt(uni.getStorageSync('isReload')) === 1) {
+                resolve(true)
+                return
+            } 
+            resolve(false)
+        } catch (err) {
+            resolve(false)
+        }
+    })
+}

+ 34 - 12
src/utils/index.js

@@ -77,7 +77,7 @@ export function isAlipay() {
 // 是否在微信小程序中运行
 export function getIsMin() {
   const platform = getPlatform();
-  console.log('platform====>80', platform);
+  // console.log('platform====>80', platform);
   return platform === 'miniprogram';
 }
 
@@ -134,7 +134,7 @@ export function getUrlParams( url = window.location.href ) {
 
 // 根据不同环境和lsbid返回 groupId 和 mallId
 export function getGroupIdAndMallIdByLsbId( lbsId ) {
-  console.log(125,lbsId);
+  // console.log(125,lbsId);
   const lbsObj = lbsDictionary[lbsId];
   if ( window.env === 'prod' ) {
     return lbsObj['prod'];
@@ -159,12 +159,12 @@ export function wxToLoginCallback( path,callback ) {
       },
     });
     window.subscribe('callback',( options ) => {
-      console.log('登录页面的回调',JSON.stringify(options));
+      // console.log('登录页面的回调',JSON.stringify(options));
       if ( options.isReload ) {
-        console.log('刷新页面');
+        // console.log('刷新页面');
         window.location.reload();
       } else {
-        console.log('刷新页面:callback');
+        // console.log('刷新页面:callback');
         callback && callback(options);
         uni.setStorageSync('oldPath','');
       }
@@ -300,24 +300,17 @@ export function windowSendInit() {
 export function wssInit() {
   return new Promise(( resolve,reject ) => {
     try {
-      console.log('platform====>303');
       const socket = new SockJS(`${ getUrl() }/hafengWebsocket?token=${ window.token }`);
-      console.log('platform====>305');
       window.stompClient = Stomp.over(socket);
-      console.log('platform====>307');
       // window.stompClient.debug = false;
-      console.log('platform====>308');
       windowSendInit();
-      console.log('platform====>311');
       window.stompClient.connect({},( frame ) => {
-        console.log('platform====>312');
         // 请求 projectId
         window.toWXSendMsg({
           type: 'getProjectId',
           options: {},
         });
         window.subscribe('projectId',( options ) => {
-          console.log('platform====>320');
           resolve(options);
         });
       });
@@ -326,3 +319,32 @@ export function wssInit() {
     }
   });
 }
+
+
+// 获取当前的主题
+export function getsTheCurrentTopic() {
+  let theme = 'theme-mall'
+  let componentName = ''
+  const source = uni.getStorageSync('source')
+  const custTypeId = uni.getStorageSync('custTypeId')
+  const com = ['purpleCom', 'blueCom', 'greenCom', 'officeBlueCom', 'purpleCom'];
+  if (custTypeId < 3 || !custTypeId) {
+    componentName = 'baseParkingFeeCom';
+    theme = 'theme-mall'
+  } else {
+    componentName = com[custTypeId];
+    theme = 'theme-office'
+  }
+  if (source === 'KIP') {
+    theme = 'theme-office'
+  }
+  if (source === 'PUDONG') {
+    theme = 'theme-pudong'
+  }
+  if (source === 'JINGAN') {
+    theme = 'theme-jingan'
+  }
+  return { theme, componentName }
+}
+
+export * from './common/websocket.js'