refactor: reorganize device card components
This commit is contained in:
61
src/components/device-page/device-card/decoder-card.vue
Normal file
61
src/components/device-page/device-card/decoder-card.vue
Normal file
@@ -0,0 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import type { NdmDecoderDiagInfo } from '@/apis/domains';
|
||||
import type { NdmDecoderResultVO } 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';
|
||||
|
||||
const props = defineProps<{
|
||||
stationCode: string;
|
||||
ndmDecoder: NdmDecoderResultVO;
|
||||
}>();
|
||||
|
||||
const { stationCode, ndmDecoder } = toRefs(props);
|
||||
|
||||
const lastDiagInfo = computed(() => {
|
||||
const result = destr<NdmDecoderDiagInfo>(ndmDecoder.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 selectedTab = ref('设备状态');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NCard size="small">
|
||||
<NTabs v-model:value="selectedTab" size="small">
|
||||
<NTabPane name="设备状态" tab="设备状态">
|
||||
<NFlex vertical>
|
||||
<DeviceHeaderCard :device="ndmDecoder" />
|
||||
<DeviceCommonCard :common-info="commonInfo" />
|
||||
<DeviceHardwareCard :cpu-usage="cpuUsage" :mem-usage="memUsage" />
|
||||
</NFlex>
|
||||
</NTabPane>
|
||||
<NTabPane name="历史诊断" tab="历史诊断"></NTabPane>
|
||||
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
|
||||
<!-- <NTabPane name="原始数据" tab="原始数据">
|
||||
<pre>{{ { ...ndmDecoder, lastDiagInfo } }}</pre>
|
||||
</NTabPane> -->
|
||||
</NTabs>
|
||||
</NCard>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
Reference in New Issue
Block a user