import { createRouter, createWebHistory } from 'vue-router' import MainLayout from '../layouts/MainLayout.vue' const routes = [ { path: '/login', name: 'Login', component: () => import('../pages/Login.vue'), meta: { title: '登录' } }, { path: '/', component: MainLayout, children: [ { path: '', redirect: '/work-order' }, { path: 'work-order', name: 'WorkOrder', component: () => import('../pages/WorkOrder.vue'), meta: { title: '工单管理' } }, { path: 'daily-plan', name: 'DailyPlan', component: () => import('../pages/DailyPlan.vue'), meta: { title: '日排产' } }, { path: 'bom', name: 'Bom', component: () => import('../pages/Bom.vue'), meta: { title: '物料清单' } }, { path: 'material-request', name: 'MaterialRequest', component: () => import('../pages/MaterialRequest.vue'), meta: { title: '备料单' } }, { path: 'plc-send', name: 'PlcSend', component: () => import('../pages/PlcSend.vue'), meta: { title: '工位组合下发' } }, { path: 'torque', name: 'Torque', component: () => import('../pages/Torque.vue'), meta: { title: '拧紧查询' } }, { path: 'process-flow', name: 'ProcessFlow', component: () => import('../pages/ProcessFlow.vue'), meta: { title: '工艺流程' } }, { path: 'station', name: 'Station', component: () => import('../pages/Station.vue'), meta: { title: '关联工位' } }, { path: 'performance', name: 'Performance', component: () => import('../pages/Performance.vue'), meta: { title: '绩效报表' } }, { path: 'inspect', name: 'Inspect', component: () => import('../pages/Inspect.vue'), meta: { title: '巡检终端' } }, { path: 'scan', name: 'Scan', component: () => import('../pages/Scan.vue'), meta: { title: '手动报工' } }, { path: 'trace', name: 'Trace', component: () => import('../pages/Trace.vue'), meta: { title: '工件追溯' } }, { path: 'product-type', name: 'ProductType', component: () => import('../pages/ProductType.vue'), meta: { title: '产品型号' } }, { path: 'process-route', name: 'ProcessRoute', component: () => import('../pages/ProcessRoute.vue'), meta: { title: '工艺路线' } }, { path: 'event-log', name: 'EventLog', component: () => import('../pages/EventLog.vue'), meta: { title: '操作日志' } }, { path: 'change-password', name: 'ChangePassword', component: () => import('../pages/ChangePassword.vue'), meta: { title: '修改密码' } }, { path: 'account', name: 'AccountManage', component: () => import('../pages/AccountManage.vue'), meta: { title: '账号管理' } }, { path: 'role', name: 'RoleManage', component: () => import('../pages/RoleManage.vue'), meta: { title: '角色管理' } } ] }, { path: '/:pathMatch(.*)*', redirect: '/work-order' } ] const router = createRouter({ history: createWebHistory(), routes }) router.beforeEach((to) => { if (to.path !== '/login' && !localStorage.getItem('token')) { return { path: '/login', query: to.fullPath ? { redirect: to.fullPath } : {} } } }) router.afterEach((to) => { document.title = to.meta?.title ? `${to.meta.title} - MES 产线控制` : 'MES 产线控制' }) export default router