V4修复: 删除gateway.js 组件改用fetch直连网关
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
import request from '@/uitils/request'
|
||||
|
||||
// 网关 B 组接口封装。前端直连网关 :5100。
|
||||
// 生产环境通过 nginx 反向代理 /api/gateway/* → 网关地址。
|
||||
|
||||
const gwBase = '/api/gateway'
|
||||
|
||||
/// B6a: 获取实时视频流地址
|
||||
export const getLiveStream = (adapter, deviceId) =>
|
||||
request({ url: `${gwBase}/streams/${adapter}/${deviceId}/live`, method: 'get' })
|
||||
|
||||
/// B6b: 获取回放流地址
|
||||
export const getPlaybackStream = (adapter, deviceId, start, end) =>
|
||||
request({ url: `${gwBase}/streams/${adapter}/${deviceId}/playback`, method: 'get', params: { start, end } })
|
||||
|
||||
/// 获取截图
|
||||
export const getSnapshot = (adapter, deviceId) =>
|
||||
request({ url: `${gwBase}/streams/${adapter}/${deviceId}/snapshot`, method: 'post' })
|
||||
|
||||
/// B7: 云台方向控制
|
||||
export const ptzControl = (adapter, deviceId, direction, speed = 0.5) =>
|
||||
request({ url: `${gwBase}/streams/${adapter}/${deviceId}/ptz`, method: 'post', data: { direction, action: 'continuous', speed } })
|
||||
|
||||
/// B7: 云台停止
|
||||
export const ptzStop = (adapter, deviceId) =>
|
||||
request({ url: `${gwBase}/streams/${adapter}/${deviceId}/ptz`, method: 'post', data: { action: 'stop' } })
|
||||
|
||||
/// B4: 获取实时点位值
|
||||
export const getRealtime = (adapter, deviceId) =>
|
||||
request({ url: `${gwBase}/realtime/${adapter}/${deviceId}`, method: 'get' })
|
||||
|
||||
/// B5: 设备控制写值
|
||||
export const controlDevice = (adapter, deviceId, pointIndex, value) =>
|
||||
request({ url: `${gwBase}/realtime/${adapter}/control`, method: 'post', data: { deviceId, pointIndex, value } })
|
||||
|
||||
/// B8: 分页查询告警
|
||||
export const getAlarms = (adapter, params) =>
|
||||
request({ url: `${gwBase}/alarms/${adapter}`, method: 'get', params })
|
||||
|
||||
/// B9: 告警确认
|
||||
export const confirmAlarm = (adapter, alarmId) =>
|
||||
request({ url: `${gwBase}/alarms/${adapter}/${alarmId}/confirm`, method: 'post' })
|
||||
|
||||
/// B9: 告警结束
|
||||
export const endAlarm = (adapter, alarmId) =>
|
||||
request({ url: `${gwBase}/alarms/${adapter}/${alarmId}/end`, method: 'post' })
|
||||
|
||||
/// B3: 手动触发同步
|
||||
export const triggerSync = (adapter) =>
|
||||
request({ url: `${gwBase}/devices/sync`, method: 'post', params: { adapter } })
|
||||
@@ -1,12 +1,8 @@
|
||||
<template>
|
||||
<el-dialog v-model="visible" title="设备控制" width="400px">
|
||||
<el-form label-width="80px">
|
||||
<el-form-item label="点位索引">
|
||||
<el-input-number v-model="pointIndex" :min="0" />
|
||||
</el-form-item>
|
||||
<el-form-item label="目标值">
|
||||
<el-input-number v-model="value" :step="0.1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="点位索引"><el-input-number v-model="pointIndex" :min="0" /></el-form-item>
|
||||
<el-form-item label="目标值"><el-input-number v-model="value" :step="0.1" /></el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button type="primary" @click="send">发送指令</el-button>
|
||||
@@ -16,13 +12,15 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { controlDevice } from '@/api/gateway'
|
||||
const props = defineProps({ modelValue: Boolean, device: Object })
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
const visible = computed({ get: () => props.modelValue, set: v => emit('update:modelValue', v) })
|
||||
const pointIndex = ref(0), value = ref(0)
|
||||
const send = async () => {
|
||||
await controlDevice(props.device?.adapterCode, props.device?.sourceId, pointIndex.value, value.value)
|
||||
await fetch(`/api/gateway/realtime/${props.device?.adapterCode}/control`, {
|
||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ deviceId: props.device?.sourceId, pointIndex: pointIndex.value, value: value.value })
|
||||
})
|
||||
visible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { getLiveStream } from '@/api/gateway'
|
||||
|
||||
const props = defineProps({ modelValue: Boolean, device: Object })
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
@@ -21,7 +20,10 @@ const stop = () => { stream.value = null }
|
||||
watch(() => props.device, async (d) => {
|
||||
if (d && visible.value) {
|
||||
loading.value = true
|
||||
try { stream.value = await getLiveStream(d.adapterCode, d.sourceId) } catch(e) {}
|
||||
try {
|
||||
const resp = await fetch(`/api/gateway/streams/${d.adapterCode}/${d.sourceId}/live`)
|
||||
stream.value = await resp.json()
|
||||
} catch(e) {}
|
||||
finally { loading.value = false }
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
@@ -17,13 +17,15 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { ptzControl, ptzStop } from '@/api/gateway'
|
||||
const props = defineProps({ modelValue: Boolean, device: Object })
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
const visible = computed({ get: () => props.modelValue, set: v => emit('update:modelValue', v) })
|
||||
const go = (d) => {
|
||||
if (d === 'stop') ptzStop(props.device?.adapterCode, props.device?.sourceId)
|
||||
else ptzControl(props.device?.adapterCode, props.device?.sourceId, d)
|
||||
const send = (direction, speed = 0.5) => {
|
||||
fetch(`/api/gateway/streams/${props.device?.adapterCode}/${props.device?.sourceId}/ptz`, {
|
||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ direction, action: 'continuous', speed })
|
||||
})
|
||||
}
|
||||
const stop = () => go('stop')
|
||||
const go = (d) => d === 'stop' ? send('stop') : send(d)
|
||||
const stop = () => send('stop')
|
||||
</script>
|
||||
|
||||
@@ -13,21 +13,22 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, computed, watch, onUnmounted } from 'vue'
|
||||
import { getRealtime } from '@/api/gateway'
|
||||
const props = defineProps({ modelValue: Boolean, device: Object })
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
const visible = computed({ get: () => props.modelValue, set: v => emit('update:modelValue', v) })
|
||||
const values = ref([]), loading = ref(false)
|
||||
let timer = null
|
||||
|
||||
const fetch = async () => {
|
||||
const fetchData = async () => {
|
||||
if (!props.device) return
|
||||
loading.value = true
|
||||
try { values.value = await getRealtime(props.device.adapterCode, props.device.sourceId) } catch {}
|
||||
try {
|
||||
const resp = await fetch(`/api/gateway/realtime/${props.device.adapterCode}/${props.device.sourceId}`)
|
||||
values.value = await resp.json()
|
||||
} catch {}
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
watch(() => props.device, () => { if (visible.value) { fetch(); timer = setInterval(fetch, 5000) } }, { immediate: true })
|
||||
watch(visible, v => { if (v) { fetch(); timer = setInterval(fetch, 5000) } else { clearInterval(timer) } })
|
||||
watch(visible, v => { if (v) { fetchData(); timer = setInterval(fetchData, 5000) } else { clearInterval(timer) } })
|
||||
onUnmounted(() => clearInterval(timer))
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user