Browse Source

路由 500 ,tabs 缓存问题

xiaochan 1 year ago
parent
commit
dbc0b5e53c

+ 6 - 1
src/layout/HeaderV2/RouteNavigation.vue

@@ -24,6 +24,7 @@ import tabsHook from "@/layout/HeaderV2/tabs-hook";
 import RightClickMenu from "@/components/menu-item/RightClickMenu";
 import router from '@/router'
 import XEUtils from "xe-utils";
+import {stringIsBlank} from "@/utils/blank-utils";
 
 const tagRef = ref<HTMLElement | null>(null)
 
@@ -179,7 +180,11 @@ const routingChanges = (createTabs = true) => {
     handleScrolling(data)
   })
 
-  if (XEUtils.has(currentRoute, 'meta.hideTabs', true)) {
+  if (XEUtils.get(currentRoute, 'meta.hideTabs', true)) {
+    return;
+  }
+
+  if (stringIsBlank(currentRoute.name)) {
     return;
   }
 

+ 37 - 30
src/router/index.ts

@@ -41,38 +41,45 @@ async function beforeAddRoutes() {
 
 function createNameComponent(item) {
     return () => {
-        return new Promise(resolve => {
-            vueFile[`${item.component}`]().then(res => {
-                const tmp = defineComponent({
-                    name: item.name,
-                    render() {
-                        let children = [createVNode(res.default)]
-                        const style = {
-                            height: '100%',
-                            width: '100%',
+        return new Promise((resolve, reject) => {
+            try {
+                vueFile[`${item.component}`]().then(res => {
+                    const tmp = defineComponent({
+                        name: item.name,
+                        render() {
+                            let children = [createVNode(res.default)]
+                            const style = {
+                                height: '100%',
+                                width: '100%',
+                            }
+                            const props = {
+                                style
+                            }
+                            if (item.mainCard) {
+                                props.class = 'layout_card'
+                            }
+                            if (item.mainOverflowAuto) {
+                                children = [
+                                    h('div', {
+                                        style: {
+                                            height: '100%',
+                                            width: '100%',
+                                            overflow: 'auto'
+                                        }
+                                    }, [createVNode(res.default)])
+                                ]
+                            }
+                            return h('div', props, children);
                         }
-                        const props = {
-                            style
-                        }
-                        if (item.mainCard) {
-                            props.class = 'layout_card'
-                        }
-                        if (item.mainOverflowAuto) {
-                            children = [
-                                h('div', {
-                                    style: {
-                                        height: '100%',
-                                        width: '100%',
-                                        overflow: 'auto'
-                                    }
-                                }, [createVNode(res.default)])
-                            ]
-                        }
-                        return h('div', props, children);
-                    }
+                    })
+                    resolve(tmp)
                 })
-                resolve(tmp)
-            })
+            } catch (e) {
+                reject('路由错误')
+                router.push('/500')
+                console.error(e)
+                console.error('数据', item)
+            }
         })
     }
 }

+ 7 - 0
src/router/modules/dashboard.ts

@@ -93,6 +93,13 @@ const route: Array<RouteRecordRaw> = [
         meta: {
             hideTabs: true
         }
+    }, {
+        path: '/500',
+        name: 'pageError',
+        component: import('@/views/system/500.vue'),
+        meta: {
+            hideTabs: true
+        }
     }
 ];
 

+ 24 - 6
src/views/system/401.vue → src/views/system/500.vue

@@ -1,12 +1,12 @@
 <template>
-  <div class="wscn-http404-container layout-container flex center">
+  <div class="wscn-http404-container   flex center">
     <div class="wscn-http404">
       <div class="pic-404">
-        <img class="pic-404__parent" :src="first" alt="404" />
+        <img class="pic-404__parent" :src="first" alt="404"/>
       </div>
       <div class="bullshit">
-        <div class="bullshit__oops">无权限访问!</div>
-        <div class="bullshit__info">您没有访问权限,如需权限,请联系上级授权!</div>
+        <div class="bullshit__oops">页面错误!</div>
+        <div class="bullshit__info">页面错误请联系管理员!</div>
         <el-button @click="go" type="primary" round>跳转首页</el-button>
       </div>
     </div>
@@ -14,8 +14,9 @@
 </template>
 
 <script>
-import { defineComponent } from 'vue'
+import {defineComponent} from 'vue'
 import first from '@/assets/images/401.gif'
+
 export default defineComponent({
   setup() {
     return {
@@ -30,23 +31,31 @@ export default defineComponent({
 })
 </script>
 
-<style lang="scss" scoped>
+<style lang="scss">
 .wscn-http404-container {
   border-bottom: none;
+  background: white;
+  height: 100%;
+  width: 100%;
 }
+
 .wscn-http404 {
   position: relative;
   overflow: hidden;
+
   .pic-404 {
     position: relative;
     float: left;
     width: 600px;
     overflow: hidden;
+
     &__parent {
       width: 313px;
     }
+
     &__child {
       position: absolute;
+
       &.left {
         width: 80px;
         top: 17px;
@@ -58,6 +67,7 @@ export default defineComponent({
         animation-fill-mode: forwards;
         animation-delay: 1s;
       }
+
       &.mid {
         width: 46px;
         top: 10px;
@@ -69,6 +79,7 @@ export default defineComponent({
         animation-fill-mode: forwards;
         animation-delay: 1.2s;
       }
+
       &.right {
         width: 62px;
         top: 100px;
@@ -80,6 +91,7 @@ export default defineComponent({
         animation-fill-mode: forwards;
         animation-delay: 1s;
       }
+
       @keyframes cloudLeft {
         0% {
           top: 17px;
@@ -148,12 +160,14 @@ export default defineComponent({
       }
     }
   }
+
   .bullshit {
     position: relative;
     float: left;
     width: 190px;
     padding: 30px 0;
     overflow: hidden;
+
     &__oops {
       font-size: 32px;
       font-weight: bold;
@@ -165,6 +179,7 @@ export default defineComponent({
       animation-duration: 0.5s;
       animation-fill-mode: forwards;
     }
+
     &__headline {
       font-size: 20px;
       line-height: 24px;
@@ -177,6 +192,7 @@ export default defineComponent({
       animation-delay: 0.1s;
       animation-fill-mode: forwards;
     }
+
     &__info {
       font-size: 13px;
       line-height: 21px;
@@ -188,6 +204,7 @@ export default defineComponent({
       animation-delay: 0.2s;
       animation-fill-mode: forwards;
     }
+
     &__return-home {
       display: block;
       float: left;
@@ -206,6 +223,7 @@ export default defineComponent({
       animation-delay: 0.3s;
       animation-fill-mode: forwards;
     }
+
     @keyframes slideUp {
       0% {
         transform: translateY(60px);