Fix-F2-F4: B4-batch+批量离线+凭据安全+前端地址+异常日志+滞后窗+console清理+API统一+Swagger+文档同步
This commit is contained in:
126
web.vite/src/api/gateway.js
Normal file
126
web.vite/src/api/gateway.js
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 网关 B 组接口封装
|
||||
* 所有网关 API 调用使用 fetch() 直连,不走 Vol.Pro 后端中转
|
||||
*/
|
||||
|
||||
const GW_BASE = 'http://192.168.3.108:5100'
|
||||
|
||||
/** GET 请求网关 */
|
||||
export async function gwGet(url: string): Promise<any> {
|
||||
const resp = await fetch(`${GW_BASE}${url}`)
|
||||
if (!resp.ok) throw new Error(`网关请求失败: ${resp.status}`)
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
/** POST 请求网关 */
|
||||
export async function gwPost(url: string, body?: object): Promise<any> {
|
||||
const resp = await fetch(`${GW_BASE}${url}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: body ? JSON.stringify(body) : undefined
|
||||
})
|
||||
if (!resp.ok) throw new Error(`网关请求失败: ${resp.status}`)
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════
|
||||
// 数据模型
|
||||
// ═══════════════════════════════════════════
|
||||
|
||||
/** 统一设备模型(对应网关 StandardDevice) */
|
||||
export interface StandardDevice {
|
||||
deviceId: number
|
||||
adapterCode: string
|
||||
sourceId: string
|
||||
name: string
|
||||
category: string
|
||||
group: string
|
||||
isParent: boolean
|
||||
parentSourceId?: string
|
||||
isOnline: boolean
|
||||
ipAddress?: string
|
||||
port?: number
|
||||
extra?: Record<string, any>
|
||||
}
|
||||
|
||||
/** 摄像机视图模型 */
|
||||
export interface Camera {
|
||||
id: string
|
||||
name: string
|
||||
location: string
|
||||
status: 'online' | 'offline'
|
||||
adapterCode: string
|
||||
sourceId: string
|
||||
streamUrl?: string
|
||||
hasPtz: boolean
|
||||
}
|
||||
|
||||
/** 视频流地址集合 */
|
||||
export interface StreamUrls {
|
||||
wsFlv?: string
|
||||
httpFlv?: string
|
||||
hls?: string
|
||||
webRtc?: string
|
||||
rtmp?: string
|
||||
rtsp?: string
|
||||
}
|
||||
|
||||
/** 分页容器 */
|
||||
export interface PagedResult<T> {
|
||||
items: T[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 实时点位值 */
|
||||
export interface PointValue {
|
||||
sourceDeviceId: string
|
||||
pointIndex: number
|
||||
value: number
|
||||
updateTime?: string
|
||||
interval: number
|
||||
}
|
||||
|
||||
/** 告警模型 */
|
||||
export interface StandardAlarm {
|
||||
alarmId: string
|
||||
deviceId?: string
|
||||
adapterCode: string
|
||||
level: string
|
||||
title: string
|
||||
content?: string
|
||||
occurTime: string
|
||||
status: string
|
||||
actualValue?: number
|
||||
thresholdValue?: number
|
||||
}
|
||||
|
||||
/** 设备树节点 */
|
||||
export interface DeviceTreeNode {
|
||||
id: number
|
||||
sourceId: string
|
||||
name: string
|
||||
type: number
|
||||
objectType: number
|
||||
tag?: string
|
||||
option?: Record<string, any>
|
||||
children: DeviceTreeNode[]
|
||||
}
|
||||
|
||||
/** StandardDevice → Camera 映射 */
|
||||
export function toCamera(d: StandardDevice): Camera {
|
||||
return {
|
||||
id: d.sourceId,
|
||||
name: d.name,
|
||||
location: d.extra?.location || '',
|
||||
status: d.isOnline ? 'online' : 'offline',
|
||||
adapterCode: d.adapterCode,
|
||||
sourceId: d.sourceId,
|
||||
hasPtz: d.extra?.hasPtz === '1' || d.extra?.hasPtz === true
|
||||
}
|
||||
}
|
||||
|
||||
/** 从网关获取设备列表并映射为 Camera[] */
|
||||
export async function fetchCameras(adapter: string): Promise<Camera[]> {
|
||||
const data = await gwGet(`/api/gateway/devices?adapter=${adapter}&page=1&size=100`)
|
||||
return (data.items || []).map(toCamera)
|
||||
}
|
||||
@@ -82,7 +82,7 @@
|
||||
const { proxy } = getCurrentInstance()
|
||||
const { table, editFormFields, editFormOptions, searchFormFields, searchFormOptions, columns, detail, details } = reactive(viewOptions())
|
||||
|
||||
const GW = 'http://localhost:5100'
|
||||
const GW = window.apiConfig?.gatewayUrl || 'http://localhost:5100'
|
||||
let gridRef, _timer;
|
||||
|
||||
//── 对话框状态 ──
|
||||
|
||||
Reference in New Issue
Block a user