Files
dealerhub/frontend/src/router/index.js
T

46 lines
3.1 KiB
JavaScript

import { createRouter, createWebHashHistory } from 'vue-router'
import MainLayout from '../layouts/MainLayout.vue'
const routes = [
{ path: '/login', name: 'login', component: () => import('../pages/Login.vue') },
{ path: '/register', name: 'register', component: () => import('../pages/Register.vue') },
{ path: '/storefront', name: 'storefront', component: () => import('../pages/Storefront.vue'), meta: { title: '订货商城' } },
{ path: '/storefront-admin', name: 'storefrontAdmin', component: () => import('../pages/StorefrontAdmin.vue'), meta: { title: '商城订单' } },
{
path: '/',
component: MainLayout,
redirect: '/dashboard',
children: [
{ path: 'dashboard', name: 'dashboard', component: () => import('../pages/Dashboard.vue'), meta: { title: '经营大盘' } },
{ path: 'products', name: 'products', component: () => import('../pages/Products.vue'), meta: { title: '商品中心' } },
{ path: 'customers', name: 'customers', component: () => import('../pages/Customers.vue'), meta: { title: '客户档案' } },
{ path: 'stocks', name: 'stocks', component: () => import('../pages/Stocks.vue'), meta: { title: '库存查询' } },
{ path: 'batches', name: 'batches', component: () => import('../pages/Batches.vue'), meta: { title: '批次效期' } },
{ path: 'sales-bills', name: 'salesBills', component: () => import('../pages/SalesBills.vue'), meta: { title: '销售开单' } },
{ path: 'purchase-bills', name: 'purchaseBills', component: () => import('../pages/PurchaseBills.vue'), meta: { title: '采购开单' } },
{ path: 'finance/vouchers', name: 'vouchers', component: () => import('../pages/Vouchers.vue'), meta: { title: '记账凭证' } },
{ path: 'finance/receivables', name: 'receivables', component: () => import('../pages/Receivables.vue'), meta: { title: '应收账款' } },
{ path: 'finance/payables', name: 'payables', component: () => import('../pages/Payables.vue'), meta: { title: '应付账款' } },
{ path: 'finance/reports', name: 'financeReports', component: () => import('../pages/FinanceReports.vue'), meta: { title: '财务报表' } },
{ path: 'channel', name: 'channel', component: () => import('../pages/Channel.vue'), meta: { title: '电商渠道' } },
{ path: 'notify', name: 'notify', component: () => import('../pages/Notify.vue'), meta: { title: '消息预警' } },
{ path: 'openapi-keys', name: 'openapiKeys', component: () => import('../pages/OpenApiKeys.vue'), meta: { title: '开放平台' } },
{ path: 'billing', name: 'billing', component: () => import('../pages/Billing.vue'), meta: { title: '套餐与用量' } },
{ path: 'audit-logs', name: 'auditLogs', component: () => import('../pages/AuditLogs.vue'), meta: { title: '操作轨迹' } },
],
},
]
const router = createRouter({ history: createWebHashHistory(), routes })
const PUBLIC_ROUTES = new Set(['login', 'storefront'])
router.beforeEach((to) => {
const token = localStorage.getItem('token')
if (!PUBLIC_ROUTES.has(to.name) && !token) return { name: 'login' }
if (to.name === 'login' && token) return { name: 'dashboard' }
return true
})
export default router