index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. * 路由配置
  3. */
  4. import { createRouter, createWebHistory } from 'vue-router'
  5. import { useUserStore } from '@/stores/user'
  6. const router = createRouter({
  7. history: createWebHistory(import.meta.env.BASE_URL),
  8. routes: [
  9. {
  10. path: '/login',
  11. name: 'Login',
  12. component: () => import('@/views/Login.vue'),
  13. meta: { title: '登录', requiresAuth: false }
  14. },
  15. {
  16. path: '/',
  17. component: () => import('@/layouts/MainLayout.vue'),
  18. redirect: '/dashboard',
  19. meta: { requiresAuth: true },
  20. children: [
  21. {
  22. path: 'dashboard',
  23. name: 'Dashboard',
  24. component: () => import('@/views/Dashboard.vue'),
  25. meta: { title: '数据面板', icon: 'DataBoard' }
  26. },
  27. // 轮播图管理
  28. {
  29. path: 'banner',
  30. name: 'Banner',
  31. component: () => import('@/views/banner/BannerList.vue'),
  32. meta: { title: '轮播图管理', icon: 'Picture' }
  33. },
  34. // 小喇叭公告管理
  35. {
  36. path: 'announcement',
  37. name: 'Announcement',
  38. component: () => import('@/views/announcement/AnnouncementList.vue'),
  39. meta: { title: '小喇叭公告', icon: 'Microphone' }
  40. },
  41. // 活动管理
  42. {
  43. path: 'activity',
  44. name: 'Activity',
  45. redirect: '/activity/list',
  46. meta: { title: '活动管理', icon: 'Calendar' },
  47. children: [
  48. {
  49. path: 'list',
  50. name: 'ActivityList',
  51. component: () => import('@/views/activity/ActivityList.vue'),
  52. meta: { title: '活动列表' }
  53. },
  54. {
  55. path: 'create',
  56. name: 'ActivityCreate',
  57. component: () => import('@/views/activity/ActivityForm.vue'),
  58. meta: { title: '创建活动' }
  59. },
  60. {
  61. path: 'edit/:id',
  62. name: 'ActivityEdit',
  63. component: () => import('@/views/activity/ActivityForm.vue'),
  64. meta: { title: '编辑活动' }
  65. },
  66. {
  67. path: 'registrations/:id',
  68. name: 'ActivityRegistrations',
  69. component: () => import('@/views/activity/ActivityRegistrations.vue'),
  70. meta: { title: '报名管理' }
  71. }
  72. ]
  73. },
  74. // 红娘管理
  75. {
  76. path: 'matchmaker',
  77. name: 'Matchmaker',
  78. redirect: '/matchmaker/list',
  79. meta: { title: '红娘管理', icon: 'User' },
  80. children: [
  81. {
  82. path: 'list',
  83. name: 'MatchmakerList',
  84. component: () => import('@/views/matchmaker/MatchmakerList.vue'),
  85. meta: { title: '红娘列表' }
  86. },
  87. {
  88. path: 'create',
  89. name: 'MatchmakerCreate',
  90. component: () => import('@/views/matchmaker/MatchmakerForm.vue'),
  91. meta: { title: '添加红娘' }
  92. },
  93. {
  94. path: 'edit/:id',
  95. name: 'MatchmakerEdit',
  96. component: () => import('@/views/matchmaker/MatchmakerForm.vue'),
  97. meta: { title: '编辑红娘' }
  98. }
  99. ]
  100. },
  101. // 课程管理
  102. {
  103. path: 'course',
  104. name: 'Course',
  105. redirect: '/course/list',
  106. meta: { title: '课程管理', icon: 'Reading' },
  107. children: [
  108. {
  109. path: 'list',
  110. name: 'CourseList',
  111. component: () => import('@/views/course/CourseList.vue'),
  112. meta: { title: '课程列表' }
  113. },
  114. {
  115. path: 'create',
  116. name: 'CourseCreate',
  117. component: () => import('@/views/course/CourseForm.vue'),
  118. meta: { title: '创建课程' }
  119. },
  120. {
  121. path: 'detail/:id',
  122. name: 'CourseDetail',
  123. component: () => import('@/views/course/CourseDetail.vue'),
  124. meta: { title: '课程详情' }
  125. },
  126. {
  127. path: 'edit/:id',
  128. name: 'CourseEdit',
  129. component: () => import('@/views/course/CourseForm.vue'),
  130. meta: { title: '编辑课程' }
  131. }
  132. ]
  133. },
  134. // 成功案例管理
  135. {
  136. path: 'success-case',
  137. name: 'SuccessCase',
  138. redirect: '/success-case/list',
  139. meta: { title: '成功案例', icon: 'TrophyBase' },
  140. children: [
  141. {
  142. path: 'list',
  143. name: 'SuccessCaseList',
  144. component: () => import('@/views/success-case/SuccessCaseList.vue'),
  145. meta: { title: '案例列表' }
  146. },
  147. {
  148. path: 'create',
  149. name: 'SuccessCaseCreate',
  150. component: () => import('@/views/success-case/SuccessCaseForm.vue'),
  151. meta: { title: '创建案例' }
  152. },
  153. {
  154. path: 'edit/:id',
  155. name: 'SuccessCaseEdit',
  156. component: () => import('@/views/success-case/SuccessCaseForm.vue'),
  157. meta: { title: '编辑案例' }
  158. }
  159. ]
  160. },
  161. // 用户管理
  162. {
  163. path: 'user',
  164. name: 'User',
  165. redirect: '/user/list',
  166. meta: { title: '用户管理', icon: 'UserFilled' },
  167. children: [
  168. {
  169. path: 'list',
  170. name: 'UserList',
  171. component: () => import('@/views/user/UserList.vue'),
  172. meta: { title: '用户列表' }
  173. },
  174. {
  175. path: 'vip',
  176. name: 'UserVip',
  177. component: () => import('@/views/user/UserVipList.vue'),
  178. meta: { title: 'VIP用户' }
  179. }
  180. ]
  181. },
  182. // VIP套餐管理
  183. {
  184. path: 'vip-package',
  185. name: 'VipPackage',
  186. component: () => import('@/views/vip/VipPackageList.vue'),
  187. meta: { title: 'VIP套餐', icon: 'Medal' }
  188. },
  189. // 动态管理
  190. {
  191. path: 'dynamic',
  192. name: 'Dynamic',
  193. component: () => import('@/views/dynamic/DynamicList.vue'),
  194. meta: { title: '动态管理', icon: 'ChatDotSquare' }
  195. },
  196. // 举报管理
  197. {
  198. path: 'report',
  199. name: 'Report',
  200. component: () => import('@/views/report/ReportList.vue'),
  201. meta: { title: '举报管理', icon: 'Warning' }
  202. }
  203. ]
  204. },
  205. {
  206. path: '/:pathMatch(.*)*',
  207. name: 'NotFound',
  208. component: () => import('@/views/404.vue'),
  209. meta: { title: '404' }
  210. }
  211. ]
  212. })
  213. // 路由守卫
  214. router.beforeEach((to, from, next) => {
  215. const userStore = useUserStore()
  216. // 设置页面标题
  217. document.title = to.meta.title ? `${to.meta.title} - 婚恋管理系统` : '婚恋管理系统'
  218. // 检查是否需要认证
  219. if (to.meta.requiresAuth !== false) {
  220. if (!userStore.token) {
  221. next('/login')
  222. } else {
  223. next()
  224. }
  225. } else {
  226. // 如果已登录,访问登录页则跳转到首页
  227. if (to.path === '/login' && userStore.token) {
  228. next('/')
  229. } else {
  230. next()
  231. }
  232. }
  233. })
  234. export default router