2 次代碼提交 adba674a0e ... 82dc1956b4

作者 SHA1 備註 提交日期
  yb 82dc1956b4 update code 2 天之前
  yb 4a7f8d4dc7 feat(camera): update camera control API endpoints and add preset management functions 2 天之前
共有 4 個文件被更改,包括 35 次插入16 次删除
  1. 24 4
      src/api/camera.ts
  2. 1 1
      src/api/ptz.ts
  3. 6 6
      tests/unit/api/camera.spec.ts
  4. 4 5
      vite.config.ts

+ 24 - 4
src/api/camera.ts

@@ -25,7 +25,7 @@ export function listCameras(machineId?: string): Promise<IListResponse<CameraDTO
 
 // 获取摄像头信息
 export function getCamera(cameraId: string): Promise<IBaseResponse<CameraDTO>> {
-  return get(`/camera/${cameraId}`)
+  return get(`/camera/control/${cameraId}`)
 }
 
 // 切换摄像头通道 (MVP核心)
@@ -40,19 +40,39 @@ export function getCurrentChannel(machineId: string): Promise<IBaseResponse<Chan
 
 // 开始PTZ控制 (后台专用)
 export function ptzStart(cameraId: string, action: PTZAction, speed: number = 50): Promise<BaseResponse> {
-  return post(`/camera/${cameraId}/ptz/start`, undefined, {
+  return post(`/camera/control/${cameraId}/ptz/start`, undefined, {
     params: { action, speed }
   })
 }
 
 // 停止PTZ控制 (后台专用)
 export function ptzStop(cameraId: string): Promise<BaseResponse> {
-  return post(`/camera/${cameraId}/ptz/stop`)
+  return post(`/camera/control/${cameraId}/ptz/stop`)
 }
 
 // PTZ 直接控制 (pan/tilt/zoom 方式)
 export function ptzDirectControl(cameraId: string, data: PTZControlRequest): Promise<BaseResponse> {
-  return post(`/camera/${cameraId}/ptz/control`, data)
+  return post(`/camera/control/${cameraId}/ptz/control`, data)
+}
+
+// 获取预置位列表 (PTZ后端)
+export function presetList(cameraId: string): Promise<BaseResponse> {
+  return get(`/camera/control/${cameraId}/preset/list`)
+}
+
+// 跳转到预置位 (PTZ后端)
+export function presetGoto(cameraId: string, presetId: number): Promise<BaseResponse> {
+  return post(`/camera/control/${cameraId}/preset/goto`, { presetId })
+}
+
+// 设置预置位 (PTZ后端)
+export function presetSet(cameraId: string, presetId: number, presetName?: string): Promise<BaseResponse> {
+  return post(`/camera/control/${cameraId}/preset/set`, { presetId, presetName })
+}
+
+// 删除预置位 (PTZ后端)
+export function presetRemove(cameraId: string, presetId: number): Promise<BaseResponse> {
+  return post(`/camera/control/${cameraId}/preset/remove`, { presetId })
 }
 
 // ==================== Admin APIs ====================

+ 1 - 1
src/api/ptz.ts

@@ -32,7 +32,7 @@ export interface PTZResult {
 
 // ==================== 常量 ====================
 
-const PTZ_API_BASE = 'http://localhost:3002'
+const PTZ_API_BASE = '/camera/control'
 const DEFAULT_SPEED = 50
 
 // 方向预设值 (单位向量)

+ 6 - 6
tests/unit/api/camera.spec.ts

@@ -48,14 +48,14 @@ describe('Camera API', () => {
     })
 
     describe('getCamera', () => {
-      it('should call GET /camera/:id', async () => {
+      it('should call GET /camera/control/:id', async () => {
         const camera = mockCameras[0]
         const mockResponse = wrapResponse(camera)
         vi.mocked(request.get).mockResolvedValue(mockResponse)
 
         const result = await getCamera(camera.cameraId)
 
-        expect(request.get).toHaveBeenCalledWith(`/camera/${camera.cameraId}`)
+        expect(request.get).toHaveBeenCalledWith(`/camera/control/${camera.cameraId}`)
         expect(result.data.cameraId).toBe(camera.cameraId)
       })
     })
@@ -90,26 +90,26 @@ describe('Camera API', () => {
     })
 
     describe('ptzStart', () => {
-      it('should call POST /camera/:id/ptz/start', async () => {
+      it('should call POST /camera/control/:id/ptz/start', async () => {
         const mockResponse = wrapResponse(null)
         vi.mocked(request.post).mockResolvedValue(mockResponse)
 
         await ptzStart('cam-001', 'up', 50)
 
-        expect(request.post).toHaveBeenCalledWith('/camera/cam-001/ptz/start', undefined, {
+        expect(request.post).toHaveBeenCalledWith('/camera/control/cam-001/ptz/start', undefined, {
           params: { action: 'up', speed: 50 }
         })
       })
     })
 
     describe('ptzStop', () => {
-      it('should call POST /camera/:id/ptz/stop', async () => {
+      it('should call POST /camera/control/:id/ptz/stop', async () => {
         const mockResponse = wrapResponse(null)
         vi.mocked(request.post).mockResolvedValue(mockResponse)
 
         await ptzStop('cam-001')
 
-        expect(request.post).toHaveBeenCalledWith('/camera/cam-001/ptz/stop')
+        expect(request.post).toHaveBeenCalledWith('/camera/control/cam-001/ptz/stop')
       })
     })
   })

+ 4 - 5
vite.config.ts

@@ -67,12 +67,11 @@ export default defineConfig({
         changeOrigin: true,
         secure: false // 禁用 SSL 证书验证(开发环境)
       },
-      // 摄像头 PTZ 代理 - 固定 IP(开发环境)
-      '/camera-proxy': {
-        target: 'http://192.168.0.64',
+      // PTZ 摄像头控制
+      '/camera/control': {
+        target: 'http://localhost:3002',
         changeOrigin: true,
-        secure: false,
-        rewrite: (path) => path.replace(/^\/camera-proxy/, '')
+        rewrite: (path) => path.replace(/^\/camera\/control/, '')
       }
     }
   },