import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '@/stores/auth' const router = createRouter({ history: createWebHistory(), routes: [ { path: '/login', name: 'Login', component: () => import('@/views/Login.vue'), meta: { public: true }, }, { path: '/bind-wecom', name: 'BindWecom', component: () => import('@/views/BindWecom.vue'), meta: { public: true }, }, // Mobile routes (manager-facing) { path: '/m', component: () => import('@/components/MobileLayout.vue'), children: [ { path: '', name: 'MobileHome', component: () => import('@/views/mobile/Home.vue') }, { path: 'visit/new', name: 'VisitForm', component: () => import('@/views/mobile/VisitForm.vue') }, { path: 'visit/:id/edit', name: 'VisitEdit', component: () => import('@/views/mobile/VisitForm.vue') }, { path: 'work-plan/new', name: 'WorkPlanForm', component: () => import('@/views/mobile/WorkPlanForm.vue') }, { path: 'mini-biz/new', name: 'MiniBusinessForm', component: () => import('@/views/mobile/MiniBusinessForm.vue') }, { path: 'key-visit/new', name: 'KeyVisitForm', component: () => import('@/views/mobile/KeyVisitForm.vue') }, { path: 'note/new', name: 'DailyNoteForm', component: () => import('@/views/mobile/DailyNoteForm.vue') }, { path: 'note/:id/edit', name: 'DailyNoteEdit', component: () => import('@/views/mobile/DailyNoteForm.vue') }, ], }, // Desktop routes (director/leader-facing) { path: '/', component: () => import('@/components/DesktopLayout.vue'), children: [ { path: '', name: 'Dashboard', component: () => import('@/views/desktop/Dashboard.vue') }, { path: 'weekly-report', name: 'WeeklyReport', component: () => import('@/views/desktop/WeeklyReport.vue') }, { path: 'light-board', name: 'LightBoard', component: () => import('@/views/desktop/LightBoard.vue') }, { path: 'work-plans', name: 'WorkPlans', component: () => import('@/views/desktop/WorkPlans.vue') }, { path: 'mini-business', name: 'MiniBusiness', component: () => import('@/views/desktop/MiniBusiness.vue') }, { path: 'key-visits', name: 'KeyVisits', component: () => import('@/views/desktop/KeyVisits.vue') }, { path: 'workspace', name: 'ManagerWorkspace', component: () => import('@/views/desktop/ManagerWorkspace.vue') }, { path: 'customers', name: 'CustomerManage', component: () => import('@/views/desktop/CustomerManage.vue') }, { path: 'users', name: 'UserManage', component: () => import('@/views/desktop/UserManage.vue') }, { path: 'settings', name: 'Settings', component: () => import('@/views/desktop/Settings.vue') }, ], }, ], }) router.beforeEach((to, _from, next) => { const auth = useAuthStore() if (to.meta.public) { next() return } if (!auth.isLoggedIn) { next('/login') return } next() }) export default router