V4修复: 网关调用用fetch直连localhost:5100, 框架调用保持proxy.http

This commit is contained in:
2026-05-17 13:21:27 +08:00
parent 12d2662bd1
commit b0a3141c79
4 changed files with 17 additions and 17 deletions

View File

@@ -11,15 +11,16 @@
</el-dialog>
</template>
<script setup>
import { ref, computed, getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
import { ref, computed } from 'vue'
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 = () => {
const url = `api/gateway/realtime/${props.device?.adapterCode}/control`
proxy.http.post(url, { deviceId: props.device?.sourceId, pointIndex: pointIndex.value, value: value.value })
fetch(`http://localhost:5100/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>

View File

@@ -8,8 +8,7 @@
</el-dialog>
</template>
<script setup>
import { ref, computed, watch, getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
import { ref, computed, watch } from 'vue'
const props = defineProps({ modelValue: Boolean, device: Object })
const emit = defineEmits(['update:modelValue'])
const visible = computed({ get: () => props.modelValue, set: v => emit('update:modelValue', v) })
@@ -19,8 +18,8 @@ const stop = () => { stream.value = null }
watch(() => props.device, async (d) => {
if (d && visible.value) {
loading.value = true
const url = `api/gateway/streams/${d.adapterCode}/${d.sourceId}/live`
proxy.http.get(url, {}, true).then(r => { stream.value = r }).finally(() => loading.value = false)
try { const r = await fetch(`http://localhost:5100/api/gateway/streams/${d.adapterCode}/${d.sourceId}/live`); stream.value = await r.json() }
catch {} finally { loading.value = false }
}
}, { immediate: true })
</script>

View File

@@ -16,14 +16,15 @@
</el-dialog>
</template>
<script setup>
import { computed, getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
import { computed } from 'vue'
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 send = (direction, speed = 0.5) => {
const url = `api/gateway/streams/${props.device?.adapterCode}/${props.device?.sourceId}/ptz`
proxy.http.post(url, { direction, action: direction === 'stop' ? 'stop' : 'continuous', speed })
fetch(`http://localhost:5100/api/gateway/streams/${props.device?.adapterCode}/${props.device?.sourceId}/ptz`, {
method: 'POST', headers: {'Content-Type':'application/json'},
body: JSON.stringify({ direction, action: direction === 'stop' ? 'stop' : 'continuous', speed })
})
}
const go = (d) => send(d)
const stop = () => send('stop')

View File

@@ -10,18 +10,17 @@
</el-dialog>
</template>
<script setup>
import { ref, computed, watch, onUnmounted, getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
import { ref, computed, watch, onUnmounted } from 'vue'
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 fetchData = () => {
const fetchData = async () => {
if (!props.device) return
loading.value = true
const url = `api/gateway/realtime/${props.device.adapterCode}/${props.device.sourceId}`
proxy.http.get(url, {}, false).then(r => { values.value = r || [] }).finally(() => loading.value = false)
try { const r = await fetch(`http://localhost:5100/api/gateway/realtime/${props.device.adapterCode}/${props.device.sourceId}`); values.value = await r.json() }
catch {} finally { loading.value = false }
}
watch(visible, v => { if (v) { fetchData(); timer = setInterval(fetchData, 5000) } else { clearInterval(timer) } })
onUnmounted(() => clearInterval(timer))