diff --git a/apps/web-antd/src/views/iot/home/data.ts b/apps/web-antd/src/views/iot/home/data.ts index 5a84bd8e9..433db75c7 100644 --- a/apps/web-antd/src/views/iot/home/data.ts +++ b/apps/web-antd/src/views/iot/home/data.ts @@ -3,12 +3,12 @@ import type { IotStatisticsApi } from '#/api/iot/statistics'; /** 统计数据 */ export type StatsData = IotStatisticsApi.StatisticsSummaryRespVO; -/** 默认统计数据 */ +/** 默认统计数据;用 -1 作为「未加载」哨兵,避免与「真 0 设备」混淆 */ export const defaultStatsData: StatsData = { - productCategoryCount: 0, - productCount: 0, - deviceCount: 0, - deviceMessageCount: 0, + productCategoryCount: -1, + productCount: -1, + deviceCount: -1, + deviceMessageCount: -1, productCategoryTodayCount: 0, productTodayCount: 0, deviceTodayCount: 0, diff --git a/apps/web-antd/src/views/iot/home/modules/device-count-card.vue b/apps/web-antd/src/views/iot/home/modules/device-count-card.vue index 422f6e758..ced22f4eb 100644 --- a/apps/web-antd/src/views/iot/home/modules/device-count-card.vue +++ b/apps/web-antd/src/views/iot/home/modules/device-count-card.vue @@ -25,7 +25,7 @@ const hasData = computed(() => { const categories = Object.entries( props.statsData.productCategoryDeviceCounts || {}, ); - return categories.length > 0 && props.statsData.deviceCount !== 0; + return categories.length > 0 && props.statsData.deviceCount !== -1; }); /** 初始化图表 */ diff --git a/apps/web-antd/src/views/iot/home/modules/device-map-card.vue b/apps/web-antd/src/views/iot/home/modules/device-map-card.vue index baa2eec75..90a2a0478 100644 --- a/apps/web-antd/src/views/iot/home/modules/device-map-card.vue +++ b/apps/web-antd/src/views/iot/home/modules/device-map-card.vue @@ -4,6 +4,9 @@ import type { IotDeviceApi } from '#/api/iot/device/device'; import { computed, onMounted, onUnmounted, ref } from 'vue'; import { useRouter } from 'vue-router'; +import { DICT_TYPE } from '@vben/constants'; +import { getDictLabel } from '@vben/hooks'; + import { Card, Empty, Spin } from 'ant-design-vue'; import { getDeviceLocationList } from '#/api/iot/device/device'; @@ -28,15 +31,10 @@ const stateColorMap: Record = { [DeviceStateEnum.OFFLINE]: '#9CA3AF', // 离线 - 灰色 }; -/** 获取设备状态配置 */ +/** 获取设备状态配置;名称走字典,颜色用本地映射 */ function getStateConfig(state: number): { color: string; name: string } { - const stateNames: Record = { - [DeviceStateEnum.INACTIVE]: '待激活', - [DeviceStateEnum.ONLINE]: '在线', - [DeviceStateEnum.OFFLINE]: '离线', - }; return { - name: stateNames[state] || '未知', + name: getDictLabel(DICT_TYPE.IOT_DEVICE_STATE, state) || '未知', color: stateColorMap[state] || '#909399', }; } @@ -118,7 +116,7 @@ function initMap() { if (link) { link.addEventListener('click', (e) => { e.preventDefault(); - const deviceId = e.target as HTMLElement.dataset.id; + const deviceId = (e.target as HTMLElement).dataset.id; if (deviceId) { router.push({ name: 'IoTDeviceDetail', diff --git a/apps/web-antd/src/views/iot/home/modules/device-state-count-card.vue b/apps/web-antd/src/views/iot/home/modules/device-state-count-card.vue index 3a93f21f0..41be3d5f1 100644 --- a/apps/web-antd/src/views/iot/home/modules/device-state-count-card.vue +++ b/apps/web-antd/src/views/iot/home/modules/device-state-count-card.vue @@ -29,7 +29,7 @@ const { renderEcharts: renderInactiveChart } = useEcharts( /** 是否有数据 */ const hasData = computed(() => { if (!props.statsData) return false; - return props.statsData.deviceCount !== 0; + return props.statsData.deviceCount !== -1; }); /** 初始化图表 */