- src/api/camera: 新增 ptzControl / ptzStop / ptzPresetGoto / ptzPresetSet 及 PtzDirection、转速与预置点校验 - src/components/CameraPtzPanel: 8 方向按住转动(松手停止)、转速 1-7、预置点 1-8 快捷键与编号跳转/覆盖保存 - 防呆: 按下请求未返回时先记录、返回后补发 stop;window pointerup/pointercancel/blur 与卸载时兜底停止 - newcamara 预览弹窗接入云台面板
265 lines
5.3 KiB
TypeScript
265 lines
5.3 KiB
TypeScript
import request from '@/utils/request'
|
||
|
||
const v = '1.0'
|
||
|
||
/** 摄像头列表(仓库隔离,分页+筛选) */
|
||
export function list(data?: {
|
||
pagination?: { page?: number; pageSize?: number }
|
||
where?: { server_id?: number; custom_name?: string; status?: number }
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.list',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data: data || {},
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/** 摄像头详情 */
|
||
export function detail(data: { id: number }) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.detail',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data,
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/** 新增摄像头 */
|
||
export function create(data: {
|
||
server_id: number
|
||
channel_id: number
|
||
channel_name?: string
|
||
custom_name?: string
|
||
status?: number
|
||
username?: string
|
||
password?: string
|
||
remark?: string
|
||
ip?: string
|
||
port?: number
|
||
model?: string
|
||
serial_number?: string
|
||
stream_type?: string
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.create',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data,
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/** 更新摄像头 */
|
||
export function update(data: {
|
||
id: number
|
||
server_id?: number
|
||
channel_id?: number
|
||
channel_name?: string
|
||
custom_name?: string
|
||
status?: number
|
||
username?: string
|
||
password?: string
|
||
remark?: string
|
||
ip?: string
|
||
port?: number
|
||
model?: string
|
||
serial_number?: string
|
||
stream_type?: string
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.update',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data,
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/** 设置摄像头 OSD 文字叠加 */
|
||
export function setOsd(data: {
|
||
id: number
|
||
text: string
|
||
x?: number
|
||
y?: number
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.setOsd',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data,
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/** 删除摄像头(软删除) */
|
||
export function del(data: { id: number }) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.delete',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data,
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/** 云台方向:8 个位置(大小写不敏感,服务端统一转小写校验) */
|
||
export type PtzDirection =
|
||
| 'up'
|
||
| 'down'
|
||
| 'left'
|
||
| 'right'
|
||
| 'upleft'
|
||
| 'upright'
|
||
| 'downleft'
|
||
| 'downright'
|
||
|
||
/** 云台转速默认值(可选 1-7 的整数) */
|
||
export const PTZ_DEFAULT_SPEED = 4
|
||
|
||
/** 云台转速范围:1-7 的整数 */
|
||
export function normalizePtzSpeed(speed?: number): number {
|
||
const n = Number(speed)
|
||
if (!Number.isFinite(n)) return PTZ_DEFAULT_SPEED
|
||
const int = Math.round(n)
|
||
if (int < 1) return 1
|
||
if (int > 7) return 7
|
||
return int
|
||
}
|
||
|
||
/** 云台预置点范围:1-256 的整数 */
|
||
export function normalizePtzPresetId(presetId: number): number {
|
||
const n = Number(presetId)
|
||
if (!Number.isFinite(n)) return 0
|
||
const int = Math.round(n)
|
||
if (int < 1 || int > 256) return 0
|
||
return int
|
||
}
|
||
|
||
/**
|
||
* 云台方向控制(按下):按指定方向持续转动摄像头
|
||
* 必须配对调用 ptzStop 停止
|
||
*/
|
||
export function ptzControl(data: {
|
||
id: number
|
||
action: PtzDirection
|
||
speed?: number
|
||
}) {
|
||
const body: Record<string, unknown> = {
|
||
id: Number(data.id),
|
||
action: String(data.action || '').toLowerCase()
|
||
}
|
||
if (data.speed !== undefined && data.speed !== null) {
|
||
body.speed = normalizePtzSpeed(data.speed)
|
||
}
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.ptzControl',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data: body,
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/**
|
||
* 云台停止(松手):停止转动
|
||
* action 必须与按下时(ptzControl)一致
|
||
*/
|
||
export function ptzStop(data: {
|
||
id: number
|
||
action: PtzDirection
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.ptzStop',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data: {
|
||
id: Number(data.id),
|
||
action: String(data.action || '').toLowerCase()
|
||
},
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/**
|
||
* 云台预置点跳转:跳转到指定预置点
|
||
* 一次调用即可,无需 ptzStop
|
||
*/
|
||
export function ptzPresetGoto(data: {
|
||
id: number
|
||
presetId: number
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.ptzPresetGoto',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data: {
|
||
id: Number(data.id),
|
||
presetId: normalizePtzPresetId(data.presetId)
|
||
},
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|
||
|
||
/**
|
||
* 云台预置点设置:把摄像头当前机位保存为指定预置点
|
||
* 一次调用即可;已存在的编号会被当前机位覆盖
|
||
*/
|
||
export function ptzPresetSet(data: {
|
||
id: number
|
||
presetId: number
|
||
}) {
|
||
return request({
|
||
url: '/system',
|
||
method: 'post',
|
||
params: {
|
||
method: 'camera.ptzPresetSet',
|
||
v,
|
||
timestamp: new Date().getTime()
|
||
},
|
||
data: {
|
||
id: Number(data.id),
|
||
presetId: normalizePtzPresetId(data.presetId)
|
||
},
|
||
isSystemApi: true
|
||
} as any)
|
||
}
|