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: '/display', name: 'Display', component: () => import('../pages/Display.vue'), meta: { title: '库存大屏' } }, { path: '/', component: MainLayout, children: [ { path: '', name: 'Dashboard', component: () => import('../pages/Dashboard.vue'), meta: { title: '工作台', keepAlive: true, componentName: 'Dashboard' } }, { path: 'inbound', name: 'Inbound', component: () => import('../pages/Inbound.vue'), meta: { title: '入库管理', keepAlive: true, componentName: 'Inbound' } }, { path: 'outbound', name: 'Outbound', component: () => import('../pages/Outbound.vue'), meta: { title: '出库管理', keepAlive: true, componentName: 'Outbound' } }, { path: 'inventory', name: 'Inventory', component: () => import('../pages/Inventory.vue'), meta: { title: '库存查询', keepAlive: true, componentName: 'Inventory' } }, { path: 'inspection', name: 'Inspection', component: () => import('../pages/Inspection.vue'), meta: { title: '质量检验', keepAlive: true, componentName: 'Inspection' } }, { path: 'stocktake', name: 'Stocktake', component: () => import('../pages/Stocktake.vue'), meta: { title: '库存盘点', keepAlive: true, componentName: 'Stocktake' } }, { path: 'semi', name: 'Semi', component: () => import('../pages/Semi.vue'), meta: { title: '半成品/成品', keepAlive: true, componentName: 'Semi' } }, { path: 'ledger', name: 'Ledger', component: () => import('../pages/Ledger.vue'), meta: { title: '备料台账', keepAlive: true, componentName: 'Ledger' } }, { path: 'zone', name: 'Zone', component: () => import('../pages/BaseData.vue'), props: { mode: 'zone' }, meta: { title: '区域维护', keepAlive: true, componentName: 'BaseData' } }, { path: 'material', name: 'Material', component: () => import('../pages/BaseData.vue'), props: { mode: 'material' }, meta: { title: '物料档案', keepAlive: true, componentName: 'BaseData' } }, { path: 'change-password', name: 'ChangePassword', component: () => import('../pages/ChangePassword.vue'), meta: { title: '修改密码' } }, { path: 'users', name: 'UserManage', component: () => import('../pages/UserManage.vue'), meta: { title: '账号管理', keepAlive: true, componentName: 'UserManage' } }, { path: 'roles', name: 'RoleManage', component: () => import('../pages/RoleManage.vue'), meta: { title: '角色管理', keepAlive: true, componentName: 'RoleManage' } } ] }, { path: '/:pathMatch(.*)*', redirect: '/' } ] const router = createRouter({ history: createWebHistory(), routes }) // 路由守卫:除 /login 和 /display 外校验 token router.beforeEach((to) => { if (to.path !== '/login' && to.path !== '/display' && !to.path.startsWith('/display')) { if (!localStorage.getItem('token')) { return { path: '/login', query: to.fullPath ? { redirect: to.fullPath } : {} } } } }) router.afterEach((to) => { document.title = to.meta?.title ? `${to.meta.title} - 库房客户端` : '库房客户端' }) export default router