77681 8 uur geleden
bovenliggende
commit
2201e2aab0
3 gewijzigde bestanden met toevoegingen van 24 en 5 verwijderingen
  1. 16 1
      gw-ui/src/layout/index.vue
  2. 8 3
      gw-ui/src/permission.js
  3. 0 1
      gw-ui/src/router/index.js

+ 16 - 1
gw-ui/src/layout/index.vue

@@ -1,6 +1,7 @@
 <!-- layout/index.vue -->
 <template>
   <div
+    v-if="layoutReady"
     class="app-wrapper"
     :style="{
       '--current-color': theme,
@@ -53,6 +54,9 @@ const HOME_PATH = "/index";
 // 默认业务入口(工程基本信息 - 内部首页)
 const DEFAULT_BIZ_PATH = "/proj/index";
 
+// 布局就绪状态 — 权限路由加载完成后才渲染,避免闪烁
+const layoutReady = ref(false);
+
 // 计算属性
 const theme = computed(() => settingsStore.theme);
 const sidebar = computed(() => appStore.sidebar);
@@ -156,10 +160,21 @@ watch(
 onMounted(() => {
   // 如果当前是根路径或首页,跳转到工程基本信息-堤防管理(默认页面)
   if (route.path === "/" || route.path === HOME_PATH) {
-    router.push(DEFAULT_BIZ_PATH);
+    router.replace(DEFAULT_BIZ_PATH);
   }
   activeTopMenu.value = getCurrentTopMenu();
 });
+
+// 权限路由加载完成后才渲染布局,避免异步加载期间 Layout 空壳闪烁
+watch(
+  () => permissionStore.routes,
+  (routes) => {
+    if (routes && routes.length > 0) {
+      layoutReady.value = true;
+    }
+  },
+  { immediate: true },
+);
 </script>
 
 <style scoped>

+ 8 - 3
gw-ui/src/permission.js

@@ -17,15 +17,20 @@ router.beforeEach((to, from, next) => {
   if (getToken()) {
     to.meta.title && useSettingsStore().setTitle(to.meta.title)
     const isLock = useLockStore().isLock
+    // 默认业务入口 — 同步跳转,避免 Layout 挂载导致页面闪烁
+    const DEFAULT_PATH = '/proj/index'
     /* has token*/
     if (to.path === '/login') {
-      next({ path: '/' })
+      next({ path: DEFAULT_PATH })
+      NProgress.done()
+    } else if (to.path === '/') {
+      next({ path: DEFAULT_PATH })
       NProgress.done()
     } else if (isLock && to.path !== '/lock') {
       next({ path: '/lock' })
       NProgress.done()
     } else if (!isLock && to.path === '/lock') {
-      next({ path: '/' })
+      next({ path: DEFAULT_PATH })
       NProgress.done()
     } else {
       if (useUserStore().roles.length === 0) {
@@ -43,7 +48,7 @@ router.beforeEach((to, from, next) => {
         }).catch(err => {
           useUserStore().logOut().then(() => {
             ElMessage.error(err)
-            next({ path: '/' })
+            next({ path: DEFAULT_PATH })
           })
         })
       } else {

+ 0 - 1
gw-ui/src/router/index.js

@@ -56,7 +56,6 @@ export const constantRoutes = [
   {
     path: '',
     component: Layout,
-    redirect: '/index',
     children: [
       {
         path: '/index',