feat(iot):优化首页的设备统计实现

pull/345/head
YunaiV 2026-05-18 08:55:39 +08:00
parent 89f75428d6
commit 71a23487f7
4 changed files with 13 additions and 15 deletions

View File

@ -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,

View File

@ -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;
});
/** 初始化图表 */

View File

@ -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<number, string> = {
[DeviceStateEnum.OFFLINE]: '#9CA3AF', // 线 -
};
/** 获取设备状态配置 */
/** 获取设备状态配置;名称走字典,颜色用本地映射 */
function getStateConfig(state: number): { color: string; name: string } {
const stateNames: Record<number, string> = {
[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',

View File

@ -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;
});
/** 初始化图表 */