import { createRouter, createWebHistory } from 'vue-router'; import NProgress from 'nprogress'; // progress bar import 'nprogress/nprogress.css'; import { isLogin } from '@/utils/auth'; import { appRoutes } from './routes'; import { REDIRECT_MAIN, NOT_FOUND_ROUTE } from './routes/base'; import createRouteGuard from './guard'; NProgress.configure({ showSpinner: false, speed: 280, minimum: 0.12, trickleSpeed: 160, }); // NProgress Configuration const router = createRouter({ history: createWebHistory(), routes: [ { path: '/', name: 'siteRoot', component: () => import('@/views/site/index.vue'), meta: { requiresAuth: false, hideInMenu: true, }, }, { path: '/login', name: 'login', component: () => import('@/views/login/index.vue'), meta: { requiresAuth: false, loginPortal: 'customer', }, }, { path: '/admin', name: 'adminLogin', component: () => import('@/views/login/index.vue'), meta: { requiresAuth: false, loginPortal: 'admin', }, }, { path: '/track/query', name: 'H5TrackQuery', component: () => import('@/views/h5/track-query/index.vue'), meta: { requiresAuth: false, hideInMenu: true, }, }, // 登录独立壳:不挂 customer-center layout,避免同步拉下单树导致首屏慢/闪乱 { path: '/h5/login', name: 'H5Login', component: () => import('@/views/h5/customer-center/login/index.vue'), meta: { requiresAuth: false, hideInMenu: true, customerPortalOnly: true, locale: 'h5.login.title', }, }, // 管理端 H5:须注册在客户 /h5 之前,避免被客户中心 catch-all 吞掉 { path: '/h5/admin/login', name: 'H5AdminLogin', component: () => import('@/views/h5/admin-center/login/index.vue'), meta: { requiresAuth: false, hideInMenu: true, adminPortalOnly: true, locale: 'h5Admin.login.title', }, }, { path: '/h5/admin', name: 'H5AdminCenter', component: () => import('@/views/h5/admin-center/layout.vue'), meta: { requiresAuth: false, hideInMenu: true, adminPortalOnly: true, }, children: [ { path: '', name: 'H5AdminCenterIndex', redirect: () => { const token = localStorage.getItem('rbac_access_token') || localStorage.getItem('token'); return token ? '/h5/admin/workplace' : '/h5/admin/login'; }, }, { path: 'workplace', name: 'H5AdminWorkplace', component: () => import('@/views/h5/admin-center/workplace/index.vue'), meta: { requiresAuth: true, locale: 'h5Admin.tab.workplace', h5HideHeader: true, adminPortalOnly: true, }, }, { path: 'monitor', name: 'H5AdminMonitor', component: () => import('@/views/h5/admin-center/monitor/index.vue'), meta: { requiresAuth: true, locale: 'h5Admin.tab.monitor', h5HideHeader: true, adminPortalOnly: true, }, }, { path: 'orders', name: 'H5AdminOrders', component: () => import('@/views/h5/admin-center/orders/index.vue'), meta: { requiresAuth: true, locale: 'h5Admin.tab.orders', h5HideHeader: true, adminPortalOnly: true, }, }, { path: 'orders/:id', name: 'H5AdminOrderDetail', component: () => import('@/views/h5/admin-center/orders/detail.vue'), meta: { requiresAuth: true, locale: 'h5.orders.detail.title', h5HideTabBar: true, h5HideHeader: true, adminPortalOnly: true, }, }, { path: 'me', name: 'H5AdminMe', component: () => import('@/views/h5/admin-center/me/index.vue'), meta: { requiresAuth: true, locale: 'h5Admin.tab.me', h5HideHeader: true, adminPortalOnly: true, }, }, { path: 'recharge', name: 'H5AdminRecharge', component: () => import('@/views/h5/admin-center/recharge/index.vue'), meta: { requiresAuth: true, locale: 'h5Admin.recharge.title', h5HideHeader: true, adminPortalOnly: true, }, }, { path: ':pathMatch(.*)*', name: 'H5AdminCenterFallback', redirect: () => { const token = localStorage.getItem('rbac_access_token') || localStorage.getItem('token'); return token ? '/h5/admin/workplace' : '/h5/admin/login'; }, }, ], }, { path: '/h5', name: 'H5CustomerCenter', component: () => import('@/views/h5/customer-center/layout.vue'), meta: { requiresAuth: false, hideInMenu: true, customerPortalOnly: true, }, children: [ { path: '', name: 'H5CustomerCenterIndex', redirect: () => (isLogin() ? '/h5/orders' : '/h5/price'), }, { path: 'assistant', name: 'H5Assistant', component: () => import('@/views/h5/customer-center/assistant/index.vue'), meta: { requiresAuth: true, h5GuestOk: true, locale: 'h5.tab.assistant', h5HideHeader: true, }, }, { path: 'price', name: 'H5Price', component: () => import('@/views/h5/customer-center/price/index.vue'), meta: { requiresAuth: true, h5GuestOk: true, locale: 'h5.tab.price', h5HideHeader: true, }, }, { path: 'orders', name: 'H5Orders', component: () => import('@/views/h5/customer-center/orders/index.vue'), meta: { requiresAuth: true, h5GuestOk: true, locale: 'h5.tab.orders', h5HideHeader: true, }, }, { path: 'orders/:id', name: 'H5OrderDetail', component: () => import('@/views/h5/customer-center/orders/detail.vue'), meta: { requiresAuth: true, locale: 'h5.orders.detail.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'me', name: 'H5Me', component: () => import('@/views/h5/customer-center/me/index.vue'), meta: { requiresAuth: true, h5GuestOk: true, locale: 'h5.tab.me', h5HideHeader: true, }, }, { path: 'storeOrders', name: 'H5StoreOrders', component: () => import('@/views/h5/customer-center/store-orders/index.vue'), meta: { requiresAuth: true, locale: 'h5.storeOrders.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'storeOrders/:id', name: 'H5StoreOrderDetail', component: () => import('@/views/h5/customer-center/store-orders/detail.vue'), meta: { requiresAuth: true, locale: 'h5.storeOrders.detail.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'recharge', name: 'H5Recharge', component: () => import('@/views/h5/customer-center/recharge/index.vue'), meta: { requiresAuth: true, locale: 'h5.recharge.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'place-order', name: 'H5PlaceOrder', component: () => import('@/views/h5/customer-center/place-order/index.vue'), meta: { requiresAuth: true, locale: 'h5.placeOrder.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'coupons', name: 'H5Coupons', component: () => import('@/views/h5/customer-center/coupons/index.vue'), meta: { requiresAuth: true, locale: 'h5.coupons.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'invite', name: 'H5Invite', component: () => import('@/views/h5/customer-center/invite/index.vue'), meta: { requiresAuth: true, locale: 'h5.invite.title', h5HideTabBar: true, h5HideHeader: true, }, }, { path: 'commission', name: 'H5Commission', component: () => import('@/views/h5/customer-center/commission/index.vue'), meta: { requiresAuth: true, locale: 'h5.commission.title', h5HideTabBar: true, h5HideHeader: true, }, }, // 未知 /h5/* 回落客户中心,避免空白页 { path: ':pathMatch(.*)*', name: 'H5CustomerCenterFallback', redirect: () => { const token = localStorage.getItem('rbac_access_token') || localStorage.getItem('token'); return token ? '/h5/orders' : '/h5/price'; }, }, ], }, { path: '/wechat/register', name: 'WechatRegister', component: () => import('@/views/wechat/register/index.vue'), meta: { requiresAuth: false, hideInMenu: true, }, }, { path: '/register', name: 'CustomerRegister', component: () => import('@/views/register/index.vue'), meta: { requiresAuth: false, hideInMenu: true, }, }, { path: '/wechat/bind', name: 'WechatBind', component: () => import('@/views/wechat/bind/index.vue'), meta: { requiresAuth: false, hideInMenu: true, }, }, { path: '/oauth/platform-store/:platform', name: 'PlatformStoreOAuthCallback', component: () => import('@/views/order/platformStore/oauthCallback.vue'), meta: { requiresAuth: true, hideInMenu: true, }, }, { path: '/Plugin/AddPackage', name: 'PluginAddPackage', component: () => import('@/views/plugin/AddPackage.vue'), meta: { requiresAuth: true, hideInMenu: true, }, }, ...appRoutes, REDIRECT_MAIN, NOT_FOUND_ROUTE, ], scrollBehavior(to) { if (to.path === '/' && to.hash) { return false; } return { top: 0 }; }, }); createRouteGuard(router); export default router;