feat: add online status of station node
This commit is contained in:
@@ -31,6 +31,7 @@ import { h, onMounted, useTemplateRef } from 'vue';
|
|||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useRoute, useRouter, type LocationQuery } from 'vue-router';
|
import { useRoute, useRouter, type LocationQuery } from 'vue-router';
|
||||||
import { destr } from 'destr';
|
import { destr } from 'destr';
|
||||||
|
import type { Station } from '@/apis/domains';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -54,7 +55,8 @@ const { data: lineDevices } = useLineDevicesQuery();
|
|||||||
const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
||||||
const treeData: Record<string, TreeOption[]> = {};
|
const treeData: Record<string, TreeOption[]> = {};
|
||||||
deviceTabPanes.forEach(({ name: paneName /* , tab: paneTab */ }) => {
|
deviceTabPanes.forEach(({ name: paneName /* , tab: paneTab */ }) => {
|
||||||
treeData[paneName] = stationList.value.map<TreeOption>(({ name: stationName, code: stationCode }) => {
|
treeData[paneName] = stationList.value.map<TreeOption>((station) => {
|
||||||
|
const { name: stationName, code: stationCode } = station;
|
||||||
const devices = lineDevices.value?.[stationCode][paneName];
|
const devices = lineDevices.value?.[stationCode][paneName];
|
||||||
const onlineDevices = devices?.filter((device) => device.deviceStatus === '10');
|
const onlineDevices = devices?.filter((device) => device.deviceStatus === '10');
|
||||||
const offlineDevices = devices?.filter((device) => device.deviceStatus === '20');
|
const offlineDevices = devices?.filter((device) => device.deviceStatus === '20');
|
||||||
@@ -64,6 +66,7 @@ const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
|||||||
return {
|
return {
|
||||||
label: stationName,
|
label: stationName,
|
||||||
key: stationCode,
|
key: stationCode,
|
||||||
|
prefix: () => renderStationNodePrefix(station),
|
||||||
suffix: () => `(${onlineDevices?.length ?? 0}/${offlineDevices?.length ?? 0}/${devices?.length ?? 0})`,
|
suffix: () => `(${onlineDevices?.length ?? 0}/${offlineDevices?.length ?? 0}/${devices?.length ?? 0})`,
|
||||||
children: nvrs
|
children: nvrs
|
||||||
?.filter((device) => {
|
?.filter((device) => {
|
||||||
@@ -74,10 +77,8 @@ const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
|||||||
return {
|
return {
|
||||||
label: `${nvrCluster.name}`,
|
label: `${nvrCluster.name}`,
|
||||||
key: nvrCluster.id,
|
key: nvrCluster.id,
|
||||||
|
prefix: () => renderDeviceNodePrefix(nvrCluster, stationCode),
|
||||||
suffix: () => `${nvrCluster.ipAddress}`,
|
suffix: () => `${nvrCluster.ipAddress}`,
|
||||||
prefix: () => {
|
|
||||||
return renderDeviceNodePrefix(nvrCluster, stationCode);
|
|
||||||
},
|
|
||||||
children: nvrs
|
children: nvrs
|
||||||
.filter((nvr) => {
|
.filter((nvr) => {
|
||||||
return nvrCluster.clusterList?.includes(nvr.ipAddress ?? '');
|
return nvrCluster.clusterList?.includes(nvr.ipAddress ?? '');
|
||||||
@@ -86,10 +87,8 @@ const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
|||||||
return {
|
return {
|
||||||
label: `${nvr.name}`,
|
label: `${nvr.name}`,
|
||||||
key: nvr.id,
|
key: nvr.id,
|
||||||
|
prefix: () => renderDeviceNodePrefix(nvr, stationCode),
|
||||||
suffix: () => `${nvr.ipAddress}`,
|
suffix: () => `${nvr.ipAddress}`,
|
||||||
prefix: () => {
|
|
||||||
return renderDeviceNodePrefix(nvr, stationCode);
|
|
||||||
},
|
|
||||||
// 当选择设备时,能获取到设备的所有信息,以及设备所属的车站
|
// 当选择设备时,能获取到设备的所有信息,以及设备所属的车站
|
||||||
device: nvr,
|
device: nvr,
|
||||||
stationCode,
|
stationCode,
|
||||||
@@ -105,14 +104,13 @@ const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
|||||||
return {
|
return {
|
||||||
label: stationName,
|
label: stationName,
|
||||||
key: stationCode,
|
key: stationCode,
|
||||||
|
prefix: () => renderStationNodePrefix(station),
|
||||||
suffix: () => `(${onlineDevices?.length ?? 0}/${offlineDevices?.length ?? 0}/${devices?.length ?? 0})`,
|
suffix: () => `(${onlineDevices?.length ?? 0}/${offlineDevices?.length ?? 0}/${devices?.length ?? 0})`,
|
||||||
children: lineDevices.value?.[stationCode][paneName].map<TreeOption>((device) => ({
|
children: lineDevices.value?.[stationCode][paneName].map<TreeOption>((device) => ({
|
||||||
label: `${device.name}`,
|
label: `${device.name}`,
|
||||||
key: device.id,
|
key: device.id,
|
||||||
|
prefix: () => renderDeviceNodePrefix(device, stationCode),
|
||||||
suffix: () => `${device.ipAddress}`,
|
suffix: () => `${device.ipAddress}`,
|
||||||
prefix: () => {
|
|
||||||
return renderDeviceNodePrefix(device, stationCode);
|
|
||||||
},
|
|
||||||
// 当选择设备时,能获取到设备的所有信息,以及设备所属的车站
|
// 当选择设备时,能获取到设备的所有信息,以及设备所属的车站
|
||||||
device,
|
device,
|
||||||
stationCode,
|
stationCode,
|
||||||
@@ -122,6 +120,12 @@ const lineDeviceTreeData = computed<Record<string, TreeOption[]>>(() => {
|
|||||||
});
|
});
|
||||||
return treeData;
|
return treeData;
|
||||||
});
|
});
|
||||||
|
const renderStationNodePrefix = (station: Station) => {
|
||||||
|
const { online } = station;
|
||||||
|
const tagType: TagProps['type'] = online ? 'success' : 'error';
|
||||||
|
const tagText = online ? '在线' : '离线';
|
||||||
|
return h(NTag, { type: tagType, size: 'tiny' }, () => tagText);
|
||||||
|
};
|
||||||
const renderDeviceNodePrefix = (device: NdmDeviceResultVO, stationCode: string) => {
|
const renderDeviceNodePrefix = (device: NdmDeviceResultVO, stationCode: string) => {
|
||||||
const renderDeviceStatusTag = (device: NdmDeviceResultVO) => {
|
const renderDeviceStatusTag = (device: NdmDeviceResultVO) => {
|
||||||
const { deviceStatus } = device;
|
const { deviceStatus } = device;
|
||||||
|
|||||||
Reference in New Issue
Block a user