This commit is contained in:
denggaofeng 2026-03-26 14:49:49 +08:00
parent fe9229f044
commit d075dabf2a
2 changed files with 32 additions and 8 deletions

View File

@ -58,7 +58,6 @@ import type { GlobalConfig, SourceItem, VideoInfo, DeviceItem } from './types'
declare const mqtt: any declare const mqtt: any
const deviceId = 'fcfabf1d5dd036033419057075a56304' // ID使
const selectedDeviceId = ref<string>('') const selectedDeviceId = ref<string>('')
const deviceList = ref<DeviceItem[]>([]) const deviceList = ref<DeviceItem[]>([])
@ -150,7 +149,7 @@ function openVideo(id: string, index: number) {
if (box && sourcesMap[id]) { if (box && sourcesMap[id]) {
box.subscribeLive(sourcesMap[id]) box.subscribeLive(sourcesMap[id])
// //
apis.subscribeLive(deviceId,id).then((res) => { apis.subscribeLive(selectedDeviceId.value,id).then((res) => {
if (res) { if (res) {
box.startPlay(res) box.startPlay(res)
} else { } else {
@ -170,6 +169,24 @@ function closeVideo(index: number) {
boxRefs[index]?.destroy() boxRefs[index]?.destroy()
} }
//
function cleanupAll() {
//
for (let i = 0; i < 4; i++) {
if (playingSources[i]) {
closeVideo(i)
}
}
//
playingSources.fill(null)
boxRefs.fill(null)
sourceList.value = []
// MQTT
mqttClient?.end(true)
mqttClient = null
drawerOpen.value = false
}
// VideoBox ready videoInfo // VideoBox ready videoInfo
function onVideoReady(_info: VideoInfo, _index: number) { function onVideoReady(_info: VideoInfo, _index: number) {
// //
@ -219,10 +236,14 @@ function onDeviceChange() {
} }
onMounted(async () => { onMounted(async () => {
window.cleanupAll = cleanupAll;
window.handleInit = handleInit;
await handleInit()
})
async function handleInit(){
try { try {
//const tokenRes = await apis.getToken()
// if (tokenRes.error_code === 0) {
//config.token = tokenRes.data
apis = createApis() apis = createApis()
// //
@ -236,12 +257,12 @@ onMounted(async () => {
if (selectedDeviceId.value) { if (selectedDeviceId.value) {
await loadSources(selectedDeviceId.value) await loadSources(selectedDeviceId.value)
} }
//}
} catch (e) { } catch (e) {
console.error('初始化失败', e) console.error('初始化失败', e)
} }
connectMqtt() connectMqtt()
}) }
async function loadSources(deviceId: string) { async function loadSources(deviceId: string) {
try { try {
@ -260,7 +281,8 @@ async function loadSources(deviceId: string) {
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
mqttClient?.end() window.cleanupAll = () => {};
window.handleInit = () => {};
}) })
</script> </script>

View File

@ -1,5 +1,7 @@
declare interface Window { declare interface Window {
HybridWebView: HybridWebView HybridWebView: HybridWebView
cleanupAll: () => void
handleInit: () => void
} }
declare interface HybridWebView { declare interface HybridWebView {
InvokeDotNet(methodName: string, ...args: any[]): Promise<T>; InvokeDotNet(methodName: string, ...args: any[]): Promise<T>;