<template>
    <div class="_energy">
        <layout>
            <template #left>
                <div style="height: 100%;display: flex;flex-direction: column;overflow: hidden;">
                    <consume :resultData="leftData" style="height: 35%;" />
                    <running :resultData="leftData.MonitorList" style="flex: 1;" />
                    <!-- <carbonEmission :resultData="leftData" style="flex: 1;" /> -->
                </div>
            </template>
            <template #content>
                <!-- <p>视频</p> -->
            </template>
            <template #right>
                <div style="height: 100%;display: flex;flex-direction: column;overflow: hidden;">
                    <sameDay :resultData="leftData" style="height: 35%;" />
                    <eventList :resultData="leftData.MonitorNms" style="flex: 1;" />
                </div>
            </template>
        </layout>
    </div>
</template>

<script setup name="Role">
import { getHikvision } from "@/api/system/monitor"
import layout from "@/components/layout_/index.vue";
import consume from './modules/consume.vue'
import running from './modules/running.vue'
import carbonEmission from './modules/carbonEmission.vue'
import sameDay from './modules/sameDay.vue'
import eventList from './modules/eventList.vue'

const route = useRoute()
const intervalId = ref(null)
const leftData = ref({})
// 生命周期
onMounted(() => {
    getHikvisionData()
});
onUnmounted(() => {
    clearInterval(intervalId.value);
})
function getHikvisionData() {
    clearInterval(intervalId.value);
    getHikvision().then((res) => {
        if (res.code == 200) {
            leftData.value = res.data
            if (route.path == '/system/video') {
                intervalId.value = setInterval(() => {
                    getHikvisionData()
                    clearInterval(intervalId.value);
                }, 10000);
            } else {
                clearInterval(intervalId.value);
                intervalId.value = null
            }
        }
    }).catch(() => {
        if (route.path == '/system/video') {
            intervalId.value = null
            getHikvisionData()
        }
    })
}
</script>
<style lang="scss">
._energy {
    height: 100%;
}
</style>