优化构架

This commit is contained in:
2026-08-03 18:49:18 +08:00
parent 1241d11c01
commit 44c33a6280
133 changed files with 651 additions and 603 deletions
+85
View File
@@ -0,0 +1,85 @@
import { createRouter, createWebHistory } from 'vue-router'
import AppLayout from '@/app/layouts/AppLayout.vue'
import { decideRouteAccess } from '@/core/routing/accessDecision'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { downloadRoutes } from '@/modules/downloads/routes'
import { firstLegOrderRoutes } from '@/modules/first-leg-orders/routes'
import { iamRoutes } from '@/modules/iam/routes'
import { masterDataRoutes } from '@/modules/master-data/routes'
import { useAuthStore } from '@/core/auth/auth'
import { customerRoutes } from '@/modules/customers/routes'
import { warehouseRoutes } from '@/modules/warehouses/routes'
import { prototypeModuleRoutes } from '@/prototype/routes'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/login',
name: 'login',
component: () => import('@/modules/auth/pages/LoginView.vue'),
meta: { title: '登录' },
},
{
path: '/',
component: AppLayout,
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'home',
component: () => import('@/app/pages/ModuleView.vue'),
meta: { title: '进入管理后台', description: '正在进入当前角色可访问的业务页面' },
},
...prototypeModuleRoutes,
...customerRoutes,
...warehouseRoutes,
...firstLegOrderRoutes,
...masterDataRoutes,
...downloadRoutes,
...iamRoutes,
{
path: '403',
name: 'forbidden',
component: () => import('@/app/pages/ForbiddenView.vue'),
meta: { title: '权限不足', description: '当前登录账号没有访问此页面的权限' },
},
],
},
{ path: '/:pathMatch(.*)*', redirect: '/' },
],
})
router.beforeEach((to) => {
document.title = to.meta.title ? `${to.meta.title} - 柏悦物流管理后台` : '柏悦物流管理后台'
const auth = useAuthStore()
if (to.name === 'login' && auth.isAuthenticated) {
return { name: 'home' }
}
if (!auth.isAuthenticated && !to.meta.requiresAuth) return true
const access = useAccessPreviewStore()
if (auth.isAuthenticated) access.initializeAfterLogin()
const decision = decideRouteAccess({
requiresAuth: to.meta.requiresAuth,
isAuthenticated: auth.isAuthenticated,
fullPath: to.fullPath,
permission: to.meta.permission,
hasPermission: to.meta.permission ? access.can(to.meta.permission) : true,
})
if (decision.type === 'login') {
return { name: 'login', query: { redirect: decision.redirect } }
}
if (decision.type === 'forbidden') {
return { name: 'forbidden', query: { from: decision.from }, replace: true }
}
if (to.name === 'home') {
return access.firstAccessiblePath
? { path: access.firstAccessiblePath, replace: true }
: { name: 'forbidden', replace: true }
}
return true
})
export default router