refactor: reorganize device card components
This commit is contained in:
72
src/components/device-page/device-card/security-box-card.vue
Normal file
72
src/components/device-page/device-card/security-box-card.vue
Normal file
@@ -0,0 +1,72 @@
|
||||
<script setup lang="ts">
|
||||
import type { NdmSecurityBoxDiagInfo } from '@/apis/domains';
|
||||
import type { NdmSecurityBoxResultVO } from '@/apis/models';
|
||||
import { destr } from 'destr';
|
||||
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
|
||||
import { computed, ref, toRefs } from 'vue';
|
||||
|
||||
import DeviceHeaderCard from './current-diag-card/device-header-card.vue';
|
||||
import DeviceCommonCard from './current-diag-card/device-common-card.vue';
|
||||
import DeviceHardwareCard from './current-diag-card/device-hardware-card.vue';
|
||||
import SecurityBoxInfoCard from './current-diag-card/security-box-info-card.vue';
|
||||
import SecurityBoxCircuitCard from './current-diag-card/security-box-circuit-card.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
stationCode: string;
|
||||
ndmSecurityBox: NdmSecurityBoxResultVO;
|
||||
}>();
|
||||
|
||||
const { stationCode, ndmSecurityBox } = toRefs(props);
|
||||
|
||||
const lastDiagInfo = computed(() => {
|
||||
const result = destr<NdmSecurityBoxDiagInfo>(ndmSecurityBox.value.lastDiagInfo);
|
||||
if (!result) return null;
|
||||
if (typeof result !== 'object') return null;
|
||||
return result;
|
||||
});
|
||||
|
||||
const commonInfo = computed<Record<string, string> | undefined>(() => {
|
||||
const info = lastDiagInfo.value?.stCommonInfo;
|
||||
if (info) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { CPU使用率, 内存使用率, ...rest } = info;
|
||||
return rest;
|
||||
}
|
||||
return info;
|
||||
});
|
||||
|
||||
const cpuUsage = computed(() => lastDiagInfo.value?.stCommonInfo.CPU使用率);
|
||||
const memUsage = computed(() => lastDiagInfo.value?.stCommonInfo.内存使用率);
|
||||
|
||||
const fanSpeeds = computed(() => lastDiagInfo.value?.info.at(0)?.fanSpeeds);
|
||||
const temperature = computed(() => lastDiagInfo.value?.info.at(0)?.temperature);
|
||||
const humidity = computed(() => lastDiagInfo.value?.info.at(0)?.humidity);
|
||||
const switches = computed(() => lastDiagInfo.value?.info.at(0)?.switches);
|
||||
|
||||
const circuits = computed(() => lastDiagInfo.value?.info.at(0)?.circuits);
|
||||
|
||||
const selectedTab = ref('设备状态');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NCard size="small">
|
||||
<NTabs v-model:value="selectedTab" size="small">
|
||||
<NTabPane name="设备状态" tab="设备状态">
|
||||
<NFlex vertical>
|
||||
<DeviceHeaderCard :device="ndmSecurityBox" />
|
||||
<DeviceCommonCard :common-info="commonInfo" />
|
||||
<DeviceHardwareCard :cpu-usage="cpuUsage" :mem-usage="memUsage" />
|
||||
<SecurityBoxInfoCard :fan-speeds="fanSpeeds" :temperature="temperature" :humidity="humidity" :switches="switches" />
|
||||
<SecurityBoxCircuitCard :station-code="stationCode" :ndm-security-box="ndmSecurityBox" :circuits="circuits" />
|
||||
</NFlex>
|
||||
</NTabPane>
|
||||
<NTabPane name="诊断历史" tab="诊断历史"></NTabPane>
|
||||
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
|
||||
<!-- <NTabPane name="原始数据" tab="原始数据">
|
||||
<pre>{{ { ...ndmSecurityBox, lastDiagInfo } }}</pre>
|
||||
</NTabPane> -->
|
||||
</NTabs>
|
||||
</NCard>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
Reference in New Issue
Block a user