index.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
  2. import { getToken } from '@/utils/auth'
  3. import NProgress from 'nprogress'
  4. import 'nprogress/nprogress.css'
  5. // NProgress 配置
  6. NProgress.configure({ showSpinner: false })
  7. const Layout = () => import('@/layout/index.vue')
  8. const routes: RouteRecordRaw[] = [
  9. {
  10. path: '/login',
  11. name: 'Login',
  12. component: () => import('@/views/login/index.vue'),
  13. meta: { title: '登录', hidden: true }
  14. },
  15. {
  16. path: '/',
  17. component: Layout,
  18. redirect: '/dashboard',
  19. children: [
  20. {
  21. path: 'dashboard',
  22. name: 'Dashboard',
  23. component: () => import('@/views/dashboard/index.vue'),
  24. meta: { title: '仪表盘', icon: 'DataLine' }
  25. },
  26. {
  27. path: 'machine',
  28. name: 'Machine',
  29. component: () => import('@/views/machine/index.vue'),
  30. meta: { title: '机器管理', icon: 'Monitor' }
  31. },
  32. {
  33. path: 'camera',
  34. name: 'Camera',
  35. component: () => import('@/views/camera/index.vue'),
  36. meta: { title: '摄像头管理', icon: 'VideoCamera' }
  37. },
  38. {
  39. path: 'camera/channel/:deviceId',
  40. name: 'CameraChannel',
  41. component: () => import('@/views/camera/channel.vue'),
  42. meta: { title: '通道列表', hidden: true }
  43. },
  44. {
  45. path: 'camera/video/:deviceId/:channelId',
  46. name: 'CameraVideo',
  47. component: () => import('@/views/camera/video.vue'),
  48. meta: { title: '视频播放', hidden: true }
  49. },
  50. {
  51. path: 'stream-test',
  52. name: 'StreamTest',
  53. component: () => import('@/views/camera/stream-test.vue'),
  54. meta: { title: 'Stream 测试', icon: 'Monitor' }
  55. },
  56. {
  57. path: 'stream/videos',
  58. name: 'StreamVideos',
  59. component: () => import('@/views/stream/video-list.vue'),
  60. meta: { title: '视频管理', icon: 'Film' }
  61. },
  62. {
  63. path: 'stream/live',
  64. name: 'StreamLive',
  65. component: () => import('@/views/stream/live-list.vue'),
  66. meta: { title: '直播管理', icon: 'VideoCameraFilled' }
  67. },
  68. {
  69. path: 'stream/config',
  70. name: 'StreamConfig',
  71. component: () => import('@/views/stream/config.vue'),
  72. meta: { title: 'Stream 配置', icon: 'Setting' }
  73. },
  74. {
  75. path: 'user',
  76. name: 'User',
  77. component: () => import('@/views/user/index.vue'),
  78. meta: { title: '用户管理', icon: 'User' }
  79. },
  80. {
  81. path: 'stats',
  82. name: 'Stats',
  83. component: () => import('@/views/stats/index.vue'),
  84. meta: { title: '观看统计', icon: 'DataAnalysis' }
  85. },
  86. {
  87. path: 'audit',
  88. name: 'Audit',
  89. component: () => import('@/views/audit/index.vue'),
  90. meta: { title: '审计日志', icon: 'Document' }
  91. },
  92. {
  93. path: 'demo/direct-url',
  94. name: 'DirectUrl',
  95. component: () => import('@/views/demo/direct-url.vue'),
  96. meta: { title: '直接 URL', icon: 'Link' }
  97. },
  98. {
  99. path: 'demo/cloudflare-stream',
  100. name: 'CloudflareStream',
  101. component: () => import('@/views/demo/cloudflare-stream.vue'),
  102. meta: { title: 'Cloudflare Stream', icon: 'VideoCamera' }
  103. },
  104. {
  105. path: 'demo/rtsp-stream',
  106. name: 'RtspStream',
  107. component: () => import('@/views/demo/rtsp-stream.vue'),
  108. meta: { title: 'RTSP 流', icon: 'Connection' }
  109. },
  110. {
  111. path: 'demo/sample-videos',
  112. name: 'SampleVideos',
  113. component: () => import('@/views/demo/sample-videos.vue'),
  114. meta: { title: '测试视频', icon: 'Film' }
  115. }
  116. ]
  117. },
  118. {
  119. path: '/:pathMatch(.*)*',
  120. redirect: '/'
  121. }
  122. ]
  123. const router = createRouter({
  124. history: createWebHistory(),
  125. routes
  126. })
  127. // 白名单(无需登录即可访问)
  128. const whiteList = ['/login', '/stream-test']
  129. router.beforeEach((to, _from, next) => {
  130. // 开始进度条
  131. NProgress.start()
  132. // 统一使用系统名称作为标题
  133. document.title = '摄像头管理系统'
  134. const hasToken = getToken()
  135. if (hasToken) {
  136. if (to.path === '/login') {
  137. next({ path: '/' })
  138. } else {
  139. next()
  140. }
  141. } else if (whiteList.includes(to.path)) {
  142. next()
  143. } else {
  144. next(`/login?redirect=${to.fullPath}`)
  145. }
  146. })
  147. router.afterEach(() => {
  148. // 结束进度条
  149. NProgress.done()
  150. })
  151. export default router