feat: ui
This commit is contained in:
@@ -1,54 +1,147 @@
|
||||
<script setup lang="ts">
|
||||
import { NCard, NStatistic, NTag, NIcon, NGrid, NGi } from 'naive-ui';
|
||||
import { Wifi } from '@vicons/ionicons5';
|
||||
import { toRefs } from 'vue';
|
||||
import { NCard, NStatistic, NTag, NGrid, NGi, NButton, NIcon } from 'naive-ui';
|
||||
import { Video } 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';
|
||||
|
||||
// 定义组件props
|
||||
interface Props {
|
||||
name: string;
|
||||
online: boolean;
|
||||
offlineDeviceCount: number;
|
||||
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[];
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const { name, online, offlineDeviceCount, alarmCount } = toRefs(props);
|
||||
const { alarmCount, ndmDeviceList, station } = 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');
|
||||
count += offlineDeviceList.length;
|
||||
});
|
||||
return count;
|
||||
});
|
||||
|
||||
const offlineDeviceTreeModalShow = ref(false);
|
||||
|
||||
// 打开离线设备详情对话框
|
||||
const openOfflineDeviceTreeModal = () => {
|
||||
if (online.value) {
|
||||
offlineDeviceTreeModalShow.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
// 打开视频平台
|
||||
const openVideoPlatform = async () => {
|
||||
try {
|
||||
const response = await axios.get<Record<string, string>>('/minio/ndm/ndm-vimps.json');
|
||||
const vimpUrl = response.data[code.value];
|
||||
if (vimpUrl) {
|
||||
window.open(vimpUrl, '_blank');
|
||||
} else {
|
||||
window.$message.warning(`未找到车站编码 ${code.value} 对应的视频平台URL`);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取视频平台URL失败:', error);
|
||||
window.$message.error('获取视频平台URL失败');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NCard bordered hoverable size="small" :title="name" class="station-card">
|
||||
<NCard bordered hoverable size="small" class="station-card" :header-style="{ padding: `6px` }" :content-style="{ padding: `0px 6px 6px 6px` }">
|
||||
<template #header>
|
||||
<span class="font-smaller">{{ name }}</span>
|
||||
</template>
|
||||
<template #header-extra>
|
||||
<NTag :type="online ? 'success' : 'error'" size="small">
|
||||
<template #icon>
|
||||
<NIcon><Wifi /></NIcon>
|
||||
</template>
|
||||
{{ online ? '在线' : '离线' }}
|
||||
</NTag>
|
||||
</template>
|
||||
<template #default>
|
||||
<NGrid :cols="2">
|
||||
<NButton text @click="openVideoPlatform">
|
||||
<NIcon>
|
||||
<Video />
|
||||
</NIcon>
|
||||
</NButton>
|
||||
<NGrid :cols="2" :style="{ opacity: online ? '1' : '0.3' }">
|
||||
<NGi>
|
||||
<NStatistic label="离线设备" :value="offlineDeviceCount" :tabular-nums="true">
|
||||
<NStatistic tabular-nums>
|
||||
<template #label>
|
||||
<span class="font-xx-small" :class="[online ? 'clickable' : '']" @click="openOfflineDeviceTreeModal">离线设备</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<span class="font-medium">{{ offlineDeviceCount }}</span>
|
||||
</template>
|
||||
<template #suffix>
|
||||
<span class="stat-suffix">台</span>
|
||||
<span class="font-xx-small">台</span>
|
||||
</template>
|
||||
</NStatistic>
|
||||
</NGi>
|
||||
<NGi>
|
||||
<NStatistic label="告警记录" :value="alarmCount" :tabular-nums="true">
|
||||
<NStatistic tabular-nums>
|
||||
<template #label>
|
||||
<span class="font-xx-small">告警记录</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<span class="font-medium">{{ alarmCount }}</span>
|
||||
</template>
|
||||
<template #suffix>
|
||||
<span class="stat-suffix">条</span>
|
||||
<span class="font-xx-small">条</span>
|
||||
</template>
|
||||
</NStatistic>
|
||||
</NGi>
|
||||
</NGrid>
|
||||
</template>
|
||||
</NCard>
|
||||
|
||||
<!-- TODO: 离线设备详情对话框 -->
|
||||
<OfflineDeviceTreeModal v-model:show="offlineDeviceTreeModalShow" :station="station" :ndm-device-list="ndmDeviceList" />
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.stat-suffix {
|
||||
font-size: 14px;
|
||||
.clickable {
|
||||
text-decoration: underline dashed;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.font-xx-small {
|
||||
font-size: xx-small;
|
||||
}
|
||||
|
||||
.font-medium {
|
||||
font-size: medium;
|
||||
}
|
||||
|
||||
.font-smaller {
|
||||
font-size: smaller;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user