diff --git a/apps/web-antd/src/api/aiot/device/index.ts b/apps/web-antd/src/api/aiot/device/index.ts index bcffe8f33..6dd952945 100644 --- a/apps/web-antd/src/api/aiot/device/index.ts +++ b/apps/web-antd/src/api/aiot/device/index.ts @@ -1,99 +1,166 @@ -import type { PageParam, PageResult } from '@vben/request'; +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; - channelId?: string; - channelName?: string; + roiId?: string; + cameraId?: string; + deviceId?: string; name?: string; - type?: string; - points?: string; - enabled?: boolean; - createdAt?: string; - updatedAt?: string; + roiType?: string; // rectangle | polygon + coordinates?: string; + color?: string; + priority?: number; + enabled?: number; // 0 | 1 + description?: string; + algorithms?: RoiAlgoBinding[]; } - /** ROI 算法绑定 */ - export interface RoiAlgoBind { - id?: number; - roiId?: number; - algorithmId?: number; - algorithmName?: string; - enabled?: boolean; - config?: Record; + /** 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; - name?: string; - code?: string; + algoCode?: string; + algoName?: string; description?: string; - enabled?: boolean; + isActive?: boolean; + paramSchema?: string; } - /** 摄像头通道 */ - export interface Channel { - channelId?: string; - name?: string; - manufacturer?: string; - status?: string; - ptztypeText?: string; - longitudeWgs84?: number; - latitudeWgs84?: number; + /** 摄像头(拉流代理) */ + export interface Camera { + id?: number; + app?: string; + stream?: string; + srcUrl?: 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 } }); +} + // ==================== ROI 区域管理 API ==================== -/** 获取 ROI 列表 */ -export function getRoiPage(params: PageParam) { - return wvpRequestClient.get>( - '/aiot/device/roi/list', - { params }, - ); +/** 获取 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: AiotDeviceApi.Roi) { +export function saveRoi(data: Partial) { return wvpRequestClient.post('/aiot/device/roi/save', data); } /** 删除 ROI */ -export function deleteRoi(id: number) { - return wvpRequestClient.delete(`/aiot/device/roi/delete?id=${id}`); +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: number; algorithmId: number }) { +export function bindAlgo(data: { roiId: string; algoCode: string }) { return wvpRequestClient.post('/aiot/device/roi/bindAlgo', data); } /** 解绑算法 */ -export function unbindAlgo(bindId: number) { - return wvpRequestClient.delete( - `/aiot/device/roi/unbindAlgo?bindId=${bindId}`, - ); +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', - ); + return wvpRequestClient.get('/aiot/device/algorithm/list'); } -// ==================== 摄像头通道 API ==================== +// ==================== 配置推送 API ==================== -/** 获取摄像头通道列表 */ -export function getChannelPage(params: PageParam) { - return wvpRequestClient.get>( - '/aiot/device/channel/list', - { params }, - ); +/** 推送配置到边缘端 */ +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 }, + }); }