refactor(ndm-security-box-diag-info): make all fields optional
This commit is contained in:
@@ -1,23 +1,24 @@
|
|||||||
export interface NdmSecurityBoxDiagInfo {
|
export interface NdmSecurityBoxDiagInfo {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
info: [
|
info?: [
|
||||||
{
|
{
|
||||||
addrCode: number;
|
addrCode?: number;
|
||||||
circuits: NdmSecurityBoxCircuit[];
|
circuits?: NdmSecurityBoxCircuit[];
|
||||||
fanSpeeds: number[];
|
fanSpeeds?: number[];
|
||||||
humidity: number;
|
humidity?: number;
|
||||||
switches: number[];
|
switches?: number[];
|
||||||
temperature: number;
|
temperature?: number;
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
stCommonInfo: {
|
stCommonInfo?: {
|
||||||
内存使用率: string;
|
[key: string]: any;
|
||||||
CPU使用率: string;
|
内存使用率?: string;
|
||||||
|
CPU使用率?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NdmSecurityBoxCircuit {
|
export interface NdmSecurityBoxCircuit {
|
||||||
current: number;
|
current?: number;
|
||||||
status: number;
|
status?: number;
|
||||||
voltage: number;
|
voltage?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ const debugModeStore = useDebugModeStore();
|
|||||||
const { stationCode, ndmSecurityBox } = toRefs(props);
|
const { stationCode, ndmSecurityBox } = toRefs(props);
|
||||||
|
|
||||||
const lastDiagInfo = computed(() => {
|
const lastDiagInfo = computed(() => {
|
||||||
const result = destr<NdmSecurityBoxDiagInfo>(ndmSecurityBox.value.lastDiagInfo);
|
const result = destr<any>(ndmSecurityBox.value.lastDiagInfo);
|
||||||
if (!result) return null;
|
if (!result) return null;
|
||||||
if (typeof result !== 'object') return null;
|
if (typeof result !== 'object') return null;
|
||||||
return result;
|
return result as NdmSecurityBoxDiagInfo;
|
||||||
});
|
});
|
||||||
|
|
||||||
const commonInfo = computed<Record<string, string> | undefined>(() => {
|
const commonInfo = computed<Record<string, string> | undefined>(() => {
|
||||||
const info = lastDiagInfo.value?.stCommonInfo;
|
const info = lastDiagInfo.value?.stCommonInfo ?? {};
|
||||||
if (info) {
|
if (info) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { CPU使用率, 内存使用率, ...rest } = info;
|
const { CPU使用率, 内存使用率, ...rest } = info;
|
||||||
@@ -39,15 +39,15 @@ const commonInfo = computed<Record<string, string> | undefined>(() => {
|
|||||||
return info;
|
return info;
|
||||||
});
|
});
|
||||||
|
|
||||||
const cpuUsage = computed(() => lastDiagInfo.value?.stCommonInfo.CPU使用率);
|
const cpuUsage = computed(() => lastDiagInfo.value?.stCommonInfo?.['CPU使用率']);
|
||||||
const memUsage = computed(() => lastDiagInfo.value?.stCommonInfo.内存使用率);
|
const memUsage = computed(() => lastDiagInfo.value?.stCommonInfo?.['内存使用率']);
|
||||||
|
|
||||||
const fanSpeeds = computed(() => lastDiagInfo.value?.info.at(0)?.fanSpeeds);
|
const fanSpeeds = computed(() => lastDiagInfo.value?.info?.at(0)?.fanSpeeds);
|
||||||
const temperature = computed(() => lastDiagInfo.value?.info.at(0)?.temperature);
|
const temperature = computed(() => lastDiagInfo.value?.info?.at(0)?.temperature);
|
||||||
const humidity = computed(() => lastDiagInfo.value?.info.at(0)?.humidity);
|
const humidity = computed(() => lastDiagInfo.value?.info?.at(0)?.humidity);
|
||||||
const switches = computed(() => lastDiagInfo.value?.info.at(0)?.switches);
|
const switches = computed(() => lastDiagInfo.value?.info?.at(0)?.switches);
|
||||||
|
|
||||||
const circuits = computed(() => lastDiagInfo.value?.info.at(0)?.circuits);
|
const circuits = computed(() => lastDiagInfo.value?.info?.at(0)?.circuits);
|
||||||
|
|
||||||
const selectedTab = ref('设备状态');
|
const selectedTab = ref('设备状态');
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user