| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- /**
- * 测试数据 Fixtures
- * 提供各模块的模拟数据
- */
- import type {
- AdminInfo,
- LoginResponse,
- MachineDTO,
- CameraInfoDTO,
- ChannelInfoDTO,
- DashboardStatsDTO
- } from '@/types'
- // ==================== 用户/认证数据 ====================
- export const mockAdminInfo: AdminInfo = {
- id: 1,
- username: 'admin',
- nickname: '管理员',
- role: 'admin',
- lastLoginAt: '2024-01-01T00:00:00Z'
- }
- export const mockLoginResponse: LoginResponse = {
- token: 'mock-jwt-token-12345',
- tokenType: 'Bearer',
- expiresIn: 3600,
- refreshToken: 'mock-refresh-token-67890',
- admin: mockAdminInfo
- }
- export const mockUsers = [
- { ...mockAdminInfo },
- {
- id: 2,
- username: 'operator1',
- nickname: '操作员1',
- role: 'operator',
- lastLoginAt: '2024-01-02T00:00:00Z'
- },
- {
- id: 3,
- username: 'viewer1',
- nickname: '观察员1',
- role: 'viewer',
- lastLoginAt: '2024-01-03T00:00:00Z'
- }
- ]
- // ==================== 机器数据 ====================
- export const mockMachines: MachineDTO[] = [
- {
- id: 1,
- machineId: 'machine-001',
- name: '一号机',
- location: '一楼大厅',
- description: '主入口监控',
- enabled: true,
- cameraCount: 3,
- createdAt: '2024-01-01 00:00:00',
- updatedAt: '2024-01-01 00:00:00'
- },
- {
- id: 2,
- machineId: 'machine-002',
- name: '二号机',
- location: '二楼走廊',
- description: '走廊监控',
- enabled: true,
- cameraCount: 2,
- createdAt: '2024-01-02 00:00:00',
- updatedAt: '2024-01-02 00:00:00'
- },
- {
- id: 3,
- machineId: 'machine-003',
- name: '三号机',
- location: '停车场',
- description: '停车场监控',
- enabled: false,
- cameraCount: 4,
- createdAt: '2024-01-03 00:00:00',
- updatedAt: '2024-01-03 00:00:00'
- }
- ]
- // ==================== 通道数据 ====================
- export const mockChannels: ChannelInfoDTO[] = [
- {
- id: 1,
- channelId: 'ch-001',
- name: '通道1-主视角',
- rtspUrl: 'rtsp://192.168.1.100:554/stream1',
- defaultView: true,
- status: 'ONLINE'
- },
- {
- id: 2,
- channelId: 'ch-002',
- name: '通道2-侧视角',
- rtspUrl: 'rtsp://192.168.1.100:554/stream2',
- defaultView: false,
- status: 'ONLINE'
- },
- {
- id: 3,
- channelId: 'ch-003',
- name: '通道3-广角',
- rtspUrl: 'rtsp://192.168.1.100:554/stream3',
- defaultView: false,
- status: 'OFFLINE'
- }
- ]
- // ==================== 摄像头数据 ====================
- export const mockCameras: CameraInfoDTO[] = [
- {
- id: 1,
- cameraId: 'cam-001',
- name: '大厅摄像头1',
- ip: '192.168.1.100',
- port: 80,
- username: 'admin',
- brand: 'hikvision',
- capability: 'ptz_enabled',
- status: 'ONLINE',
- machineId: 'machine-001',
- machineName: '一号机',
- enabled: true,
- channels: [mockChannels[0], mockChannels[1]],
- createdAt: '2024-01-01 00:00:00',
- updatedAt: '2024-01-01 00:00:00'
- },
- {
- id: 2,
- cameraId: 'cam-002',
- name: '大厅摄像头2',
- ip: '192.168.1.101',
- port: 80,
- username: 'admin',
- brand: 'dahua',
- capability: 'switch_only',
- status: 'ONLINE',
- machineId: 'machine-001',
- machineName: '一号机',
- enabled: true,
- channels: [mockChannels[2]],
- createdAt: '2024-01-02 00:00:00',
- updatedAt: '2024-01-02 00:00:00'
- },
- {
- id: 3,
- cameraId: 'cam-003',
- name: '走廊摄像头',
- ip: '192.168.1.102',
- port: 80,
- username: 'admin',
- brand: 'hikvision',
- capability: 'ptz_enabled',
- status: 'OFFLINE',
- machineId: 'machine-002',
- machineName: '二号机',
- enabled: false,
- channels: [],
- createdAt: '2024-01-03 00:00:00',
- updatedAt: '2024-01-03 00:00:00'
- }
- ]
- // ==================== 统计数据 ====================
- export const mockDashboardStats: DashboardStatsDTO = {
- machineTotal: 3,
- machineEnabled: 2,
- cameraTotal: 9,
- cameraOnline: 7,
- cameraOffline: 2,
- channelTotal: 18
- }
- // ==================== API 响应包装 ====================
- export function wrapResponse<T>(data: T, code = 200, message = 'success') {
- return {
- code,
- message,
- data,
- timestamp: Date.now(),
- traceId: `trace-${Date.now()}`
- }
- }
- export function wrapPageResponse<T>(rows: T[], total?: number) {
- return wrapResponse({
- rows,
- total: total ?? rows.length
- })
- }
- export function wrapErrorResponse(message: string, code = 400) {
- return {
- code,
- message,
- data: null,
- timestamp: Date.now()
- }
- }
|