2025-11-16 15:36:26 +08:00
|
|
|
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';
|
2025-11-16 17:34:04 +08:00
|
|
|
import AlarmList from '../views/alarm/AlarmList.vue';
|
|
|
|
|
import ThresholdAlarmList from '../views/alarm/ThresholdAlarmList.vue';
|
2025-11-21 16:57:50 +08:00
|
|
|
import RawMaterialList from '../views/feed/RawMaterialList.vue';
|
2025-11-21 18:18:22 +08:00
|
|
|
import NutrientList from '../views/feed/NutrientList.vue'; // 修正拼写错误
|
|
|
|
|
import PigAgeStageList from '../views/feed/PigAgeStageList.vue'; // 导入 PigAgeStageList 组件
|
2025-11-21 18:45:38 +08:00
|
|
|
import PigBreedList from '../views/feed/PigBreedList.vue'; // 导入 PigBreedList 组件
|
2025-11-16 15:36:26 +08:00
|
|
|
|
|
|
|
|
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: '计划管理'}},
|
2025-11-16 17:34:04 +08:00
|
|
|
{path: '/alarms', component: AlarmList, meta: {requiresAuth: true, title: '告警管理'}},
|
|
|
|
|
{path: '/alarms/thresholds', component: ThresholdAlarmList, meta: {requiresAuth: true, title: '阈值告警配置'}},
|
2025-11-16 15:36:26 +08:00
|
|
|
{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: '猪群管理' }},
|
2025-11-21 16:57:50 +08:00
|
|
|
{path: '/feed/raw-materials', component: RawMaterialList, meta: {requiresAuth: true, title: '原料管理'}},
|
2025-11-21 18:18:22 +08:00
|
|
|
{path: '/feed/nutrients', component: NutrientList, meta: {requiresAuth: true, title: '营养管理'}},
|
|
|
|
|
{path: '/feed/pig-age-stages', component: PigAgeStageList, meta: {requiresAuth: true, title: '猪年龄阶段管理'}}, // 添加猪年龄阶段管理路由
|
2025-11-22 14:06:46 +08:00
|
|
|
{path: '/feed/pig-breeds', component: PigBreedList, meta: {requiresAuth: true, title: '品种管理'}}, // 添加品种管理路由
|
2025-11-16 15:36:26 +08:00
|
|
|
{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;
|