This commit is contained in:
2025-04-17 23:32:39 +09:00
commit 5b719b6766
105 changed files with 25653 additions and 0 deletions
+180
View File
@@ -0,0 +1,180 @@
import { createRouter, createWebHistory } from 'vue-router';
// 인증 관련 뷰
const Login = () => import('@/views/auth/Login.vue');
const Profile = () => import('@/views/auth/Profile.vue');
// 관리자 뷰
const AdminDashboard = () => import('@/views/admin/Dashboard.vue');
const ClubManagement = () => import('@/views/admin/ClubManagement.vue');
const UserManagement = () => import('@/views/admin/UserManagement.vue');
const SubscriptionManagement = () => import('@/views/admin/SubscriptionManagement.vue');
// 클럽 뷰
const ClubDashboard = () => import('@/views/club/Dashboard.vue');
const MemberManagement = () => import('@/views/club/MemberManagement.vue');
const Statistics = () => import('@/views/club/Statistics.vue');
const EventManagement = () => import('@/views/club/EventManagement.vue');
const EventCalendar = () => import('@/views/club/EventCalendar.vue');
const ScoreManagement = () => import('@/views/club/ScoreManagement.vue');
const UserClubCreate = () => import('@/views/club/ClubCreate.vue');
// 구독 관리 컴포넌트 import
const ClubSubscriptionManagement = () => import('@/views/club/subscription/SubscriptionManagement.vue');
const routes = [
// 공개 경로
{
path: '/',
redirect: '/login'
},
{
path: '/login',
name: 'Login',
component: Login,
meta: { requiresAuth: false }
},
// 인증 필요 경로
{
path: '/profile',
name: 'Profile',
component: Profile,
meta: { requiresAuth: true }
},
// 관리자 경로
{
path: '/admin',
name: 'AdminDashboard',
component: AdminDashboard,
meta: { requiresAuth: true, requiresAdmin: true }
},
{
path: '/admin/clubs',
name: 'ClubManagement',
component: ClubManagement,
meta: { requiresAuth: true, requiresAdmin: true }
},
{
path: '/admin/users',
name: 'UserManagement',
component: UserManagement,
meta: { requiresAuth: true, requiresAdmin: true }
},
{
path: '/admin/subscriptions',
name: 'SubscriptionManagement',
component: SubscriptionManagement,
meta: { requiresAuth: true, requiresAdmin: true }
},
// 클럽 경로
{
path: '/club',
component: () => import('@/layouts/ClubLayout.vue'),
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'ClubDashboard',
component: () => import('@/views/club/Dashboard.vue')
},
{
path: 'members',
name: 'MemberManagement',
component: () => import('@/views/club/MemberManagement.vue')
},
{
path: 'events',
name: 'EventManagement',
component: () => import('@/views/club/EventManagement.vue')
},
{
path: 'events/calendar',
name: 'EventCalendar',
component: () => import('@/views/club/EventCalendar.vue')
},
{
path: 'events/:eventId/scores',
name: 'ScoreManagement',
component: () => import('@/views/club/ScoreManagement.vue'),
props: true
},
{
path: 'statistics',
name: 'Statistics',
component: () => import('@/views/club/Statistics.vue')
},
{
path: 'subscription',
name: 'ClubSubscription',
component: ClubSubscriptionManagement,
meta: {
requiresAuth: true,
requiredRoles: ['모임장', '운영진']
}
}
]
},
{
path: '/club/create',
name: 'UserClubCreate',
component: () => import('@/views/club/ClubCreate.vue'),
meta: { requiresAuth: true }
}
];
const router = createRouter({
history: createWebHistory(),
routes,
linkActiveClass: 'router-link-active',
linkExactActiveClass: 'router-link-active'
});
// 네비게이션 가드
router.beforeEach(async (to, from, next) => {
const isAuthenticated = !!localStorage.getItem('token');
const userRole = localStorage.getItem('userRole');
const clubId = localStorage.getItem('clubId');
const userClubRole = localStorage.getItem('userClubRole');
// 인증이 필요한 페이지인데 로그인하지 않은 경우
if (to.meta.requiresAuth && !isAuthenticated) {
next({ name: 'Login' });
return;
}
// 관리자 권한이 필요한 페이지인데 관리자가 아닌 경우
if (to.meta.requiresAdmin && userRole !== 'admin' && userRole !== 'superadmin') {
next({ name: 'ClubDashboard' });
return;
}
// 이미 로그인한 상태에서 로그인 페이지로 이동하려는 경우
if (to.name === 'Login' && isAuthenticated) {
if (userRole === 'admin' || userRole === 'superadmin') {
next({ name: 'AdminDashboard' });
} else {
next({ name: 'ClubDashboard' });
}
return;
}
// 일반 사용자가 클럽이 없는 경우, 클럽 생성 페이지로 리다이렉트 (관리자 제외)
if (isAuthenticated && userRole !== 'admin' && userRole !== 'superadmin' && !clubId &&
to.name !== 'UserClubCreate' && to.name !== 'Profile' && to.name !== 'Login') {
next({ name: 'UserClubCreate' });
return;
}
// 클럽 구독 관리 페이지에 접근하려는 경우, 권한 확인
if (to.name === 'ClubSubscription' && (userClubRole !== '모임장' && userClubRole !== '운영진')) {
next({ name: 'ClubDashboard' });
return;
}
next();
});
export default router;