119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
import { getAdminRole, hasAdminSession } from '@/utils/admin-auth'
|
|
|
|
const router = createRouter({
|
|
history: createWebHashHistory(),
|
|
routes: [
|
|
{
|
|
path: '/',
|
|
redirect: '/admin/dashboard',
|
|
},
|
|
{
|
|
path: '/claim/:token',
|
|
component: () => import('@/views/claim/ClaimView.vue'),
|
|
},
|
|
{
|
|
path: '/admin',
|
|
redirect: '/admin/dashboard',
|
|
},
|
|
{
|
|
path: '/admin/login',
|
|
component: () => import('@/views/admin/auth/AdminLoginView.vue'),
|
|
},
|
|
{
|
|
path: '/admin',
|
|
component: () => import('@/views/admin/layout/AdminLayout.vue'),
|
|
children: [
|
|
{
|
|
path: '',
|
|
redirect: '/admin/dashboard',
|
|
},
|
|
{
|
|
path: 'dashboard',
|
|
component: () => import('@/views/admin/dashboard/AdminDashboardView.vue'),
|
|
},
|
|
{
|
|
path: 'users',
|
|
meta: { allowedRoles: ['admin'] },
|
|
component: () => import('@/views/admin/users/AdminUsersView.vue'),
|
|
},
|
|
{
|
|
path: 'orders',
|
|
component: () => import('@/views/admin/orders/AdminOrdersView.vue'),
|
|
},
|
|
{
|
|
path: 'orders/:orderId',
|
|
component: () => import('@/views/admin/orders/AdminOrderDetailView.vue'),
|
|
},
|
|
{
|
|
path: 'tasks',
|
|
component: () => import('@/views/admin/tasks/AdminTasksView.vue'),
|
|
},
|
|
{
|
|
path: 'tasks/:taskId',
|
|
component: () => import('@/views/admin/tasks/AdminTaskDetailView.vue'),
|
|
},
|
|
{
|
|
path: 'cloudtentacles-records',
|
|
component: () =>
|
|
import('@/views/admin/cloudtentacles-records/AdminCloudtentaclesRecordsView.vue'),
|
|
},
|
|
{
|
|
path: 'platform-shops',
|
|
meta: { allowedRoles: ['admin'] },
|
|
component: () => import('@/views/admin/platform-shops/AdminPlatformShopsView.vue'),
|
|
},
|
|
{
|
|
path: 'platform-fulfillment',
|
|
meta: { allowedRoles: ['admin'] },
|
|
component: () => import('@/views/admin/fulfillment/AdminFulfillmentConfigHubView.vue'),
|
|
},
|
|
{
|
|
path: 'platform-kuaishou-cloud-fulfillment',
|
|
meta: { allowedRoles: ['admin'] },
|
|
redirect: '/admin/platform-fulfillment?tab=kuaishou-cloud',
|
|
},
|
|
{
|
|
path: 'audit-logs',
|
|
meta: { allowedRoles: ['admin'] },
|
|
component: () => import('@/views/admin/audit-logs/AdminAuditLogsView.vue'),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
component: () => import('@/views/NotFoundView.vue'),
|
|
},
|
|
],
|
|
})
|
|
|
|
router.beforeEach((to) => {
|
|
if (!to.path.startsWith('/admin')) {
|
|
return true
|
|
}
|
|
|
|
if (to.path === '/admin/login') {
|
|
if (hasAdminSession()) {
|
|
return '/admin/dashboard'
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
if (!hasAdminSession()) {
|
|
return '/admin/login'
|
|
}
|
|
|
|
const allowedRoles = to.matched
|
|
.map((record) => (record.meta?.allowedRoles as string[] | undefined) || [])
|
|
.find((roles) => Array.isArray(roles) && roles.length > 0)
|
|
|
|
if (allowedRoles && !allowedRoles.includes(getAdminRole())) {
|
|
return '/admin/dashboard'
|
|
}
|
|
|
|
return true
|
|
})
|
|
|
|
export default router
|