去掉不必要的配置

This commit is contained in:
denggaofeng 2026-03-25 17:46:52 +08:00
parent 1bb1e72f66
commit fe9229f044
4 changed files with 97 additions and 46 deletions

View File

@ -3,8 +3,13 @@
<!-- 顶部导航 -->
<header class="nav-bar">
<span class="nav-title">Real-time Monitoring</span>
<select v-model="selectedDeviceId" class="device-select" @change="onDeviceChange">
<option v-for="device in deviceList" :key="device.DeviceId" :value="device.DeviceId">
{{ device.DeviceName }}
</option>
</select>
<!-- <button class="layout-btn" @click="toggleLayout">
{{ layout === 1 ? '⊞ 四画面' : '⊡ 单画面' }}
{{ layout === 1 ? '⊞ Quad View' : '⊡ Single View' }}
</button> -->
</header>
@ -15,8 +20,6 @@
:key="i - 1"
:ref="(el) => setBoxRef(el, i - 1)"
:source="playingSources[i - 1] ? sourcesMap[playingSources[i - 1]!] : null"
:server-ip="config.serverIp"
:media-port="config.media_http_api"
@close="closeVideo(i - 1)"
@ready="onVideoReady($event, i - 1)"
/>
@ -51,26 +54,33 @@
import { ref, reactive, onMounted, onBeforeUnmount } from 'vue'
import VideoBox from './components/VideoBox.vue'
import { createApis } from './api'
import type { GlobalConfig, SourceItem, VideoInfo } from './types'
import type { GlobalConfig, SourceItem, VideoInfo, DeviceItem } from './types'
declare const mqtt: any
const deviceId = 'fcfabf1d5dd036033419057075a56304' // ID使
const selectedDeviceId = ref<string>('')
const deviceList = ref<DeviceItem[]>([])
// const config = reactive<GlobalConfig>({
// serverIp: '118.145.200.78',
// getSources: ':3000/ks/source',
// subscribe: ':3000/stream/live/subscribe',
// resultTopic: 'ks/video_detection',
// streamInfoTopic: 'ks/stream_local',
// media_http_api: 3001,
// websocket: 8083,
// mqttAuth: ['work', 'Bjhmdys@202010'],
// accessKey: '6952564ceb712e2daeea7039',
// accessSecret: 'df717a60-85b7-4a63-b638-0aed4605d277',
// token: '',
// getToken: ':3000/ks/system/user/token',
// getTime: ':3000/ks/system/time',
// })
const config = reactive<GlobalConfig>({
serverIp: '118.145.200.78',
getSources: ':3000/ks/source',
subscribe: ':3000/stream/live/subscribe',
resultTopic: 'ks/video_detection',
streamInfoTopic: 'ks/stream_local',
media_http_api: 3001,
websocket: 8083,
mqttAuth: ['work', 'Bjhmdys@202010'],
accessKey: '6952564ceb712e2daeea7039',
accessSecret: 'df717a60-85b7-4a63-b638-0aed4605d277',
token: '',
getToken: ':3000/ks/system/user/token',
getTime: ':3000/ks/system/time',
})
const layout = ref<1 | 4>(1)
@ -83,7 +93,7 @@ const playingSources = reactive<(string | null)[]>([null, null, null, null])
const boxRefs: (InstanceType<typeof VideoBox> | null)[] = [null, null, null, null]
let mqttClient: any = null
let apis = createApis(config)
let apis = createApis()
function setBoxRef(el: any, index: number) {
boxRefs[index] = el
@ -197,12 +207,44 @@ async function connectMqtt() {
})
}
function onDeviceChange() {
//
for (let i = 0; i < 4; i++) {
if (playingSources[i]) closeVideo(i)
}
//
sourceList.value = []
//
loadSources(selectedDeviceId.value)
}
onMounted(async () => {
try {
//const tokenRes = await apis.getToken()
// if (tokenRes.error_code === 0) {
//config.token = tokenRes.data
apis = createApis(config)
apis = createApis()
//
const devicesRes = await apis.getDevices()
deviceList.value = devicesRes
if (devicesRes.length > 0) {
selectedDeviceId.value = devicesRes[0].DeviceId
}
//
if (selectedDeviceId.value) {
await loadSources(selectedDeviceId.value)
}
//}
} catch (e) {
console.error('初始化失败', e)
}
connectMqtt()
})
async function loadSources(deviceId: string) {
try {
const sourcesRes = await apis.getSources(deviceId)
sourceList.value = sourcesRes.map((item) => {
item.sourceId = item.id
@ -212,12 +254,10 @@ onMounted(async () => {
sourcesMap[item.id] = item
return item
})
//}
} catch (e) {
console.error('初始化失败', e)
console.error('加载源列表失败', e)
}
}
connectMqtt()
})
onBeforeUnmount(() => {
mqttClient?.end()
@ -275,6 +315,23 @@ html, body {
letter-spacing: 1px;
}
.device-select {
background: rgba(0, 180, 255, 0.15);
border: 1px solid #0af;
color: #0af;
border-radius: 6px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
outline: none;
margin-left: 10px;
}
.device-select option {
background: #0d1b2e;
color: #e0f0ff;
}
.layout-btn {
background: rgba(0, 180, 255, 0.15);
border: 1px solid #0af;

View File

@ -1,7 +1,7 @@
import type { GlobalConfig, SourceItem, MqttServerInfo, DeviceItem } from '../types'
// import { generateSignature, generateRandomString } from '../utils/signature'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createApis(config: GlobalConfig) {
export function createApis() {
// const baseUrl = () => `http://${config.serverIp}`
// const authHeader = () => ({ Authorization: `Bearer ${config.token}` })
@ -43,5 +43,5 @@ export function createApis(config: GlobalConfig) {
return await window.HybridWebView.InvokeDotNet<DeviceItem[]>('GetDevicesAsync')
}
return { getSources, subscribeLive, GetMqttServerProxyInfo }
return { getSources, subscribeLive, GetMqttServerProxyInfo, getDevices }
}

View File

@ -44,8 +44,6 @@ declare const ZLMRTCClient: any
const props = defineProps<{
source: SourceItem | null
serverIp: string
mediaPort: number
}>()
const emit = defineEmits<{
@ -151,14 +149,10 @@ function playVideo(stream: string) {
const video = videoRef.value
if (!video) return
const streamUrl = stream
.replace('127.0.0.1', props.serverIp)
.replace('1985', String(props.mediaPort))
const srsrtc = new ZLMRTCClient.Endpoint({
element: video,
debug: false,
zlmsdpUrl: streamUrl,
zlmsdpUrl: stream,
simulcast: false,
useCamera: true,
audioEnable: true,

View File

@ -1,17 +1,17 @@
export interface GlobalConfig {
serverIp: string
getSources: string
subscribe: string
// serverIp: string
// getSources: string
// subscribe: string
resultTopic: string
streamInfoTopic: string
media_http_api: number
websocket: number
mqttAuth: [string, string]
accessKey: string
accessSecret: string
token: string
getToken: string
getTime: string
// media_http_api: number
// websocket: number
// mqttAuth: [string, string]
// accessKey: string
// accessSecret: string
// token: string
// getToken: string
// getTime: string
}
export interface AlgInfo {