feat(iot):优化首页的设备统计实现
parent
89f75428d6
commit
71a23487f7
|
|
@ -3,12 +3,12 @@ import type { IotStatisticsApi } from '#/api/iot/statistics';
|
||||||
/** 统计数据 */
|
/** 统计数据 */
|
||||||
export type StatsData = IotStatisticsApi.StatisticsSummaryRespVO;
|
export type StatsData = IotStatisticsApi.StatisticsSummaryRespVO;
|
||||||
|
|
||||||
/** 默认统计数据 */
|
/** 默认统计数据;用 -1 作为「未加载」哨兵,避免与「真 0 设备」混淆 */
|
||||||
export const defaultStatsData: StatsData = {
|
export const defaultStatsData: StatsData = {
|
||||||
productCategoryCount: 0,
|
productCategoryCount: -1,
|
||||||
productCount: 0,
|
productCount: -1,
|
||||||
deviceCount: 0,
|
deviceCount: -1,
|
||||||
deviceMessageCount: 0,
|
deviceMessageCount: -1,
|
||||||
productCategoryTodayCount: 0,
|
productCategoryTodayCount: 0,
|
||||||
productTodayCount: 0,
|
productTodayCount: 0,
|
||||||
deviceTodayCount: 0,
|
deviceTodayCount: 0,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const hasData = computed(() => {
|
||||||
const categories = Object.entries(
|
const categories = Object.entries(
|
||||||
props.statsData.productCategoryDeviceCounts || {},
|
props.statsData.productCategoryDeviceCounts || {},
|
||||||
);
|
);
|
||||||
return categories.length > 0 && props.statsData.deviceCount !== 0;
|
return categories.length > 0 && props.statsData.deviceCount !== -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 初始化图表 */
|
/** 初始化图表 */
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ import type { IotDeviceApi } from '#/api/iot/device/device';
|
||||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
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 { Card, Empty, Spin } from 'ant-design-vue';
|
||||||
|
|
||||||
import { getDeviceLocationList } from '#/api/iot/device/device';
|
import { getDeviceLocationList } from '#/api/iot/device/device';
|
||||||
|
|
@ -28,15 +31,10 @@ const stateColorMap: Record<number, string> = {
|
||||||
[DeviceStateEnum.OFFLINE]: '#9CA3AF', // 离线 - 灰色
|
[DeviceStateEnum.OFFLINE]: '#9CA3AF', // 离线 - 灰色
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 获取设备状态配置 */
|
/** 获取设备状态配置;名称走字典,颜色用本地映射 */
|
||||||
function getStateConfig(state: number): { color: string; name: string } {
|
function getStateConfig(state: number): { color: string; name: string } {
|
||||||
const stateNames: Record<number, string> = {
|
|
||||||
[DeviceStateEnum.INACTIVE]: '待激活',
|
|
||||||
[DeviceStateEnum.ONLINE]: '在线',
|
|
||||||
[DeviceStateEnum.OFFLINE]: '离线',
|
|
||||||
};
|
|
||||||
return {
|
return {
|
||||||
name: stateNames[state] || '未知',
|
name: getDictLabel(DICT_TYPE.IOT_DEVICE_STATE, state) || '未知',
|
||||||
color: stateColorMap[state] || '#909399',
|
color: stateColorMap[state] || '#909399',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +116,7 @@ function initMap() {
|
||||||
if (link) {
|
if (link) {
|
||||||
link.addEventListener('click', (e) => {
|
link.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const deviceId = e.target as HTMLElement.dataset.id;
|
const deviceId = (e.target as HTMLElement).dataset.id;
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
router.push({
|
router.push({
|
||||||
name: 'IoTDeviceDetail',
|
name: 'IoTDeviceDetail',
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ const { renderEcharts: renderInactiveChart } = useEcharts(
|
||||||
/** 是否有数据 */
|
/** 是否有数据 */
|
||||||
const hasData = computed(() => {
|
const hasData = computed(() => {
|
||||||
if (!props.statsData) return false;
|
if (!props.statsData) return false;
|
||||||
return props.statsData.deviceCount !== 0;
|
return props.statsData.deviceCount !== -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 初始化图表 */
|
/** 初始化图表 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue