This commit is contained in:
2026-07-24 12:42:51 +08:00 Unverified
commit 67905dfa16
56 changed files with 7630 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '../stores/auth'
import AdminLayout from '../layouts/AdminLayout.vue'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/login',
name: 'login',
component: () => import('../views/LoginView.vue'),
meta: { public: true },
},
{
path: '/',
component: AdminLayout,
children: [
{ path: '', redirect: '/dashboard' },
{
path: 'dashboard',
name: 'dashboard',
component: () => import('../views/DashboardView.vue'),
},
{
path: 'base-data',
name: 'base-data',
component: () => import('../views/BaseDataView.vue'),
},
{
path: 'users',
name: 'users',
component: () => import('../views/UsersView.vue'),
meta: { roles: ['SuperAdmin'] },
},
],
},
{ path: '/:pathMatch(.*)*', redirect: '/dashboard' },
],
})
router.beforeEach((to) => {
const auth = useAuthStore()
if (!to.meta.public && !auth.isLoggedIn) {
return { name: 'login', query: { redirect: to.fullPath } }
}
if (to.name === 'login' && auth.isLoggedIn) return { name: 'dashboard' }
const roles = to.meta.roles as string[] | undefined
if (roles && !roles.some((role) => auth.user?.roles.includes(role))) {
return { name: 'dashboard' }
}
})
export default router