| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- /**
- * 路由配置
- */
- import { createRouter, createWebHistory } from 'vue-router'
- import { useUserStore } from '@/stores/user'
- const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes: [
- {
- path: '/login',
- name: 'Login',
- component: () => import('@/views/Login.vue'),
- meta: { title: '登录', requiresAuth: false }
- },
- {
- path: '/',
- component: () => import('@/layouts/MainLayout.vue'),
- redirect: '/dashboard',
- meta: { requiresAuth: true },
- children: [
- {
- path: 'dashboard',
- name: 'Dashboard',
- component: () => import('@/views/Dashboard.vue'),
- meta: { title: '数据面板', icon: 'DataBoard' }
- },
- // 轮播图管理
- {
- path: 'banner',
- name: 'Banner',
- component: () => import('@/views/banner/BannerList.vue'),
- meta: { title: '轮播图管理', icon: 'Picture' }
- },
- // 小喇叭公告管理
- {
- path: 'announcement',
- name: 'Announcement',
- component: () => import('@/views/announcement/AnnouncementList.vue'),
- meta: { title: '小喇叭公告', icon: 'Microphone' }
- },
- // 管理员管理
- {
- path: 'admin-user',
- name: 'AdminUser',
- component: () => import('@/views/admin/AdminUserList.vue'),
- meta: { title: '管理员管理', icon: 'User' }
- },
- // 活动管理
- {
- path: 'activity',
- name: 'Activity',
- redirect: '/activity/list',
- meta: { title: '活动管理', icon: 'Calendar' },
- children: [
- {
- path: 'list',
- name: 'ActivityList',
- component: () => import('@/views/activity/ActivityList.vue'),
- meta: { title: '活动列表' }
- },
- {
- path: 'create',
- name: 'ActivityCreate',
- component: () => import('@/views/activity/ActivityForm.vue'),
- meta: { title: '创建活动' }
- },
- {
- path: 'edit/:id',
- name: 'ActivityEdit',
- component: () => import('@/views/activity/ActivityForm.vue'),
- meta: { title: '编辑活动' }
- },
- {
- path: 'registrations/:id',
- name: 'ActivityRegistrations',
- component: () => import('@/views/activity/ActivityRegistrations.vue'),
- meta: { title: '报名管理' }
- }
- ]
- },
- // 红娘管理
- {
- path: 'matchmaker',
- name: 'Matchmaker',
- redirect: '/matchmaker/list',
- meta: { title: '红娘管理', icon: 'User' },
- children: [
- {
- path: 'list',
- name: 'MatchmakerList',
- component: () => import('@/views/matchmaker/MatchmakerList.vue'),
- meta: { title: '红娘列表' }
- },
- {
- path: 'audit',
- name: 'MatchmakerAudit',
- component: () => import('@/views/matchmaker/MatchmakerAudit.vue'),
- meta: { title: '红娘审核' }
- },
- {
- path: 'create',
- name: 'MatchmakerCreate',
- component: () => import('@/views/matchmaker/MatchmakerForm.vue'),
- meta: { title: '添加红娘' }
- },
- {
- path: 'edit/:id',
- name: 'MatchmakerEdit',
- component: () => import('@/views/matchmaker/MatchmakerForm.vue'),
- meta: { title: '编辑红娘' }
- },
- {
- path: 'points-product',
- name: 'PointsProduct',
- component: () => import('@/views/points-product/PointsProductList.vue'),
- meta: { title: '积分商品' }
- },
- {
- path: 'case-audit',
- name: 'CaseAudit',
- component: () => import('@/views/matchmaker/CaseAudit.vue'),
- meta: { title: '案例审核' }
- }
- ]
- },
- // 课程管理
- {
- path: 'course',
- name: 'Course',
- redirect: '/course/list',
- meta: { title: '课程管理', icon: 'Reading' },
- children: [
- {
- path: 'list',
- name: 'CourseList',
- component: () => import('@/views/course/CourseList.vue'),
- meta: { title: '课程列表' }
- },
- {
- path: 'create',
- name: 'CourseCreate',
- component: () => import('@/views/course/CourseForm.vue'),
- meta: { title: '创建课程' }
- },
- {
- path: 'detail/:id',
- name: 'CourseDetail',
- component: () => import('@/views/course/CourseDetail.vue'),
- meta: { title: '课程详情' }
- },
- {
- path: 'edit/:id',
- name: 'CourseEdit',
- component: () => import('@/views/course/CourseForm.vue'),
- meta: { title: '编辑课程' }
- }
- ]
- },
- // 成功案例管理
- {
- path: 'success-case',
- name: 'SuccessCase',
- redirect: '/success-case/list',
- meta: { title: '成功案例', icon: 'TrophyBase' },
- children: [
- {
- path: 'list',
- name: 'SuccessCaseList',
- component: () => import('@/views/success-case/SuccessCaseList.vue'),
- meta: { title: '案例列表' }
- },
- {
- path: 'create',
- name: 'SuccessCaseCreate',
- component: () => import('@/views/success-case/SuccessCaseForm.vue'),
- meta: { title: '创建案例' }
- },
- {
- path: 'edit/:id',
- name: 'SuccessCaseEdit',
- component: () => import('@/views/success-case/SuccessCaseForm.vue'),
- meta: { title: '编辑案例' }
- }
- ]
- },
- // 用户管理
- {
- path: 'user',
- name: 'User',
- redirect: '/user/list',
- meta: { title: '用户管理', icon: 'UserFilled' },
- children: [
- {
- path: 'list',
- name: 'UserList',
- component: () => import('@/views/user/UserList.vue'),
- meta: { title: '用户列表' }
- },
- {
- path: 'vip',
- name: 'UserVip',
- component: () => import('@/views/user/UserVipList.vue'),
- meta: { title: 'VIP用户' }
- }
- ]
- },
- // VIP套餐管理
- {
- path: 'vip-package',
- name: 'VipPackage',
- component: () => import('@/views/vip/VipPackageList.vue'),
- meta: { title: 'VIP套餐', icon: 'Medal' }
- },
- // 动态管理
- {
- path: 'dynamic',
- name: 'Dynamic',
- component: () => import('@/views/dynamic/DynamicList.vue'),
- meta: { title: '动态管理', icon: 'ChatDotSquare' }
- },
- {
- path: 'dynamic/detail/:id',
- name: 'DynamicDetail',
- component: () => import('@/views/dynamic/DynamicDetail.vue'),
- meta: { title: '动态详情', hidden: true }
- },
- // 举报管理
- {
- path: 'report',
- name: 'Report',
- component: () => import('@/views/report/ReportList.vue'),
- meta: { title: '举报管理', icon: 'Warning' }
- }
- ]
- },
- {
- path: '/:pathMatch(.*)*',
- name: 'NotFound',
- component: () => import('@/views/404.vue'),
- meta: { title: '404' }
- }
- ]
- })
- // 路由守卫
- router.beforeEach((to, from, next) => {
- const userStore = useUserStore()
-
- // 设置页面标题
- document.title = to.meta.title ? `${to.meta.title} - 婚恋管理系统` : '婚恋管理系统'
-
- // 检查是否需要认证
- if (to.meta.requiresAuth !== false) {
- if (!userStore.token) {
- next('/login')
- } else {
- next()
- }
- } else {
- // 如果已登录,访问登录页则跳转到首页
- if (to.path === '/login' && userStore.token) {
- next('/')
- } else {
- next()
- }
- }
- })
- export default router
|