index.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * 测试数据 Fixtures
  3. * 提供各模块的模拟数据
  4. */
  5. import type {
  6. AdminInfo,
  7. LoginResponse,
  8. MachineDTO,
  9. CameraInfoDTO,
  10. ChannelInfoDTO,
  11. DashboardStatsDTO
  12. } from '@/types'
  13. // ==================== 用户/认证数据 ====================
  14. export const mockAdminInfo: AdminInfo = {
  15. id: 1,
  16. username: 'admin',
  17. nickname: '管理员',
  18. role: 'admin',
  19. lastLoginAt: '2024-01-01T00:00:00Z'
  20. }
  21. export const mockLoginResponse: LoginResponse = {
  22. token: 'mock-jwt-token-12345',
  23. tokenType: 'Bearer',
  24. expiresIn: 3600,
  25. refreshToken: 'mock-refresh-token-67890',
  26. admin: mockAdminInfo
  27. }
  28. export const mockUsers = [
  29. { ...mockAdminInfo },
  30. {
  31. id: 2,
  32. username: 'operator1',
  33. nickname: '操作员1',
  34. role: 'operator',
  35. lastLoginAt: '2024-01-02T00:00:00Z'
  36. },
  37. {
  38. id: 3,
  39. username: 'viewer1',
  40. nickname: '观察员1',
  41. role: 'viewer',
  42. lastLoginAt: '2024-01-03T00:00:00Z'
  43. }
  44. ]
  45. // ==================== 机器数据 ====================
  46. export const mockMachines: MachineDTO[] = [
  47. {
  48. id: 1,
  49. machineId: 'machine-001',
  50. name: '一号机',
  51. location: '一楼大厅',
  52. description: '主入口监控',
  53. enabled: true,
  54. cameraCount: 3,
  55. createdAt: '2024-01-01 00:00:00',
  56. updatedAt: '2024-01-01 00:00:00'
  57. },
  58. {
  59. id: 2,
  60. machineId: 'machine-002',
  61. name: '二号机',
  62. location: '二楼走廊',
  63. description: '走廊监控',
  64. enabled: true,
  65. cameraCount: 2,
  66. createdAt: '2024-01-02 00:00:00',
  67. updatedAt: '2024-01-02 00:00:00'
  68. },
  69. {
  70. id: 3,
  71. machineId: 'machine-003',
  72. name: '三号机',
  73. location: '停车场',
  74. description: '停车场监控',
  75. enabled: false,
  76. cameraCount: 4,
  77. createdAt: '2024-01-03 00:00:00',
  78. updatedAt: '2024-01-03 00:00:00'
  79. }
  80. ]
  81. // ==================== 通道数据 ====================
  82. export const mockChannels: ChannelInfoDTO[] = [
  83. {
  84. id: 1,
  85. channelId: 'ch-001',
  86. name: '通道1-主视角',
  87. rtspUrl: 'rtsp://192.168.1.100:554/stream1',
  88. defaultView: true,
  89. status: 'ONLINE'
  90. },
  91. {
  92. id: 2,
  93. channelId: 'ch-002',
  94. name: '通道2-侧视角',
  95. rtspUrl: 'rtsp://192.168.1.100:554/stream2',
  96. defaultView: false,
  97. status: 'ONLINE'
  98. },
  99. {
  100. id: 3,
  101. channelId: 'ch-003',
  102. name: '通道3-广角',
  103. rtspUrl: 'rtsp://192.168.1.100:554/stream3',
  104. defaultView: false,
  105. status: 'OFFLINE'
  106. }
  107. ]
  108. // ==================== 摄像头数据 ====================
  109. export const mockCameras: CameraInfoDTO[] = [
  110. {
  111. id: 1,
  112. cameraId: 'cam-001',
  113. name: '大厅摄像头1',
  114. ip: '192.168.1.100',
  115. port: 80,
  116. username: 'admin',
  117. brand: 'hikvision',
  118. capability: 'ptz_enabled',
  119. status: 'ONLINE',
  120. machineId: 'machine-001',
  121. machineName: '一号机',
  122. enabled: true,
  123. channels: [mockChannels[0], mockChannels[1]],
  124. createdAt: '2024-01-01 00:00:00',
  125. updatedAt: '2024-01-01 00:00:00'
  126. },
  127. {
  128. id: 2,
  129. cameraId: 'cam-002',
  130. name: '大厅摄像头2',
  131. ip: '192.168.1.101',
  132. port: 80,
  133. username: 'admin',
  134. brand: 'dahua',
  135. capability: 'switch_only',
  136. status: 'ONLINE',
  137. machineId: 'machine-001',
  138. machineName: '一号机',
  139. enabled: true,
  140. channels: [mockChannels[2]],
  141. createdAt: '2024-01-02 00:00:00',
  142. updatedAt: '2024-01-02 00:00:00'
  143. },
  144. {
  145. id: 3,
  146. cameraId: 'cam-003',
  147. name: '走廊摄像头',
  148. ip: '192.168.1.102',
  149. port: 80,
  150. username: 'admin',
  151. brand: 'hikvision',
  152. capability: 'ptz_enabled',
  153. status: 'OFFLINE',
  154. machineId: 'machine-002',
  155. machineName: '二号机',
  156. enabled: false,
  157. channels: [],
  158. createdAt: '2024-01-03 00:00:00',
  159. updatedAt: '2024-01-03 00:00:00'
  160. }
  161. ]
  162. // ==================== 统计数据 ====================
  163. export const mockDashboardStats: DashboardStatsDTO = {
  164. machineTotal: 3,
  165. machineEnabled: 2,
  166. cameraTotal: 9,
  167. cameraOnline: 7,
  168. cameraOffline: 2,
  169. channelTotal: 18
  170. }
  171. // ==================== API 响应包装 ====================
  172. export function wrapResponse<T>(data: T, code = 200, message = 'success') {
  173. return {
  174. code,
  175. message,
  176. data,
  177. timestamp: Date.now(),
  178. traceId: `trace-${Date.now()}`
  179. }
  180. }
  181. export function wrapPageResponse<T>(rows: T[], total?: number) {
  182. return wrapResponse({
  183. rows,
  184. total: total ?? rows.length
  185. })
  186. }
  187. export function wrapErrorResponse(message: string, code = 400) {
  188. return {
  189. code,
  190. message,
  191. data: null,
  192. timestamp: Date.now()
  193. }
  194. }