import { createRouter, createWebHistory } from 'vue-router' import { useUserStore } from '@/stores/user' import Layout from '@/views/Layout.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/login', name: 'Login', component: () => import('@/views/auth/Login.vue') }, { path: '/', component: Layout, redirect: '/dashboard', children: [ { path: 'dashboard', name: 'Dashboard', component: () => import('@/views/Dashboard.vue'), meta: { title: '仪表盘' } }, { path: 'system/users', name: 'Users', component: () => import('@/views/system/Users.vue'), meta: { title: '用户管理' } }, { path: 'system/roles', name: 'Roles', component: () => import('@/views/system/Roles.vue'), meta: { title: '角色管理' } }, { path: 'system/permissions', name: 'Permissions', component: () => import('@/views/system/Permissions.vue'), meta: { title: '权限管理' } }, { path: 'system/depts', name: 'Depts', component: () => import('@/views/system/Depts.vue'), meta: { title: '组织架构' } }, { path: 'system/audit', name: 'Audit', component: () => import('@/views/system/Audit.vue'), meta: { title: '审计日志' } }, { path: 'system/settings', name: 'Settings', component: () => import('@/views/system/Settings.vue'), meta: { title: '系统设置' } }, { path: 'project/list', name: 'ProjectList', component: () => import('@/views/project/List.vue'), meta: { title: '项目管理' } }, { path: 'equipment/list', name: 'EquipmentList', component: () => import('@/views/equipment/EquipmentList.vue'), meta: { title: '设备管理' } }, { path: 'equipment/detail/:id', name: 'EquipmentDetail', component: () => import('@/views/equipment/EquipmentDetail.vue'), meta: { title: '设备详情' } }, { path: 'equipment/health', name: 'EquipmentHealth', component: () => import('@/views/equipment/EquipmentHealth.vue'), meta: { title: '设备健康预测' } }, { path: 'equipment/maintenance-plan', name: 'MaintenancePlan', component: () => import('@/views/equipment/MaintenancePlan.vue'), meta: { title: '维保计划' } }, { path: 'equipment/maintenance-task', name: 'MaintenanceTask', component: () => import('@/views/equipment/MaintenanceTask.vue'), meta: { title: '维保工单' } }, { path: 'equipment/inspection', name: 'Inspection', component: () => import('@/views/equipment/Inspection.vue'), meta: { title: '巡检管理' } }, { path: 'inspection/templates', name: 'InspectionTemplates', component: () => import('@/views/inspection/TemplateList.vue'), meta: { title: '点检模板' } }, { path: 'maintenance/plans', name: 'MaintenancePlans', component: () => import('@/views/maintenance/PlanList.vue'), meta: { title: '维保计划' } }, { path: 'maintenance/tasks', name: 'MaintenanceTasks', component: () => import('@/views/maintenance/TaskList.vue'), meta: { title: '维保任务' } }, { path: 'energy/meters', name: 'EnergyMeters', component: () => import('@/views/energy/MeterList.vue'), meta: { title: '计量点管理' } }, { path: 'energy/consumption', name: 'EnergyConsumption', component: () => import('@/views/energy/ConsumptionRecord.vue'), meta: { title: '能耗录入' } }, { path: 'energy/statistics', name: 'EnergyStatistics', component: () => import('@/views/energy/EnergyStatistics.vue'), meta: { title: '能耗统计' } }, { path: 'sparepart/list', name: 'SparePartList', component: () => import('@/views/sparepart/SparePartList.vue'), meta: { title: '备件管理' } }, { path: 'sparepart/detail/:id', name: 'SparePartDetail', component: () => import('@/views/sparepart/SparePartDetail.vue'), meta: { title: '备件详情' } }, { path: 'sparepart/stock/in', name: 'SparePartInStock', component: () => import('@/views/sparepart/StockOperation.vue'), meta: { title: '备件入库' } }, { path: 'sparepart/stock/out', name: 'SparePartOutStock', component: () => import('@/views/sparepart/StockOperation.vue'), meta: { title: '备件出库' } } ] } ] }) router.beforeEach((to, _from, next) => { const userStore = useUserStore() if (to.path !== '/login' && !userStore.isLoggedIn()) { next('/login') } else { next() } }) export default router