wangrong
2026-07-25 1219bbc5e2f999c65d8d8c83282777b468321fe0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
    <div class="monitor-page" style="height:100%;display:flex;gap:12px;">
        <!-- 左侧树形 -->
        <div class="left-tree" style="width:280px;border:1px solid var(--el-border-color);border-radius:6px;">
            <site-tree @select="handleTreeSelect" />
        </div>
 
        <!-- 右侧监控区域 -->
        <div class="right-player" style="flex:1;border:1px solid var(--el-border-color);border-radius:6px;padding:12px;overflow:auto;">
            <el-empty v-if="deviceList.length === 0" description="请左侧选择站点加载监控设备" />
            <div class="player-grid" v-if="deviceList.length">
                <div v-for="dev in deviceList" :key="dev.id" class="player-card">
                    <div class="title">{{ dev.iotName }}</div>
                    <EzuikitPlayer
                    v-if="ysToken"
                    :key="'p_' + dev.id + '_' + ysToken"
                    :container-id="'player_' + dev.id"
                    :access-token="ysToken"
                    :url="`ezopen://open.ys7.com/${dev.iotCode}/1.hd.live`"
                    />
                </div>
            </div>
        </div>
    </div>
</template>
 
<script lang="ts" setup>
defineOptions({
  name: 'monitor-device',
});
 
import { ref, onMounted } from 'vue';
import { useCool } from '/@/cool';
import SiteTree from '../components/site-tree.vue';
import EzuikitPlayer from '../../ezuikit/components/ezuikit-player.vue';
 
const { service } = useCool();
 
const deviceList = ref<any[]>([]);
let ysToken = ref('');
 
async function fetchYsToken() {
  if (ysToken.value) return;
  try {
    //const res = await service.monitor.ys7.getToken();
    const res = await service.base.sys.param.stringbykey({key:"ys7.accessToken"});
    ysToken = res;
  } catch (e: any) {
    console.error('萤石 Token 获取失败', e?.response?.data?.message || e.message);
  }
}
 
onMounted(fetchYsToken);
 
async function handleTreeSelect(businessId: string | number | null) {
  if (!businessId) {
    deviceList.value = [];
    return;
  }
  if (!ysToken.value) await fetchYsToken();
  try {
    const res = await service.basicdata.iot.getYsDevices({ businessId });
    deviceList.value = res || [];
  } catch {
    deviceList.value = [];
  }
}
</script>
 
<style lang="scss" scoped>
.monitor-page {
    height: 100%;
}
.left-tree {
    height: 100%;
}
.right-player {
    height: 100%;
}
.player-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
    gap: 16px;
}
.player-card {
    .title {
        padding: 6px 0;
        font-weight: 500;
    }
}
</style>