feat: add alarm-host

This commit is contained in:
yangsy
2025-11-26 16:28:05 +08:00
parent 8fa904dfc0
commit 68052f7630
15 changed files with 238 additions and 11 deletions

View File

@@ -0,0 +1,65 @@
<script setup lang="ts">
import type { NdmAlarmHostResultVO } from '@/apis';
import { AlarmHostHistoryDiagCard, DeviceCommonCard, DeviceHeaderCard } from '@/components';
import { useSettingStore } from '@/stores';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue';
import { destr } from 'destr';
const props = defineProps<{
stationCode: string;
ndmAlarmHost: NdmAlarmHostResultVO;
}>();
const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmAlarmHost } = toRefs(props);
const lastDiagInfo = computed(() => {
const result = destr<any>(ndmAlarmHost.value.lastDiagInfo);
if (!result) return null;
if (typeof result !== 'object') return null;
return result;
});
const commonInfo = computed(() => {
const { createdTime, updatedTime, manufacturer } = ndmAlarmHost.value;
return {
创建时间: createdTime ?? '',
更新时间: updatedTime ?? '',
制造商: manufacturer ?? '',
};
});
const selectedTab = ref('设备状态');
</script>
<template>
<NCard size="small">
<NTabs v-model:value="selectedTab" size="small">
<NTabPane name="设备状态" tab="设备状态">
<NFlex vertical>
<DeviceHeaderCard :station-code="stationCode" :device="ndmAlarmHost" />
<DeviceCommonCard :common-info="commonInfo" />
</NFlex>
</NTabPane>
<NTabPane name="历史诊断" tab="历史诊断">
<!-- 历史诊断组件中包含请求逻辑当改变选择的设备时需要重新发起请求因此添加显式的key触发组件的更新 -->
<AlarmHostHistoryDiagCard :station-code="stationCode" :ndm-alarm-host="ndmAlarmHost" :key="ndmAlarmHost.id" />
</NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmAlarmHost, lastDiagInfo } }}</pre>
</NTabPane>
</NTabs>
</NCard>
</template>
<style scoped lang="scss">
.raw-data {
white-space: pre-wrap;
word-break: break-all;
}
</style>

View File

@@ -0,0 +1,99 @@
<script setup lang="ts">
import type { NdmAlarmHostResultVO } from '@/apis';
import { DeviceAlarmHistoryDiagCard, DeviceStatusHistoryDiagCard } from '@/components';
import dayjs from 'dayjs';
import { NButton, NCard, NDatePicker, NFlex, NGi, NGrid, NSelect, type DatePickerProps, type SelectOption } from 'naive-ui';
import { computed, onMounted, reactive, ref, toRefs, useTemplateRef } from 'vue';
const props = defineProps<{
stationCode: string;
ndmAlarmHost: NdmAlarmHostResultVO;
}>();
const { stationCode, ndmAlarmHost } = toRefs(props);
const searchFields = reactive({
dateTimeRange: undefined as DatePickerProps['value'],
});
const onDateChange = (value: [number, number] | null) => {
if (!value) {
return;
}
const [start, end] = value;
const diffDays = dayjs(end).diff(dayjs(start), 'day');
if (diffDays > 7) {
// 如果超过7天自动调整结束时间
const adjustedEnd = dayjs(start).add(7, 'day').valueOf();
searchFields.dateTimeRange = [start, adjustedEnd];
window.$message.warning('时间范围不能超过7天已自动调整');
} else {
searchFields.dateTimeRange = value;
}
};
type DeviceStatusHistoryDiagCardInst = InstanceType<typeof DeviceStatusHistoryDiagCard> | null;
type DeviceAlarmHistoryDiagCardInst = InstanceType<typeof DeviceAlarmHistoryDiagCard> | null;
const deviceStatusHistoryDiagCardRef = useTemplateRef<DeviceStatusHistoryDiagCardInst>('deviceStatusHistoryDiagCardRef');
const deviceAlarmHistoryDiagCardRef = useTemplateRef<DeviceAlarmHistoryDiagCardInst>('deviceAlarmHistoryDiagCardRef');
function refreshData() {
deviceStatusHistoryDiagCardRef.value?.refresh();
deviceAlarmHistoryDiagCardRef.value?.refresh();
}
const loading = computed(() => {
return deviceStatusHistoryDiagCardRef.value?.isPending || deviceAlarmHistoryDiagCardRef.value?.isPending;
});
onMounted(() => {
const now = dayjs();
const todayEnd = now.endOf('date');
const weekAgo = now.subtract(1, 'week').startOf('date');
searchFields.dateTimeRange = [weekAgo.valueOf(), todayEnd.valueOf()];
refreshData();
});
const diagCards = ref<SelectOption[]>([
{ label: '设备状态', value: 'status' },
{ label: '设备告警', value: 'alarm' },
]);
const selectedCards = ref<string[]>([...diagCards.value.map((option) => `${option.value ?? ''}`)]);
</script>
<template>
<NCard size="small">
<NFlex vertical>
<NCard size="small">
<NFlex justify="space-between" :wrap="false">
<NGrid :x-gap="8" :y-gap="8">
<NGi :span="20">
<NDatePicker v-model:value="searchFields.dateTimeRange" type="datetimerange" @update:value="onDateChange" />
</NGi>
<NGi :span="20">
<NSelect v-model:value="selectedCards" multiple :options="diagCards" />
</NGi>
</NGrid>
<NButton secondary :loading="loading" @click="refreshData">刷新数据</NButton>
</NFlex>
</NCard>
<DeviceStatusHistoryDiagCard
v-if="selectedCards.includes('status')"
:ref="'deviceStatusHistoryDiagCardRef'"
:station-code="stationCode"
:ndm-device="ndmAlarmHost"
:date-time-range="searchFields.dateTimeRange"
/>
<DeviceAlarmHistoryDiagCard
v-if="selectedCards.includes('alarm')"
:ref="'deviceAlarmHistoryDiagCardRef'"
:station-code="stationCode"
:ndm-device="ndmAlarmHost"
:date-time-range="searchFields.dateTimeRange"
/>
</NFlex>
</NCard>
</template>
<style scoped lang="scss"></style>

View File

@@ -1,3 +1,4 @@
export { default as AlarmHostHistoryDiagCard } from './alarm-host-history-diag-card.vue';
export { default as CameraHistoryDiagCard } from './camera-history-diag-card.vue';
export { default as DecoderHistoryDiagCard } from './decoder-history-diag-card.vue';
export { default as DeviceAlarmHistoryDiagCard } from './device-alarm-history-diag-card.vue';

View File

@@ -1,3 +1,4 @@
export { default as AlarmHostCard } from './alarm-host-card.vue';
export { default as CameraCard } from './camera-card.vue';
export { default as DecoderCard } from './decoder-card.vue';
export { default as KeyboardCard } from './keyboard-card.vue';