import { useAppConfig } from '@vben/hooks'; import { wvpRequestClient } from '#/api/aiot/request'; const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD); export namespace AiotDeviceApi { /** ROI 区域 */ export interface Roi { id?: number; roiId?: string; cameraId?: string; deviceId?: string; name?: string; roiType?: string; // rectangle | polygon coordinates?: string; color?: string; priority?: number; enabled?: number; // 0 | 1 description?: string; algorithms?: RoiAlgoBinding[]; } /** ROI 算法绑定(详情里的嵌套结构) */ export interface RoiAlgoBinding { bind: AlgoBind; algorithm?: Algorithm; } /** 算法绑定记录 */ export interface AlgoBind { bindId?: string; roiId?: string; algoCode?: string; enabled?: number; params?: string; } /** 算法 */ export interface Algorithm { id?: number; algoCode?: string; algoName?: string; description?: string; isActive?: boolean; paramSchema?: string; } /** 摄像头(拉流代理) */ export interface Camera { id?: number; type?: string; // default | ffmpeg app?: string; stream?: string; srcUrl?: string; timeout?: number; rtspType?: string; // 0=TCP, 1=UDP, 2=Multicast enable?: boolean; enableAudio?: boolean; enableMp4?: boolean; enableDisableNoneReader?: boolean; relatesMediaServerId?: string; ffmpegCmdKey?: string; pulling?: boolean; mediaServerId?: string; } } // ==================== 摄像头管理 API ==================== /** 获取摄像头列表 */ export function getCameraList(params: { page: number; count: number; query?: string; pulling?: boolean; }) { return wvpRequestClient.get('/aiot/device/proxy/list', { params }); } /** 开始拉流 */ export function startCamera(id: number) { return wvpRequestClient.get('/aiot/device/proxy/start', { params: { id } }); } /** 停止拉流 */ export function stopCamera(id: number) { return wvpRequestClient.get('/aiot/device/proxy/stop', { params: { id } }); } /** 保存摄像头(新增/编辑) */ export function saveCamera(data: Partial) { return wvpRequestClient.post('/aiot/device/proxy/save', data); } /** 删除摄像头 */ export function deleteCamera(id: number) { return wvpRequestClient.delete('/aiot/device/proxy/delete', { params: { id }, }); } /** 获取在线媒体服务器列表 */ export function getMediaServerList() { return wvpRequestClient.get('/aiot/device/server/online/list'); } // ==================== ROI 区域管理 API ==================== /** 获取 ROI 列表(分页) */ export function getRoiList(params: { page: number; count: number; cameraId?: string; deviceId?: string; query?: string; }) { return wvpRequestClient.get('/aiot/device/roi/list', { params }); } /** 获取 ROI 详情 */ export function getRoiDetail(id: number) { return wvpRequestClient.get(`/aiot/device/roi/${id}`); } /** 获取某摄像头的所有 ROI */ export function getRoiByCameraId(cameraId: string) { return wvpRequestClient.get('/aiot/device/roi/channel', { params: { cameraId }, }); } /** 保存 ROI */ export function saveRoi(data: Partial) { return wvpRequestClient.post('/aiot/device/roi/save', data); } /** 删除 ROI */ export function deleteRoi(roiId: string) { return wvpRequestClient.delete(`/aiot/device/roi/delete/${roiId}`); } /** 获取截图 URL */ export function getSnapUrl(app: string, stream: string) { return `${apiURL}/aiot/device/roi/snap?app=${encodeURIComponent(app)}&stream=${encodeURIComponent(stream)}&t=${Date.now()}`; } // ==================== 算法绑定 API ==================== /** 绑定算法到 ROI */ export function bindAlgo(data: { roiId: string; algoCode: string }) { return wvpRequestClient.post('/aiot/device/roi/bindAlgo', data); } /** 解绑算法 */ export function unbindAlgo(bindId: string) { return wvpRequestClient.delete('/aiot/device/roi/unbindAlgo', { params: { bindId }, }); } /** 更新算法参数 */ export function updateAlgoParams(data: { bindId: string; params?: string; enabled?: number; }) { return wvpRequestClient.post('/aiot/device/roi/updateAlgoParams', data); } // ==================== 算法管理 API ==================== /** 获取算法列表 */ export function getAlgorithmList() { return wvpRequestClient.get('/aiot/device/algorithm/list'); } // ==================== 配置推送 API ==================== /** 推送配置到边缘端 */ export function pushConfig(cameraId: string) { return wvpRequestClient.post('/aiot/device/config/push', null, { params: { cameraId }, }); } /** 导出配置 */ export function exportConfig(cameraId: string) { return wvpRequestClient.get('/aiot/device/config/export', { params: { cameraId }, }); }