import {createRouter, createWebHistory} from 'vue-router'; import Home from '../views/home/Home.vue'; import DeviceList from '../views/device/DeviceList.vue'; import PlanList from '../views/plan/PlanList.vue'; import LoginForm from '../views/home/LoginForm.vue'; import DeviceTemplateList from '../views/device/DeviceTemplateList.vue'; import PigFarmManagementView from '../views/pms/PigFarmManagementView.vue'; import PigBatchManagementView from '../views/pms/PigBatchManagementView.vue'; import DeviceCommandLogView from '../views/monitor/DeviceCommandLogView.vue'; import MedicationLogsView from '../views/monitor/MedicationLogsView.vue'; import NotificationLogView from '../views/monitor/NotificationLogView.vue'; import PendingCollectionsView from '../views/monitor/PendingCollectionsView.vue'; import PigBatchLogsView from '../views/monitor/PigBatchLogsView.vue'; import PigPurchasesView from '../views/monitor/PigPurchasesView.vue'; import PigSalesView from '../views/monitor/PigSalesView.vue'; import PigSickLogsView from '../views/monitor/PigSickLogsView.vue'; import PigTransferLogsView from '../views/monitor/PigTransferLogsView.vue'; import PlanExecutionLogsView from '../views/monitor/PlanExecutionLogsView.vue'; import SensorDataView from '../views/monitor/SensorDataView.vue'; import TaskExecutionLogsView from '../views/monitor/TaskExecutionLogsView.vue'; import UserActionLogsView from '../views/monitor/UserActionLogsView.vue'; import WeighingBatchesView from '../views/monitor/WeighingBatchesView.vue'; import WeighingRecordsView from '../views/monitor/WeighingRecordsView.vue'; import AlarmList from '../views/alarm/AlarmList.vue'; import ThresholdAlarmList from '../views/alarm/ThresholdAlarmList.vue'; import RawMaterialList from '../views/feed/RawMaterialList.vue'; import NutrientList from '../views/feed/NutrientList.vue'; // 导入 NutrientList 组件 const routes = [ {path: '/', component: Home, meta: {requiresAuth: true, title: '系统首页'}}, {path: '/devices', component: DeviceList, meta: {requiresAuth: true, title: '设备管理'}}, {path: '/device-templates', component: DeviceTemplateList, meta: {requiresAuth: true, title: '设备模板管理'}}, {path: '/plans', component: PlanList, meta: {requiresAuth: true, title: '计划管理'}}, {path: '/alarms', component: AlarmList, meta: {requiresAuth: true, title: '告警管理'}}, {path: '/alarms/thresholds', component: ThresholdAlarmList, meta: {requiresAuth: true, title: '阈值告警配置'}}, {path: '/login', component: LoginForm}, {path: '/pms/farm-management', name: 'PigFarmManagement', component: PigFarmManagementView, meta: { requiresAuth: true, title: '栏舍管理' }}, {path: '/pms/batch-management', name: 'PigBatchManagement', component: PigBatchManagementView, meta: { requiresAuth: true, title: '猪群管理' }}, {path: '/feed/raw-materials', component: RawMaterialList, meta: {requiresAuth: true, title: '原料管理'}}, {path: '/feed/nutrients', component: NutrientList, meta: {requiresAuth: true, title: '营养管理'}}, // 添加营养管理路由 {path: '/monitor/device-command-logs', component: DeviceCommandLogView, meta: {requiresAuth: true, title: '设备命令日志'}}, {path: '/monitor/medication-logs', component: MedicationLogsView, meta: {requiresAuth: true, title: '用药记录'}}, {path: '/monitor/notifications', component: NotificationLogView, meta: {requiresAuth: true, title: '通知记录'}}, {path: '/monitor/pending-collections', component: PendingCollectionsView, meta: {requiresAuth: true, title: '待采集请求'}}, {path: '/monitor/pig-batch-logs', component: PigBatchLogsView, meta: {requiresAuth: true, title: '猪批次日志'}}, {path: '/monitor/pig-purchases', component: PigPurchasesView, meta: {requiresAuth: true, title: '猪只采购记录'}}, {path: '/monitor/pig-sales', component: PigSalesView, meta: {requiresAuth: true, title: '猪只售卖记录'}}, {path: '/monitor/pig-sick-logs', component: PigSickLogsView, meta: {requiresAuth: true, title: '病猪日志'}}, {path: '/monitor/pig-transfer-logs', component: PigTransferLogsView, meta: {requiresAuth: true, title: '猪只迁移日志'}}, {path: '/monitor/plan-execution-logs', component: PlanExecutionLogsView, meta: {requiresAuth: true, title: '计划执行日志'}}, {path: '/monitor/sensor-data', component: SensorDataView, meta: {requiresAuth: true, title: '传感器数据'}}, {path: '/monitor/task-execution-logs', component: TaskExecutionLogsView, meta: {requiresAuth: true, title: '任务执行日志'}}, {path: '/monitor/user-action-logs', component: UserActionLogsView, meta: {requiresAuth: true, title: '用户操作日志'}}, {path: '/monitor/weighing-batches', component: WeighingBatchesView, meta: {requiresAuth: true, title: '批次称重记录'}}, {path: '/monitor/weighing-records', component: WeighingRecordsView, meta: {requiresAuth: true, title: '单次称重记录'}}, ]; const router = createRouter({ history: createWebHistory(), routes }); router.beforeEach((to, from, next) => { const loggedIn = localStorage.getItem('jwt_token'); if (to.matched.some(record => record.meta.requiresAuth) && !loggedIn) { next('/login'); } else if (to.path === '/login' && loggedIn) { next('/'); } else { next(); } }); export default router;