index.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
  2. import NProgress from 'nprogress'
  3. import { getToken } from '@/utils/auth'
  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-vendor',
  40. name: 'CameraVendor',
  41. component: () => import('@/views/camera-vendor/index.vue'),
  42. meta: { title: '摄像头厂家', icon: 'OfficeBuilding' }
  43. },
  44. {
  45. path: 'lss-manage',
  46. name: 'LssManage',
  47. meta: { title: 'LSS 管理', icon: 'Connection' },
  48. redirect: '/lss-manage/list',
  49. children: [
  50. {
  51. path: 'list',
  52. name: 'LssList',
  53. component: () => import('@/views/lss/index.vue'),
  54. meta: { title: 'LSS 列表', icon: 'List' }
  55. }
  56. ]
  57. },
  58. {
  59. path: 'live-stream-manage',
  60. name: 'LiveStreamManage',
  61. meta: { title: 'LiveStream 管理', icon: 'VideoCamera' },
  62. redirect: '/live-stream-manage/list',
  63. children: [
  64. {
  65. path: 'list',
  66. name: 'LiveStreamList',
  67. component: () => import('@/views/live-stream/index.vue'),
  68. meta: { title: 'LiveStream 列表', icon: 'List' }
  69. }
  70. ]
  71. },
  72. {
  73. path: 'camera/channel/:deviceId',
  74. name: 'CameraChannel',
  75. component: () => import('@/views/camera/channel.vue'),
  76. meta: { title: '通道列表', hidden: true }
  77. },
  78. {
  79. path: 'camera/video/:deviceId/:channelId',
  80. name: 'CameraVideo',
  81. component: () => import('@/views/camera/video.vue'),
  82. meta: { title: '视频播放', hidden: true }
  83. },
  84. {
  85. path: 'streamtest',
  86. name: 'StreamTest',
  87. component: () => import('@/views/camera/stream-test.vue'),
  88. meta: { title: 'Stream 测试', icon: 'Monitor' }
  89. },
  90. {
  91. path: 'stream/videos',
  92. name: 'StreamVideos',
  93. component: () => import('@/views/stream/video-list.vue'),
  94. meta: { title: '视频管理', icon: 'Film' }
  95. },
  96. {
  97. path: 'stream/live',
  98. name: 'StreamLive',
  99. component: () => import('@/views/stream/live-list.vue'),
  100. meta: { title: '直播管理', icon: 'VideoCameraFilled' }
  101. },
  102. {
  103. path: 'stream/config',
  104. name: 'StreamConfig',
  105. component: () => import('@/views/stream/config.vue'),
  106. meta: { title: 'Stream 配置', icon: 'Setting' }
  107. },
  108. {
  109. path: 'user',
  110. name: 'User',
  111. component: () => import('@/views/user/index.vue'),
  112. meta: { title: '用户管理', icon: 'User' }
  113. },
  114. {
  115. path: 'cc',
  116. name: 'CloudflareStream',
  117. component: () => import('@/views/demo/cloudflareStream.vue'),
  118. meta: { title: 'Cloudflare Stream', icon: 'VideoCamera' }
  119. },
  120. {
  121. path: 'stats',
  122. name: 'Stats',
  123. component: () => import('@/views/stats/index.vue'),
  124. meta: { title: '观看统计', icon: 'DataAnalysis' }
  125. },
  126. {
  127. path: 'audit',
  128. name: 'Audit',
  129. component: () => import('@/views/audit/index.vue'),
  130. meta: { title: '审计日志', icon: 'Document' }
  131. },
  132. {
  133. path: 'demo/directurl',
  134. name: 'DirectUrl',
  135. component: () => import('@/views/demo/direct-url.vue'),
  136. meta: { title: '直接 URL', icon: 'Link' }
  137. },
  138. {
  139. path: 'demo/rtsp',
  140. name: 'RtspStream',
  141. component: () => import('@/views/demo/rtsp-stream.vue'),
  142. meta: { title: 'RTSP 流', icon: 'Connection' }
  143. },
  144. {
  145. path: 'demo/samples',
  146. name: 'SampleVideos',
  147. component: () => import('@/views/demo/sample-videos.vue'),
  148. meta: { title: '测试视频', icon: 'Film' }
  149. },
  150. {
  151. path: 'demo/hls',
  152. name: 'HlsStream',
  153. component: () => import('@/views/demo/hls-stream.vue'),
  154. meta: { title: 'M3U8/HLS', icon: 'VideoPlay' }
  155. },
  156. {
  157. path: 'monitor',
  158. name: 'Monitor',
  159. component: () => import('@/views/monitor/index.vue'),
  160. meta: { title: '多视频监控', icon: 'Monitor' }
  161. },
  162. {
  163. path: 'test/m-table',
  164. name: 'MTableDemo',
  165. component: () => import('@/views/test/m-table-demo.vue'),
  166. meta: { title: 'MTable 测试', icon: 'Grid' }
  167. },
  168. {
  169. path: 'system',
  170. name: 'System',
  171. meta: { title: '系统管理', icon: 'Setting' },
  172. redirect: '/system/user',
  173. children: [
  174. {
  175. path: 'user',
  176. name: 'SystemUser',
  177. component: () => import('@/views/system/user/index.vue'),
  178. meta: { title: '用户管理', icon: 'User' }
  179. },
  180. {
  181. path: 'role',
  182. name: 'SystemRole',
  183. component: () => import('@/views/system/role/index.vue'),
  184. meta: { title: '角色管理', icon: 'UserFilled' }
  185. }
  186. ]
  187. }
  188. ]
  189. },
  190. {
  191. path: '/:pathMatch(.*)*',
  192. redirect: '/'
  193. }
  194. ]
  195. const router = createRouter({
  196. history: createWebHistory(),
  197. routes
  198. })
  199. // 白名单(无需登录即可访问)
  200. const whiteList = ['/login', '/streamtest']
  201. router.beforeEach((to, _from, next) => {
  202. // 开始进度条
  203. NProgress.start()
  204. // 统一使用系统名称作为标题
  205. document.title = '摄像头管理系统'
  206. const hasToken = getToken()
  207. if (hasToken) {
  208. if (to.path === '/login') {
  209. next({ path: '/' })
  210. } else {
  211. next()
  212. }
  213. } else if (whiteList.includes(to.path)) {
  214. next()
  215. } else {
  216. next(`/login?redirect=${to.fullPath}`)
  217. }
  218. })
  219. router.afterEach(() => {
  220. // 结束进度条
  221. NProgress.done()
  222. })
  223. export default router