feat: get alarms from all stations
This commit is contained in:
173
src/components/device-alarm-detail-modal.vue
Normal file
173
src/components/device-alarm-detail-modal.vue
Normal file
@@ -0,0 +1,173 @@
|
||||
`
|
||||
<script setup lang="ts">
|
||||
import type { Station } from '@/apis/domains';
|
||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models/device';
|
||||
import type { StationAlarms } from '@/composables/query/use-line-alarms-query';
|
||||
import { DeviceType, DeviceTypeName, type DeviceTypeCode } from '@/enums/device-type';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import dayjs from 'dayjs';
|
||||
import { NCol, NDataTable, NModal, NRow, NStatistic, type DataTableColumns, type DataTableRowData, type PaginationProps } from 'naive-ui';
|
||||
import { computed, h, reactive, toRefs, watch } from 'vue';
|
||||
|
||||
interface Props {
|
||||
station: Station;
|
||||
stationAlarms: StationAlarms;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { station, stationAlarms } = toRefs(props);
|
||||
const show = defineModel<boolean>('show', { required: true });
|
||||
|
||||
watch(show, (newValue) => {
|
||||
const queryControlStore = useQueryControlStore();
|
||||
if (newValue) {
|
||||
console.log('对话框打开,停止轮询');
|
||||
queryControlStore.disablePolling();
|
||||
} else {
|
||||
console.log('对话框关闭,开启轮询');
|
||||
queryControlStore.enablePolling();
|
||||
}
|
||||
});
|
||||
|
||||
const alarmCount = computed(() => {
|
||||
return Object.values(DeviceType).reduce((count, deviceType) => {
|
||||
return count + stationAlarms.value[deviceType].occurred.length;
|
||||
}, 0);
|
||||
});
|
||||
|
||||
const classifiedCount = computed(() => {
|
||||
return Object.values(DeviceType).map<{ label: string; count: number }>((deviceType) => {
|
||||
return {
|
||||
label: DeviceTypeName[deviceType],
|
||||
count: stationAlarms.value[deviceType].occurred.length,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const tablePagination = reactive<PaginationProps>({
|
||||
size: 'small',
|
||||
showSizePicker: true,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
pageSizes: [5, 10, 20, 50, 80, 100],
|
||||
// itemCount: 0,
|
||||
// pageCount: 1,
|
||||
prefix: ({ itemCount }) => {
|
||||
return h('div', {}, { default: () => `共${itemCount}条` });
|
||||
},
|
||||
onUpdatePage: (page: number) => {
|
||||
tablePagination.page = page;
|
||||
},
|
||||
onUpdatePageSize: (pageSize: number) => {
|
||||
tablePagination.pageSize = pageSize;
|
||||
tablePagination.page = 1;
|
||||
},
|
||||
});
|
||||
|
||||
const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
||||
{ title: '告警流水号', key: 'alarmNo' },
|
||||
{
|
||||
title: '告警时间',
|
||||
key: 'alarmDate',
|
||||
render: (rowData /* , rowIndex */) => {
|
||||
return dayjs(Number(rowData.alarmDate ?? 0)).format('YYYY-MM-DD HH:mm:ss');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
key: 'deviceType',
|
||||
render: (rowData) => {
|
||||
return DeviceTypeName[(rowData.deviceType ?? DeviceType.Camera) as DeviceTypeCode];
|
||||
},
|
||||
filterMultiple: true,
|
||||
filterOptions: Object.values(DeviceTypeName).map((typeName) => ({ label: typeName, value: typeName })),
|
||||
filter: (filterOptionValue, row) => {
|
||||
return row.deviceType === filterOptionValue;
|
||||
},
|
||||
},
|
||||
{ title: '设备名称', key: 'deviceName' },
|
||||
{ title: '告警类型', key: 'alarmType', align: 'center' },
|
||||
{ title: '故障级别', key: 'faultLevel', align: 'center' },
|
||||
{ title: '故障编码', key: 'faultCode', align: 'center' },
|
||||
{ title: '故障位置', key: 'faultLocation' },
|
||||
{ title: '故障描述', key: 'faultDescription' },
|
||||
{ title: '修复建议', key: 'alarmRepairSuggestion' },
|
||||
{
|
||||
title: '是否恢复',
|
||||
key: 'recovered',
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
return rowData.recovered ? '是' : '否';
|
||||
},
|
||||
filterMultiple: false,
|
||||
filterOptions: [
|
||||
{ label: '是', value: 'true' },
|
||||
{ label: '否', value: 'false' },
|
||||
],
|
||||
filter: (filterOptionValue, row) => {
|
||||
return row.recovered === filterOptionValue;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '恢复时间',
|
||||
key: 'recoverTime',
|
||||
render: (rowData) => {
|
||||
return rowData.recoverTime ? dayjs(Number(rowData.recoverTime)).format('YYYY-MM-DD HH:mm:ss') : '';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '告警确认',
|
||||
key: 'alarmConfirm',
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
return rowData.alarmConfirm === '1' ? '已确认' : '未确认';
|
||||
},
|
||||
filterMultiple: false,
|
||||
filterOptions: [
|
||||
{ label: '已确认', value: '1' },
|
||||
{ label: '未确认', value: '2' },
|
||||
],
|
||||
filter: (filterOptionValue, row) => {
|
||||
return row.alarmConfirm === filterOptionValue;
|
||||
},
|
||||
},
|
||||
// { title: '设备ID', key: 'deviceId' },
|
||||
];
|
||||
|
||||
const tableData = computed<DataTableRowData[]>(() => {
|
||||
const records = stationAlarms.value['unclassified'].occurred;
|
||||
const recovered = stationAlarms.value['unclassified'].recovered;
|
||||
|
||||
return records.map((record) => {
|
||||
const recoveredAlarmLog = recovered.find((item) => item.alarmNo === record.alarmNo);
|
||||
return {
|
||||
...record,
|
||||
recovered: recoveredAlarmLog ? 'true' : 'false',
|
||||
recoverTime: recoveredAlarmLog?.alarmDate,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const onModalClose = () => {};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NModal v-model:show="show" preset="card" style="width: 100vw; height: 100vh" :title="`${station.name} - 设备告警详情`" @close="onModalClose">
|
||||
<div v-if="alarmCount === 0" style="text-align: center; padding: 20px; color: #6c757d">
|
||||
<span>当前没有设备告警</span>
|
||||
</div>
|
||||
<div v-else style="height: 100%; display: flex; flex-direction: column">
|
||||
<NRow style="flex: 0 0 auto; margin-bottom: 16px">
|
||||
<NCol :span="3" v-for="item in classifiedCount" :key="item.label">
|
||||
<NStatistic :label="item.label + '告警'" :value="item.count"></NStatistic>
|
||||
</NCol>
|
||||
</NRow>
|
||||
<div style="flex: 1 1 auto; min-height: 0">
|
||||
<NDataTable :columns="tableColumns" :data="tableData" :pagination="tablePagination" flex-height style="height: 100%" />
|
||||
</div>
|
||||
</div>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
`
|
||||
@@ -1,7 +0,0 @@
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
@@ -1,41 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { NButton, NInput, NModal, NTree } from 'naive-ui';
|
||||
import { computed, ref, toRefs, watch } from 'vue';
|
||||
import { computed, h, ref, toRefs, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { TreeOption, TreeOverrideNodeClickBehavior } from 'naive-ui';
|
||||
import type {
|
||||
NdmCameraResultVO,
|
||||
NdmDecoderResultVO,
|
||||
NdmDeviceVO,
|
||||
NdmKeyboardResultVO,
|
||||
NdmMediaServerResultVO,
|
||||
NdmNvrResultVO,
|
||||
NdmSecurityBoxResultVO,
|
||||
NdmSwitchResultVO,
|
||||
NdmVideoServerResultVO,
|
||||
} from '@/apis/models/device';
|
||||
import type { NdmDeviceVO } from '@/apis/models/device';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { DeviceType, DeviceTypeName } from '@/enums/device-type';
|
||||
import type { Station } from '@/apis/domains';
|
||||
import { h } from 'vue';
|
||||
import type { StationDevices } from '@/composables/query/use-line-devices-query';
|
||||
|
||||
interface Props {
|
||||
station: Station;
|
||||
ndmDeviceList: {
|
||||
[DeviceType.Camera]: NdmCameraResultVO[];
|
||||
[DeviceType.Decoder]: NdmDecoderResultVO[];
|
||||
[DeviceType.Keyboard]: NdmKeyboardResultVO[];
|
||||
[DeviceType.MediaServer]: NdmMediaServerResultVO[];
|
||||
[DeviceType.Nvr]: NdmNvrResultVO[];
|
||||
[DeviceType.SecurityBox]: NdmSecurityBoxResultVO[];
|
||||
[DeviceType.Switch]: NdmSwitchResultVO[];
|
||||
[DeviceType.VideoServer]: NdmVideoServerResultVO[];
|
||||
};
|
||||
stationDevices: StationDevices;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { station, ndmDeviceList } = toRefs(props);
|
||||
const { station, stationDevices } = toRefs(props);
|
||||
const show = defineModel<boolean>('show', { required: true });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
@@ -59,19 +41,19 @@ const searchFilter: (pattern: string, node: TreeOption) => boolean = (pattern, n
|
||||
|
||||
const offlineDeviceCount = computed(() => {
|
||||
let count = 0;
|
||||
Object.values(DeviceType).forEach((type) => {
|
||||
const offlineDeviceList = ndmDeviceList.value[type].filter((device) => device.deviceStatus === '20');
|
||||
Object.values(DeviceType).forEach((deviceType) => {
|
||||
const offlineDeviceList = stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20');
|
||||
count += offlineDeviceList.length;
|
||||
});
|
||||
return count;
|
||||
});
|
||||
|
||||
const treeData = computed<TreeOption[]>(() => {
|
||||
return Object.values(DeviceType).map<TreeOption>((type) => {
|
||||
const offlineDeviceList = ndmDeviceList.value[type].filter((device) => device.deviceStatus === '20');
|
||||
return Object.values(DeviceType).map<TreeOption>((deviceType) => {
|
||||
const offlineDeviceList = stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20');
|
||||
return {
|
||||
label: `${DeviceTypeName[type]} (${offlineDeviceList.length}台)`,
|
||||
key: type,
|
||||
label: `${DeviceTypeName[deviceType]} (${offlineDeviceList.length}台)`,
|
||||
key: deviceType,
|
||||
children: offlineDeviceList.map<TreeOption>((device) => ({
|
||||
label: `${device.name}`,
|
||||
key: device.id,
|
||||
@@ -3,60 +3,55 @@ import { NCard, NStatistic, NTag, NGrid, NGi, NButton, NIcon, useThemeVars } fro
|
||||
import { Video as VideoIcon } from '@vicons/carbon';
|
||||
import { toRefs, computed, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import OfflineDeviceTreeModal from './offline-device-tree-modal.vue';
|
||||
import type {
|
||||
NdmCameraResultVO,
|
||||
NdmDecoderResultVO,
|
||||
NdmDeviceAlarmLogResultVO,
|
||||
NdmKeyboardResultVO,
|
||||
NdmMediaServerResultVO,
|
||||
NdmNvrResultVO,
|
||||
NdmSecurityBoxResultVO,
|
||||
NdmSwitchResultVO,
|
||||
NdmVideoServerResultVO,
|
||||
} from '@/apis/models/device';
|
||||
import { DeviceType } from '@/enums/device-type';
|
||||
import type { Station } from '@/apis/domains';
|
||||
import type { StationDevices } from '@/composables/query/use-line-devices-query';
|
||||
import type { StationAlarms } from '@/composables/query/use-line-alarms-query';
|
||||
import OfflineDeviceDetailModal from './offline-device-detail-modal.vue';
|
||||
import DeviceAlarmDetailModal from './device-alarm-detail-modal.vue';
|
||||
|
||||
interface Props {
|
||||
station: Station;
|
||||
alarmCount: number;
|
||||
ndmDeviceList: {
|
||||
[DeviceType.Camera]: NdmCameraResultVO[];
|
||||
[DeviceType.Decoder]: NdmDecoderResultVO[];
|
||||
[DeviceType.Keyboard]: NdmKeyboardResultVO[];
|
||||
[DeviceType.MediaServer]: NdmMediaServerResultVO[];
|
||||
[DeviceType.Nvr]: NdmNvrResultVO[];
|
||||
[DeviceType.SecurityBox]: NdmSecurityBoxResultVO[];
|
||||
[DeviceType.Switch]: NdmSwitchResultVO[];
|
||||
[DeviceType.VideoServer]: NdmVideoServerResultVO[];
|
||||
};
|
||||
ndmDeviceAlarmLogList: NdmDeviceAlarmLogResultVO[];
|
||||
stationDevices: StationDevices;
|
||||
stationAlarms: StationAlarms;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const { alarmCount, ndmDeviceList, station } = toRefs(props);
|
||||
const { station, stationDevices, stationAlarms } = toRefs(props);
|
||||
const { code, name, online } = toRefs(station.value);
|
||||
|
||||
// 计算总离线设备数量
|
||||
const offlineDeviceCount = computed(() => {
|
||||
let count = 0;
|
||||
Object.values(DeviceType).forEach((type) => {
|
||||
const offlineDeviceList = ndmDeviceList.value[type].filter((device) => device.deviceStatus === '20');
|
||||
Object.values(DeviceType).forEach((deviceType) => {
|
||||
const offlineDeviceList = stationDevices.value[deviceType].filter((device) => device.deviceStatus === '20');
|
||||
count += offlineDeviceList.length;
|
||||
});
|
||||
return count;
|
||||
});
|
||||
const devicAlarmCount = computed(() => {
|
||||
let count = 0;
|
||||
Object.values(DeviceType).forEach((deviceType) => {
|
||||
count += stationAlarms.value[deviceType].occurred.length;
|
||||
});
|
||||
return count;
|
||||
});
|
||||
|
||||
const offlineDeviceTreeModalShow = ref(false);
|
||||
const deviceAlarmTreeModalShow = ref(false);
|
||||
|
||||
// 打开离线设备详情对话框
|
||||
// 打开对话框
|
||||
const openOfflineDeviceTreeModal = () => {
|
||||
if (online.value) {
|
||||
offlineDeviceTreeModalShow.value = true;
|
||||
}
|
||||
};
|
||||
const openDeviceAlarmTreeModal = () => {
|
||||
if (online.value) {
|
||||
deviceAlarmTreeModalShow.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
// 打开视频平台
|
||||
const openVideoPlatform = async () => {
|
||||
@@ -111,10 +106,10 @@ const theme = useThemeVars();
|
||||
<NGi>
|
||||
<NStatistic tabular-nums>
|
||||
<template #label>
|
||||
<span class="font-xx-small">告警记录</span>
|
||||
<span class="font-xx-small" :class="[online ? 'clickable' : '']" @click="openDeviceAlarmTreeModal">告警记录</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<span class="font-medium">{{ alarmCount }}</span>
|
||||
<span class="font-medium">{{ devicAlarmCount }}</span>
|
||||
</template>
|
||||
<template #suffix>
|
||||
<span class="font-xx-small">条</span>
|
||||
@@ -126,7 +121,8 @@ const theme = useThemeVars();
|
||||
</NCard>
|
||||
|
||||
<!-- 离线设备详情对话框 -->
|
||||
<OfflineDeviceTreeModal v-model:show="offlineDeviceTreeModalShow" :station="station" :ndm-device-list="ndmDeviceList" />
|
||||
<OfflineDeviceDetailModal v-model:show="offlineDeviceTreeModalShow" :station="station" :station-devices="stationDevices" />
|
||||
<DeviceAlarmDetailModal v-model:show="deviceAlarmTreeModalShow" :station="station" :station-alarms="stationAlarms" />
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -136,7 +132,7 @@ const theme = useThemeVars();
|
||||
transition: color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
color: v-bind('theme.infoColorHover');
|
||||
color: v-bind('theme.primaryColorHover');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user