Переглянути джерело

feat: optimized qiankun sub app error detection

zhangyuhan 3 роки тому
батько
коміт
6cd4d9eb6c
1 змінених файлів з 12 додано та 6 видалено
  1. 12 6
      packages/micro-frame/qiankun/store.js

+ 12 - 6
packages/micro-frame/qiankun/store.js

@@ -56,11 +56,14 @@ export default {
         }
       })
       addGlobalUncaughtErrorHandler((event) => {
+        const isSubAppLoadError = event.type === 'error' && event.message.indexOf('died in status LOADING_SOURCE_CODE') !== -1
         commit('toggleLoading', false)
-        commit('toggleAbnormal', {
-          type: true,
-          message: '抱歉,加载应用未成功,请联系客服或刷新重试'
-        })
+        if (isSubAppLoadError) {
+          commit('toggleAbnormal', {
+            type: true,
+            message: '抱歉,加载应用未成功,请联系客服或刷新重试'
+          })
+        }
       })
       dispatch('syncModel', state.sharedModel)
     },
@@ -75,11 +78,11 @@ export default {
 
       action.setGlobalState(payload)
     },
-    canMatchApp ({ state, commit }) {
+    canMatchApp ({ state, commit, getters }) {
       const nowPath = getNowRoute()?.params?.pathMatch
       let result = true
       if (nowPath) {
-        result = typeof state.MicroApps.find(m => nowPath.indexOf(m?.rule) === 1)?.rule === 'string'
+        result = getters.ruleRoutes.some(m => new RegExp(m).test(`/${nowPath}`))
       }
       if (!result) {
         commit('toggleLoading', false)
@@ -91,6 +94,9 @@ export default {
     }
   },
   getters: {
+    ruleRoutes (state) {
+      return state.MicroApps.map(m => m?.rule || '').filter(v => v)
+    },
     hooks () {
       return {
         openLink: openLink