wangfei
2024-11-21 999ac56a03c8221a084a3afab870d258dd4d9741
UI-Project/src/router/index.js
@@ -1,9 +1,8 @@
import {createRouter, createWebHashHistory} from 'vue-router'
// import i18n from '@/utils/lang'
// import User from '../views/sys/User.vue'
// import Role from '../views/sys/Role.vue'
// import Menu from '../views/sys/Menu.vue'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
@@ -17,6 +16,11 @@
      path: '/login',
      name: 'login',
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/new-page', // 新增的无需登录的页面
      name: 'newPage',
      component: () => import('../views/NewPage.vue')
    },
    {
      path: '/main',
@@ -68,26 +72,41 @@
        /*----------- 上片机 ----------------*/
      {
        path: 'Returns',
        name: 'Returns',
        component: () => import('../views/Returns/returns.vue'),
        name: 'return',
        component: () => import('../views/Returns/return.vue'),
        children:[
          {
            path: '/Returns/returns',
            name: 'returns',
            component: () => import('../views/Returns/returns.vue')
          },
          {
            path: '/Returns/upreturns',
            name: 'upreturns',
            component: () => import('../views/Returns/upreturns.vue')
          },
          {
            path: '/Returns/upreturns2',
            name: 'upreturns2',
            component: () => import('../views/Returns/upreturns2.vue')
          },
        ]
      },
      /*----------- 掰片/识别 ----------------*/
    {
      path: 'Identify',
      name: 'Identify',
      component: () => import('../views/Identify/identify.vue'),
      children:[
      name: 'ident',
      component: () => import('../views/Identify/ident.vue'),
      children: [
        {
          path: '/Identify/identify',
          name: 'identify',
          component: () => import('../views/Identify/identify.vue')
        },
        {
          path: '/Identify/identifwu',
          name: 'identifwu',
          component: () => import('../views/Identify/identifwu.vue')
        },
      ]
    },
@@ -107,6 +126,11 @@
        name: 'cachingun',
        component: () => import('../views/Caching/cachingun.vue')
      },
      {
        path: '/Caching/cachingyiwu',
        name: 'cachingyiwu',
        component: () => import('../views/Caching/cachingyiwu.vue')
      },
    ]
  },
  /*----------- 磨边(冷加工) ----------------*/
@@ -124,6 +148,11 @@
      path: '/StockBasicData/stockBasicDatatwo',
      name: 'stockBasicDatatwo',
      component: () => import('../views/StockBasicData/stockBasicDatatwo.vue')
    },
    {
      path: '/StockBasicData/stockBasicyiwu',
      name: 'stockBasicyiwu',
      component: () => import('../views/StockBasicData/stockBasicyiwu.vue')
    },
  ]
},
@@ -186,20 +215,25 @@
            }
          ]
        },
        {
         /*----------- 仓储中心 ----------------*/
         {
          path: 'GlassStorage',
          name: 'GlassStorage',
          component: () => import('../views/GlassStorage/MaterialRackManagement.vue'),
          component: () => import('../views/GlassStorage/GlassStorage.vue'),
          children:[
            {
              path: '/GlassStorage/MaterialRackManagement',
              name: 'MaterialRackManagement',
              component: () => import('../views/GlassStorage/MaterialRackManagement.vue')
            },
            {
              path: '/GlassStorage/rawfilmstorage',
              name: 'rawfilmstorage',
              component: () => import('../views/GlassStorage/rawfilmstorage.vue')
            }
          ]
         },
        },
         /*----------- 可视化系统 ----------------*/
         {
          path: 'Visualization',
@@ -246,6 +280,32 @@
    }
  ]
 },
  /*----------- 大屏显示 ----------------*/
  {
    path: 'largescreen',
    name: 'largescreen',
    component: () => import('../views/largescreen/largescreen.vue'),
    children:[
      {
        path: '/largescreen/largescreen',
        name: 'largescreen',
        component: () => import('../views/largescreen/largescreen.vue')
      },
    ]
  },
  /*----------- 报工管理 ----------------*/
  {
    path: 'reportWork',
    name: 'reportWork',
    component: () => import('../views/ReportWork/reportWork.vue'),
    children:[
      {
        path: '/ReportWork/reportWork',
        name: 'reportWork',
        component: () => import('../views/ReportWork/reportWork.vue')
      },
    ]
  },
        /*----------- 管理系统 ----------------*/
        {
          path: 'sys',
@@ -271,7 +331,7 @@
        },
        {
          path: '',
          redirect: '/returns/returns'
          redirect: '/Returns/returns'
        }
      ]
    },
@@ -283,5 +343,14 @@
    
  ]
})
export default router
// 导航守卫
router.beforeEach((to, from, next) => {
  const isAuthenticated = !!localStorage.getItem('authToken'); // 假设这是你的登录状态检查逻辑
  if (to.matched.some(record => record.meta.requiresAuth) && !isAuthenticated) {
    next({ name: 'login' }); // 如果需要登录但未登录,则重定向到登录页面
  } else {
    next(); // 否则继续导航
  }
});
export default router