Browse Source
- 在路由配置中添加了 beforeEach 守卫,用于检查用户登录状态 - 如果用户未登录且目标路由不是登录页,将重定向到登录页 - 移除了部分注释代码,清理了路由配置master
1 changed files with 175 additions and 166 deletions
@ -1,186 +1,195 @@ |
|||||
import { createRouter, createWebHashHistory } from 'vue-router' |
import { createRouter, createWebHashHistory } from 'vue-router' |
||||
|
|
||||
const router = createRouter({ |
const router = createRouter({ |
||||
history: createWebHashHistory(import.meta.env.BASE_URL), |
history: createWebHashHistory(import.meta.env.BASE_URL), |
||||
routes: [ |
routes: [ |
||||
{ |
|
||||
path: '/', |
|
||||
name: 'home', |
|
||||
// 自动引导到 /editor
|
|
||||
component: () => import('@/views/HomeView.vue'), |
|
||||
children: [ |
|
||||
{ |
{ |
||||
path: '/dashboard', |
path: '/', |
||||
name: 'dashboard', |
name: 'home', |
||||
meta: { |
// 自动引导到 /editor
|
||||
title: '仪表盘' |
component: () => import('@/views/HomeView.vue'), |
||||
}, |
children: [ |
||||
component: () => import('@/views/dashboard/index.vue') |
{ |
||||
|
path: '/dashboard', |
||||
|
name: 'dashboard', |
||||
|
meta: { |
||||
|
title: '仪表盘' |
||||
|
}, |
||||
|
component: () => import('@/views/dashboard/index.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/modelingSimulation', |
||||
|
name: 'modelingSimulation', |
||||
|
redirect: '/editor' |
||||
|
}, |
||||
|
{ |
||||
|
path: '/taskManagement', |
||||
|
name: 'taskManagement', |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '/taskQuery', |
||||
|
name: 'taskQuery', |
||||
|
meta: { |
||||
|
title: '任务查询' |
||||
|
}, |
||||
|
component: () => import('@/views/taskManagement/taskQuery.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/automatedPresentation', |
||||
|
name: 'automatedPresentation', |
||||
|
meta: { |
||||
|
title: '自动演示管理' |
||||
|
}, |
||||
|
component: () => import('@/views/taskManagement/automatedPresentation.vue') |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
path: '/log', |
||||
|
name: 'log', |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '/upstream', |
||||
|
name: 'upstream', |
||||
|
meta: { |
||||
|
title: '上游接口日志' |
||||
|
}, |
||||
|
component: () => import('@/views/log/upstream.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/device', |
||||
|
name: 'device', |
||||
|
meta: { |
||||
|
title: '设备报文日志' |
||||
|
}, |
||||
|
component: () => import('@/views/log/device.vue') |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
path: '/device', |
||||
|
name: 'device', |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '/points', |
||||
|
name: 'points', |
||||
|
meta: { |
||||
|
title: '点位管理' |
||||
|
}, |
||||
|
component: () => import('@/views/device/points.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/locations', |
||||
|
name: 'locations', |
||||
|
meta: { |
||||
|
title: '货位管理' |
||||
|
}, |
||||
|
component: () => import('@/views/device/locations.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/vehicles', |
||||
|
name: 'vehicles', |
||||
|
meta: { |
||||
|
title: '车辆管理' |
||||
|
}, |
||||
|
component: () => import('@/views/device/vehicles.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/chargers', |
||||
|
name: 'chargers', |
||||
|
meta: { |
||||
|
title: '充电位管理' |
||||
|
}, |
||||
|
component: () => import('@/views/device/chargers.vue') |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
path: '/inventory', |
||||
|
name: 'inventory', |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '/query', |
||||
|
name: 'query', |
||||
|
meta: { |
||||
|
title: '库存查询' |
||||
|
}, |
||||
|
component: () => import('@/views/inventory/query.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/account', |
||||
|
name: 'account', |
||||
|
meta: { |
||||
|
title: '帐页查询' |
||||
|
}, |
||||
|
component: () => import('@/views/inventory/account.vue') |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
path: '/user', |
||||
|
name: 'user', |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '/users', |
||||
|
name: 'users', |
||||
|
meta: { |
||||
|
title: '用户管理' |
||||
|
}, |
||||
|
component: () => import('@/views/user/users.vue') |
||||
|
}, |
||||
|
{ |
||||
|
path: '/roles', |
||||
|
name: 'roles', |
||||
|
meta: { |
||||
|
title: '角色管理' |
||||
|
}, |
||||
|
component: () => import('@/views/user/roles.vue') |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
] |
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/modelingSimulation', |
path: '/tp', |
||||
name: 'modelingSimulation', |
name: 'tp', |
||||
redirect: '/editor' |
component: () => import('@/components/ThreePerfView.vue') |
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/taskManagement', |
path: '/editor', |
||||
name: 'taskManagement', |
name: 'editor', |
||||
children: [ |
// component: HomeView,
|
||||
{ |
component: () => import('../editor/ModelMain.vue') |
||||
path: '/taskQuery', |
|
||||
name: 'taskQuery', |
|
||||
meta: { |
|
||||
title: '任务查询' |
|
||||
}, |
|
||||
component: () => import('@/views/taskManagement/taskQuery.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/automatedPresentation', |
|
||||
name: 'automatedPresentation', |
|
||||
meta: { |
|
||||
title: '自动演示管理' |
|
||||
}, |
|
||||
component: () => import('@/views/taskManagement/automatedPresentation.vue') |
|
||||
} |
|
||||
] |
|
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/log', |
path: '/about', |
||||
name: 'log', |
name: 'about', |
||||
children: [ |
// route level code-splitting
|
||||
{ |
// this generates a separate chunk (About.[hash].js) for this route
|
||||
path: '/upstream', |
// which is lazy-loaded when the route is visited.
|
||||
name: 'upstream', |
component: () => import('../views/AboutView.vue') |
||||
meta: { |
|
||||
title: '上游接口日志' |
|
||||
}, |
|
||||
component: () => import('@/views/log/upstream.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/device', |
|
||||
name: 'device', |
|
||||
meta: { |
|
||||
title: '设备报文日志' |
|
||||
}, |
|
||||
component: () => import('@/views/log/device.vue') |
|
||||
} |
|
||||
] |
|
||||
}, |
|
||||
{ |
|
||||
path: '/device', |
|
||||
name: 'device', |
|
||||
children: [ |
|
||||
{ |
|
||||
path: '/points', |
|
||||
name: 'points', |
|
||||
meta: { |
|
||||
title: '点位管理' |
|
||||
}, |
|
||||
component: () => import('@/views/device/points.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/locations', |
|
||||
name: 'locations', |
|
||||
meta: { |
|
||||
title: '货位管理' |
|
||||
}, |
|
||||
component: () => import('@/views/device/locations.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/vehicles', |
|
||||
name: 'vehicles', |
|
||||
meta: { |
|
||||
title: '车辆管理' |
|
||||
}, |
|
||||
component: () => import('@/views/device/vehicles.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/chargers', |
|
||||
name: 'chargers', |
|
||||
meta: { |
|
||||
title: '充电位管理' |
|
||||
}, |
|
||||
component: () => import('@/views/device/chargers.vue') |
|
||||
} |
|
||||
] |
|
||||
}, |
}, |
||||
|
|
||||
{ |
{ |
||||
path: '/inventory', |
path: '/DataForm01', |
||||
name: 'inventory', |
name: 'DataForm01', |
||||
children: [ |
component: () => import('@/pages/DataForm01.vue') |
||||
{ |
|
||||
path: '/query', |
|
||||
name: 'query', |
|
||||
meta: { |
|
||||
title: '库存查询' |
|
||||
}, |
|
||||
component: () => import('@/views/inventory/query.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/account', |
|
||||
name: 'account', |
|
||||
meta: { |
|
||||
title: '帐页查询' |
|
||||
}, |
|
||||
component: () => import('@/views/inventory/account.vue') |
|
||||
} |
|
||||
] |
|
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/user', |
path: '/JsDemo', |
||||
name: 'user', |
name: 'JsDemo', |
||||
children: [ |
component: () => import('@/pages/JsDemo.vue') |
||||
{ |
|
||||
path: '/users', |
|
||||
name: 'users', |
|
||||
meta: { |
|
||||
title: '用户管理' |
|
||||
}, |
|
||||
component: () => import('@/views/user/users.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/roles', |
|
||||
name: 'roles', |
|
||||
meta: { |
|
||||
title: '角色管理' |
|
||||
}, |
|
||||
component: () => import('@/views/user/roles.vue') |
|
||||
} |
|
||||
] |
|
||||
} |
} |
||||
] |
] |
||||
}, |
}) |
||||
{ |
|
||||
path: '/tp', |
|
||||
name: 'tp', |
|
||||
component: () => import('@/components/ThreePerfView.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/editor', |
|
||||
name: 'editor', |
|
||||
// component: HomeView,
|
|
||||
component: () => import('../editor/ModelMain.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/about', |
|
||||
name: 'about', |
|
||||
// route level code-splitting
|
|
||||
// this generates a separate chunk (About.[hash].js) for this route
|
|
||||
// which is lazy-loaded when the route is visited.
|
|
||||
component: () => import('../views/AboutView.vue') |
|
||||
}, |
|
||||
|
|
||||
{ |
router.beforeEach((to, from) => { |
||||
path: '/DataForm01', |
if (to.name !== "login" && !window.globalConfig.user) { |
||||
name: 'DataForm01', |
return { name: "login" }; |
||||
component: () => import('@/pages/DataForm01.vue') |
|
||||
}, |
|
||||
{ |
|
||||
path: '/JsDemo', |
|
||||
name: 'JsDemo', |
|
||||
component: () => import('@/pages/JsDemo.vue') |
|
||||
} |
} |
||||
] |
// if (to.name === "login" && window.globalConfig.user) {
|
||||
|
// return { name: "home" };
|
||||
|
// }
|
||||
}) |
}) |
||||
|
|
||||
export default router |
export default router |
||||
|
|||||
Loading…
Reference in new issue