|
@@ -1,4 +1,4 @@
|
|
|
-import { get, post } from '@/utils/request'
|
|
|
|
|
|
|
+import { get, post, ptzGet, ptzPost } from '@/utils/request'
|
|
|
import type {
|
|
import type {
|
|
|
IBaseResponse,
|
|
IBaseResponse,
|
|
|
IListResponse,
|
|
IListResponse,
|
|
@@ -23,9 +23,9 @@ export function listCameras(machineId?: string): Promise<IListResponse<CameraDTO
|
|
|
return post('/camera/list', machineId ? { machineId } : {})
|
|
return post('/camera/list', machineId ? { machineId } : {})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 获取摄像头信息
|
|
|
|
|
|
|
+// 获取摄像头信息 (主API)
|
|
|
export function getCamera(cameraId: string): Promise<IBaseResponse<CameraDTO>> {
|
|
export function getCamera(cameraId: string): Promise<IBaseResponse<CameraDTO>> {
|
|
|
- return get(`/camera/control/${cameraId}`)
|
|
|
|
|
|
|
+ return get(`/cameras/${cameraId}`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 切换摄像头通道 (MVP核心)
|
|
// 切换摄像头通道 (MVP核心)
|
|
@@ -38,46 +38,65 @@ export function getCurrentChannel(machineId: string): Promise<IBaseResponse<Chan
|
|
|
return get('/camera/current', { machineId })
|
|
return get('/camera/current', { machineId })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 开始PTZ控制 (后台专用)
|
|
|
|
|
|
|
+// 开始PTZ控制 (PTZ服务)
|
|
|
|
|
+// 使用 /ptz/control 端点,通过 body 传递 cameraId
|
|
|
export function ptzStart(cameraId: string, action: PTZAction, speed: number = 50): Promise<BaseResponse> {
|
|
export function ptzStart(cameraId: string, action: PTZAction, speed: number = 50): Promise<BaseResponse> {
|
|
|
- return post(`/camera/control/${cameraId}/ptz/start`, undefined, {
|
|
|
|
|
- params: { action, speed }
|
|
|
|
|
|
|
+ // 映射 action 到 PTZ 服务支持的 command
|
|
|
|
|
+ const commandMap: Record<PTZAction, string> = {
|
|
|
|
|
+ up: 'up',
|
|
|
|
|
+ down: 'down',
|
|
|
|
|
+ left: 'left',
|
|
|
|
|
+ right: 'right',
|
|
|
|
|
+ zoom_in: 'zoom_in',
|
|
|
|
|
+ zoom_out: 'zoom_out',
|
|
|
|
|
+ stop: 'stop'
|
|
|
|
|
+ }
|
|
|
|
|
+ return ptzPost('/ptz/control', {
|
|
|
|
|
+ host: cameraId,
|
|
|
|
|
+ command: commandMap[action] || 'stop',
|
|
|
|
|
+ speed
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 停止PTZ控制 (后台专用)
|
|
|
|
|
|
|
+// 停止PTZ控制 (PTZ服务)
|
|
|
export function ptzStop(cameraId: string): Promise<BaseResponse> {
|
|
export function ptzStop(cameraId: string): Promise<BaseResponse> {
|
|
|
- return post(`/camera/control/${cameraId}/ptz/stop`)
|
|
|
|
|
|
|
+ return ptzPost('/ptz/control', {
|
|
|
|
|
+ host: cameraId,
|
|
|
|
|
+ command: 'stop'
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// PTZ 直接控制 (pan/tilt/zoom 方式)
|
|
|
|
|
|
|
+// PTZ 直接控制 (pan/tilt/zoom 方式, PTZ服务)
|
|
|
export function ptzDirectControl(cameraId: string, data: PTZControlRequest): Promise<BaseResponse> {
|
|
export function ptzDirectControl(cameraId: string, data: PTZControlRequest): Promise<BaseResponse> {
|
|
|
- return post(`/camera/control/${cameraId}/ptz/control`, data)
|
|
|
|
|
|
|
+ return ptzPost('/ptz/control', {
|
|
|
|
|
+ host: cameraId,
|
|
|
|
|
+ ...data
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 获取预置位列表 (PTZ后端)
|
|
|
|
|
|
|
+// 获取预置位列表 (PTZ服务)
|
|
|
export function presetList(cameraId: string): Promise<BaseResponse> {
|
|
export function presetList(cameraId: string): Promise<BaseResponse> {
|
|
|
- return get(`/camera/control/${cameraId}/preset/list`)
|
|
|
|
|
|
|
+ return ptzGet(`/${cameraId}/preset/list`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 获取PTZ能力 (PTZ后端)
|
|
|
|
|
|
|
+// 获取PTZ能力 (PTZ服务)
|
|
|
export function getPTZCapabilities(cameraId: string): Promise<BaseResponse> {
|
|
export function getPTZCapabilities(cameraId: string): Promise<BaseResponse> {
|
|
|
- return get(`/camera/control/${cameraId}/ptz/capabilities`)
|
|
|
|
|
|
|
+ return ptzGet(`/${cameraId}/ptz/capabilities`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 跳转到预置位 (PTZ后端)
|
|
|
|
|
|
|
+// 跳转到预置位 (PTZ服务)
|
|
|
export function presetGoto(cameraId: string, presetId: number): Promise<BaseResponse> {
|
|
export function presetGoto(cameraId: string, presetId: number): Promise<BaseResponse> {
|
|
|
- return post(`/camera/control/${cameraId}/preset/goto`, { presetId })
|
|
|
|
|
|
|
+ return ptzPost(`/${cameraId}/preset/goto`, { presetId })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 设置预置位 (PTZ后端)
|
|
|
|
|
|
|
+// 设置预置位 (PTZ服务)
|
|
|
export function presetSet(cameraId: string, presetId: number, presetName?: string): Promise<BaseResponse> {
|
|
export function presetSet(cameraId: string, presetId: number, presetName?: string): Promise<BaseResponse> {
|
|
|
- return post(`/camera/control/${cameraId}/preset/set`, { presetId, presetName })
|
|
|
|
|
|
|
+ return ptzPost(`/${cameraId}/preset/set`, { presetId, presetName })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 删除预置位 (PTZ后端)
|
|
|
|
|
|
|
+// 删除预置位 (PTZ服务)
|
|
|
export function presetRemove(cameraId: string, presetId: number): Promise<BaseResponse> {
|
|
export function presetRemove(cameraId: string, presetId: number): Promise<BaseResponse> {
|
|
|
- return post(`/camera/control/${cameraId}/preset/remove`, { presetId })
|
|
|
|
|
|
|
+ return ptzPost(`/${cameraId}/preset/remove`, { presetId })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ==================== Admin APIs ====================
|
|
// ==================== Admin APIs ====================
|
|
@@ -131,7 +150,7 @@ export function adminPTZControl(data: AdminPTZRequest): Promise<IBaseResponse<bo
|
|
|
return post('/admin/cameras/ptz', data)
|
|
return post('/admin/cameras/ptz', data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// ==================== Preset APIs ====================
|
|
|
|
|
|
|
+// ==================== Preset APIs (PTZ服务) ====================
|
|
|
|
|
|
|
|
// 预置位类型
|
|
// 预置位类型
|
|
|
export interface PresetInfo {
|
|
export interface PresetInfo {
|
|
@@ -139,30 +158,25 @@ export interface PresetInfo {
|
|
|
name: string
|
|
name: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 获取预置位列表
|
|
|
|
|
|
|
+// 获取预置位列表 (兼容旧API)
|
|
|
export function getPresets(cameraId: string): Promise<IListResponse<PresetInfo>> {
|
|
export function getPresets(cameraId: string): Promise<IListResponse<PresetInfo>> {
|
|
|
- return get(`/camera/${cameraId}/presets`)
|
|
|
|
|
|
|
+ return ptzGet(`/${cameraId}/preset/list`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 跳转到预置位
|
|
|
|
|
|
|
+// 跳转到预置位 (兼容旧API)
|
|
|
export function gotoPreset(cameraId: string, presetToken: string): Promise<BaseResponse> {
|
|
export function gotoPreset(cameraId: string, presetToken: string): Promise<BaseResponse> {
|
|
|
- return post(`/camera/${cameraId}/preset/goto`, undefined, {
|
|
|
|
|
- params: { presetToken }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ return ptzPost(`/${cameraId}/preset/goto`, { presetId: parseInt(presetToken) || 1 })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 设置预置位 (保存当前位置)
|
|
|
|
|
|
|
+// 设置预置位 (保存当前位置, 兼容旧API)
|
|
|
export function setPreset(cameraId: string, presetName?: string): Promise<IBaseResponse<PresetInfo>> {
|
|
export function setPreset(cameraId: string, presetName?: string): Promise<IBaseResponse<PresetInfo>> {
|
|
|
- return post(`/camera/${cameraId}/preset/set`, undefined, {
|
|
|
|
|
- params: presetName ? { presetName } : undefined
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ // 旧API不指定presetId,这里使用一个默认值
|
|
|
|
|
+ return ptzPost(`/${cameraId}/preset/set`, { presetId: 1, presetName })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 删除预置位
|
|
|
|
|
|
|
+// 删除预置位 (兼容旧API)
|
|
|
export function removePreset(cameraId: string, presetToken: string): Promise<BaseResponse> {
|
|
export function removePreset(cameraId: string, presetToken: string): Promise<BaseResponse> {
|
|
|
- return post(`/camera/${cameraId}/preset/remove`, undefined, {
|
|
|
|
|
- params: { presetToken }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ return ptzPost(`/${cameraId}/preset/remove`, { presetId: parseInt(presetToken) || 1 })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ==================== 兼容旧代码的别名 ====================
|
|
// ==================== 兼容旧代码的别名 ====================
|