index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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: 'admin-user',
  44. name: 'AdminUser',
  45. component: () => import('@/views/admin/AdminUserList.vue'),
  46. meta: { title: '管理员管理', icon: 'User' }
  47. },
  48. // 活动管理
  49. {
  50. path: 'activity',
  51. name: 'Activity',
  52. redirect: '/activity/list',
  53. meta: { title: '活动管理', icon: 'Calendar' },
  54. children: [
  55. {
  56. path: 'list',
  57. name: 'ActivityList',
  58. component: () => import('@/views/activity/ActivityList.vue'),
  59. meta: { title: '活动列表' }
  60. },
  61. {
  62. path: 'create',
  63. name: 'ActivityCreate',
  64. component: () => import('@/views/activity/ActivityForm.vue'),
  65. meta: { title: '创建活动' }
  66. },
  67. {
  68. path: 'edit/:id',
  69. name: 'ActivityEdit',
  70. component: () => import('@/views/activity/ActivityForm.vue'),
  71. meta: { title: '编辑活动' }
  72. },
  73. {
  74. path: 'registrations/:id',
  75. name: 'ActivityRegistrations',
  76. component: () => import('@/views/activity/ActivityRegistrations.vue'),
  77. meta: { title: '报名管理' }
  78. }
  79. ]
  80. },
  81. // 红娘管理
  82. {
  83. path: 'matchmaker',
  84. name: 'Matchmaker',
  85. redirect: '/matchmaker/list',
  86. meta: { title: '红娘管理', icon: 'User' },
  87. children: [
  88. {
  89. path: 'list',
  90. name: 'MatchmakerList',
  91. component: () => import('@/views/matchmaker/MatchmakerList.vue'),
  92. meta: { title: '红娘列表' }
  93. },
  94. {
  95. path: 'audit',
  96. name: 'MatchmakerAudit',
  97. component: () => import('@/views/matchmaker/MatchmakerAudit.vue'),
  98. meta: { title: '红娘审核' }
  99. },
  100. {
  101. path: 'create',
  102. name: 'MatchmakerCreate',
  103. component: () => import('@/views/matchmaker/MatchmakerForm.vue'),
  104. meta: { title: '添加红娘' }
  105. },
  106. {
  107. path: 'edit/:id',
  108. name: 'MatchmakerEdit',
  109. component: () => import('@/views/matchmaker/MatchmakerForm.vue'),
  110. meta: { title: '编辑红娘' }
  111. },
  112. {
  113. path: 'points-product',
  114. name: 'PointsProduct',
  115. component: () => import('@/views/points-product/PointsProductList.vue'),
  116. meta: { title: '积分商品' }
  117. },
  118. {
  119. path: 'case-audit',
  120. name: 'CaseAudit',
  121. component: () => import('@/views/matchmaker/CaseAudit.vue'),
  122. meta: { title: '案例审核' }
  123. }
  124. ]
  125. },
  126. // 课程管理
  127. {
  128. path: 'course',
  129. name: 'Course',
  130. redirect: '/course/list',
  131. meta: { title: '课程管理', icon: 'Reading' },
  132. children: [
  133. {
  134. path: 'list',
  135. name: 'CourseList',
  136. component: () => import('@/views/course/CourseList.vue'),
  137. meta: { title: '课程列表' }
  138. },
  139. {
  140. path: 'create',
  141. name: 'CourseCreate',
  142. component: () => import('@/views/course/CourseForm.vue'),
  143. meta: { title: '创建课程' }
  144. },
  145. {
  146. path: 'detail/:id',
  147. name: 'CourseDetail',
  148. component: () => import('@/views/course/CourseDetail.vue'),
  149. meta: { title: '课程详情' }
  150. },
  151. {
  152. path: 'edit/:id',
  153. name: 'CourseEdit',
  154. component: () => import('@/views/course/CourseForm.vue'),
  155. meta: { title: '编辑课程' }
  156. }
  157. ]
  158. },
  159. // 成功案例管理
  160. {
  161. path: 'success-case',
  162. name: 'SuccessCase',
  163. redirect: '/success-case/list',
  164. meta: { title: '成功案例', icon: 'TrophyBase' },
  165. children: [
  166. {
  167. path: 'list',
  168. name: 'SuccessCaseList',
  169. component: () => import('@/views/success-case/SuccessCaseList.vue'),
  170. meta: { title: '案例列表' }
  171. },
  172. {
  173. path: 'create',
  174. name: 'SuccessCaseCreate',
  175. component: () => import('@/views/success-case/SuccessCaseForm.vue'),
  176. meta: { title: '创建案例' }
  177. },
  178. {
  179. path: 'edit/:id',
  180. name: 'SuccessCaseEdit',
  181. component: () => import('@/views/success-case/SuccessCaseForm.vue'),
  182. meta: { title: '编辑案例' }
  183. }
  184. ]
  185. },
  186. // 用户管理
  187. {
  188. path: 'user',
  189. name: 'User',
  190. redirect: '/user/list',
  191. meta: { title: '用户管理', icon: 'UserFilled' },
  192. children: [
  193. {
  194. path: 'list',
  195. name: 'UserList',
  196. component: () => import('@/views/user/UserList.vue'),
  197. meta: { title: '用户列表' }
  198. },
  199. {
  200. path: 'vip',
  201. name: 'UserVip',
  202. component: () => import('@/views/user/UserVipList.vue'),
  203. meta: { title: 'VIP用户' }
  204. }
  205. ]
  206. },
  207. // VIP套餐管理
  208. {
  209. path: 'vip-package',
  210. name: 'VipPackage',
  211. component: () => import('@/views/vip/VipPackageList.vue'),
  212. meta: { title: 'VIP套餐', icon: 'Medal' }
  213. },
  214. // 动态管理
  215. {
  216. path: 'dynamic',
  217. name: 'Dynamic',
  218. component: () => import('@/views/dynamic/DynamicList.vue'),
  219. meta: { title: '动态管理', icon: 'ChatDotSquare' }
  220. },
  221. {
  222. path: 'dynamic/detail/:id',
  223. name: 'DynamicDetail',
  224. component: () => import('@/views/dynamic/DynamicDetail.vue'),
  225. meta: { title: '动态详情', hidden: true }
  226. },
  227. // 举报管理
  228. {
  229. path: 'report',
  230. name: 'Report',
  231. component: () => import('@/views/report/ReportList.vue'),
  232. meta: { title: '举报管理', icon: 'Warning' }
  233. }
  234. ]
  235. },
  236. {
  237. path: '/:pathMatch(.*)*',
  238. name: 'NotFound',
  239. component: () => import('@/views/404.vue'),
  240. meta: { title: '404' }
  241. }
  242. ]
  243. })
  244. // 路由守卫
  245. router.beforeEach((to, from, next) => {
  246. const userStore = useUserStore()
  247. // 设置页面标题
  248. document.title = to.meta.title ? `${to.meta.title} - 婚恋管理系统` : '婚恋管理系统'
  249. // 检查是否需要认证
  250. if (to.meta.requiresAuth !== false) {
  251. if (!userStore.token) {
  252. next('/login')
  253. } else {
  254. next()
  255. }
  256. } else {
  257. // 如果已登录,访问登录页则跳转到首页
  258. if (to.path === '/login' && userStore.token) {
  259. next('/')
  260. } else {
  261. next()
  262. }
  263. }
  264. })
  265. export default router