import { createRouter, createWebHistory } from 'vue-router' import BasicLayout from '../layouts/BasicLayout.vue' const routes = [ { path: '/', component: BasicLayout, children: [ { path: '', redirect: '/dashboard' }, { path: '/dashboard', name: 'Dashboard', component: () => import('../views/dashboard/Dashboard.vue'), meta: { title: '工作台' } }, { path: '/user/list', name: 'UserList', component: () => import('../views/user/UserList.vue'), meta: { title: '用户列表' } }, { path: '/deliveryman/list', name: 'DeliverymanList', component: () => import('../views/deliveryman/List.vue'), meta: { title: '配送员列表' } }, { path: '/community/list', name: 'CommunityList', component: () => import('../views/community/CommunityList.vue'), meta: { title: '小区列表' } }, { path: '/coupon/template/list', name: 'CouponTemplateList', component: () => import('../views/coupon/TemplateList.vue'), meta: { title: '优惠券模板' } }, { path: '/coupon/activity/list', name: 'CouponActivityList', component: () => import('../views/coupon/ActivityList.vue'), meta: { title: '优惠券活动' } }, { path: '/community/building', name: 'BuildingList', component: () => import('../views/community/BuildingList.vue'), meta: { title: '楼栋列表' } }, { path: 'community/station', name: 'StationList', component: () => import('../views/station/StationList.vue'), meta: { title: '驿站列表' } } ] }, { path: '/login', name: 'login', component: () => import('../views/login/Login.vue') }, { path: '/merchant', component: BasicLayout, children: [ { path: 'list', component: () => import('@/views/merchant/List.vue'), meta: { title: '商家列表' } }, { path: 'categories', component: () => import('@/views/merchant/CategoryList.vue'), meta: { title: '商家分类' } }, { path: 'products', component: () => import('@/views/merchant/ProductList.vue'), meta: { title: '商品列表' } } ] }, { path: '/system', component: BasicLayout, children: [ { path: 'logs', component: () => import('@/views/system/LogList.vue'), meta: { title: '日志查询' } } ] }, { path: '/order', component: BasicLayout, children: [ { path: 'delivery', component: () => import('@/views/order/DeliveryList.vue'), meta: { title: '配送订单' } }, { path: 'online', component: () => import('@/views/order/OnlineList.vue'), meta: { title: '买单订单' } } ] }, { path: '/finance', component: BasicLayout, children: [ { path: 'withdraw', component: () => import('@/views/finance/WithdrawList.vue'), meta: { title: '提现管理' } } ] } ] const router = createRouter({ history: createWebHistory(), routes }) router.beforeEach((to, from, next) => { const token = localStorage.getItem('token') if (to.path === '/login') { if (token) { next('/') } else { next() } } else { if (token) { next() } else { next('/login') } } document.title = to.meta.title ? `${to.meta.title} - 蜂快 · 运营管理系统` : '蜂快 · 运营管理系统' next() }) export default router