| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import { get, post } from '@/utils/request'
- import type {
- IBaseResponse,
- IListResponse,
- IPageResponse,
- BaseResponse,
- CameraDTO,
- ChannelDTO,
- CameraInfoDTO,
- CameraAddRequest,
- CameraUpdateRequest,
- CameraListRequest,
- SwitchChannelRequest,
- PTZAction,
- PTZControlRequest,
- AdminPTZRequest
- } from '@/types'
- // ==================== Controller APIs (MVP) ====================
- // 获取摄像头列表 (POST)
- export function listCameras(machineId?: string): Promise<IListResponse<CameraDTO>> {
- return post('/camera/list', machineId ? { machineId } : {})
- }
- // 获取摄像头信息
- export function getCamera(cameraId: string): Promise<IBaseResponse<CameraDTO>> {
- return get(`/camera/${cameraId}`)
- }
- // 切换摄像头通道 (MVP核心)
- export function switchChannel(data: SwitchChannelRequest): Promise<IBaseResponse<ChannelDTO>> {
- return post('/camera/switch', data)
- }
- // 获取当前活动通道
- export function getCurrentChannel(machineId: string): Promise<IBaseResponse<ChannelDTO>> {
- return get('/camera/current', { machineId })
- }
- // 开始PTZ控制 (后台专用)
- export function ptzStart(cameraId: string, action: PTZAction, speed: number = 50): Promise<BaseResponse> {
- return post(`/camera/${cameraId}/ptz/start`, undefined, {
- params: { action, speed }
- })
- }
- // 停止PTZ控制 (后台专用)
- export function ptzStop(cameraId: string): Promise<BaseResponse> {
- return post(`/camera/${cameraId}/ptz/stop`)
- }
- // PTZ 直接控制 (pan/tilt/zoom 方式)
- export function ptzDirectControl(cameraId: string, data: PTZControlRequest): Promise<BaseResponse> {
- return post(`/camera/${cameraId}/ptz/control`, data)
- }
- // ==================== Admin APIs ====================
- // 获取摄像头列表 (管理后台,分页)
- export function adminListCameras(params?: CameraListRequest): Promise<IPageResponse<CameraInfoDTO>> {
- return post('/admin/cameras/list', params || {})
- }
- // 获取摄像头列表 (全部,不分页)
- export function adminListAllCameras(machineId?: string): Promise<IListResponse<CameraInfoDTO>> {
- return get('/admin/cameras/listAll', machineId ? { machineId } : undefined)
- }
- // 获取摄像头详情
- export function adminGetCamera(id: number): Promise<IBaseResponse<CameraInfoDTO>> {
- return get('/admin/cameras/detail', { id })
- }
- // 添加摄像头
- export function adminAddCamera(data: CameraAddRequest): Promise<IBaseResponse<CameraInfoDTO>> {
- return post('/admin/cameras/add', data)
- }
- // 更新摄像头
- export function adminUpdateCamera(data: CameraUpdateRequest): Promise<IBaseResponse<CameraInfoDTO>> {
- return post('/admin/cameras/update', data)
- }
- // 删除摄像头
- export function adminDeleteCamera(id: number): Promise<BaseResponse> {
- return post('/admin/cameras/delete', undefined, {
- params: { id }
- })
- }
- // 检测摄像头连通性
- export function adminCheckCamera(id: number): Promise<IBaseResponse<boolean>> {
- return post('/admin/cameras/check', undefined, {
- params: { id }
- })
- }
- // 获取摄像头快照
- export function adminGetSnapshot(id: number): Promise<IBaseResponse<Blob>> {
- return get('/admin/cameras/snapshot', { id }, { responseType: 'blob' })
- }
- // PTZ 控制 (Admin)
- export function adminPTZControl(data: AdminPTZRequest): Promise<IBaseResponse<boolean>> {
- return post('/admin/cameras/ptz', data)
- }
- // ==================== 兼容旧代码的别名 ====================
- // 获取设备列表 (兼容 - 使用不分页接口)
- export const listDevice = adminListAllCameras
- // 获取设备详情 (兼容)
- export const getDevice = (deviceId: string) => getCamera(deviceId)
- // 添加设备 (兼容)
- export const addDevice = adminAddCamera
- // 修改设备 (兼容)
- export const updateDevice = adminUpdateCamera
- // 删除设备 (兼容)
- export const delDevice = (id: number) => adminDeleteCamera(id)
- // PTZ控制 (兼容旧API)
- export function ptzControl(
- _deviceId: string,
- channelId: string,
- command: string,
- horizonSpeed?: number,
- _verticalSpeed?: number,
- _zoomSpeed?: number
- ): Promise<BaseResponse> {
- // 映射旧的命令到新的 action
- const actionMap: Record<string, PTZAction> = {
- up: 'up',
- down: 'down',
- left: 'left',
- right: 'right',
- zoomin: 'zoom_in',
- zoomout: 'zoom_out',
- stop: 'stop'
- }
- const action = actionMap[command.toLowerCase()] || 'stop'
- const speed = horizonSpeed || 50
- // 使用 channelId 关联的 cameraId 进行 PTZ 控制
- return ptzStart(channelId, action, speed)
- }
|