完成JC-ArtList与JC-Salon端侧清理和统一命名
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import {
|
||||
canAccessAdminRoute,
|
||||
clearAdminBootstrapSession,
|
||||
ensureAdminAuthBootstrap,
|
||||
getAdminBootstrapSnapshot,
|
||||
resolveAdminLandingPath,
|
||||
} from '@/utils/admin-auth-bootstrap'
|
||||
|
||||
const pageNames = [
|
||||
['', 'HomeView', 'admin', undefined], ['dashboard', 'DashboardView', 'admin-dashboard', 'dashboard:view'],
|
||||
['users', 'UsersView', 'admin-users', 'user:view'], ['products', 'ProductsView', 'admin-products', 'product:view'],
|
||||
['coupons', 'CouponsView', 'admin-coupons', 'coupon:view'], ['comments', 'CommentsView', 'admin-comments', 'comment:view'],
|
||||
['shops', 'ShopsView', 'admin-shops', 'shop:view'], ['permissions', 'PermissionsView', 'admin-permissions', 'permission:view'],
|
||||
['orders', 'OrdersView', 'admin-orders', 'order:view'], ['schedules', 'SchedulesView', 'admin-schedules', 'schedule:view'],
|
||||
['after-sales', 'AfterSalesView', 'admin-after-sales', 'after_sale:view'], ['inventory', 'InventoryView', 'admin-inventory', 'inventory:view'],
|
||||
['campaigns', 'CampaignsView', 'admin-campaigns', 'campaign:view'], ['manage', 'ManageView', 'admin-manage', undefined],
|
||||
['profile', 'ProfileView', 'admin-profile', undefined], ['tags', 'TagsView', 'admin-tags', 'tag:view'],
|
||||
['nail-artists', 'NailArtistsView', 'admin-nail-artists', 'nail_artist:view'], ['messages', 'SystemMessagesView', 'admin-messages', 'message:view'],
|
||||
['announcements', 'AnnouncementsView', 'admin-announcements', 'announcement:view'], ['vip-recharge-plans', 'VipRechargePlansView', 'admin-vip-recharge-plans', 'user:vip:manage'],
|
||||
['messagehub-push-configs', 'MessageHubPushConfigsView', 'admin-messagehub-push-configs', 'messagehub:config:manage'],
|
||||
['legal-agreements', 'LegalAgreementsView', 'admin-legal-agreements', 'legal_agreement:manage']
|
||||
] as const
|
||||
|
||||
const routes = [
|
||||
{ path: '/admin/login', name: 'admin-login', component: () => import('../views/admin/AdminLoginView.vue'), meta: { requiresAuth: false, isAdmin: true, hideNav: true } },
|
||||
{
|
||||
path: '/admin', component: () => import('../views/admin/AdminLayout.vue'), meta: { requiresAuth: true, isAdmin: true, hideNav: true },
|
||||
children: pageNames.map(([path, view, name, permissionCode]) => ({
|
||||
path, name, component: () => import(`../views/admin/${view}.vue`), meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode }
|
||||
}))
|
||||
},
|
||||
{ path: '/:pathMatch(.*)*', name: 'not-found', component: () => import('../views/NotFoundView.vue'), meta: { requiresAuth: false, isAdmin: true, hideNav: true } }
|
||||
]
|
||||
|
||||
const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes })
|
||||
|
||||
router.beforeEach(async to => {
|
||||
if (!to.meta.isAdmin) return true
|
||||
const snapshot = getAdminBootstrapSnapshot()
|
||||
if (to.path === '/admin/login') {
|
||||
if (!snapshot.token || !snapshot.userInfo) return true
|
||||
return (await ensureAdminAuthBootstrap()) === 'ready' ? resolveAdminLandingPath() : true
|
||||
}
|
||||
if (!snapshot.token || !snapshot.userInfo) {
|
||||
clearAdminBootstrapSession()
|
||||
return '/admin/login'
|
||||
}
|
||||
if (await ensureAdminAuthBootstrap() !== 'ready') return '/admin/login'
|
||||
return canAccessAdminRoute(to.path, to.meta.permissionCode as string | undefined) ? true : resolveAdminLandingPath()
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user