fix: iot
This commit is contained in:
@@ -32,9 +32,9 @@ const IconComponent = computed(() => iconMap[props.icon] || iconMap.menu);
|
||||
<div class="flex h-full flex-col">
|
||||
<div class="mb-4 flex items-start justify-between">
|
||||
<div class="flex flex-1 flex-col">
|
||||
<span class="mb-2 text-sm font-medium text-gray-500">{{
|
||||
title
|
||||
}}</span>
|
||||
<span class="mb-2 text-sm font-medium text-gray-500">
|
||||
{{ title }}
|
||||
</span>
|
||||
<span class="text-3xl font-bold text-gray-800">
|
||||
<span v-if="value === -1">--</span>
|
||||
<CountTo v-else :end-val="value" :duration="1000" />
|
||||
@@ -49,9 +49,9 @@ const IconComponent = computed(() => iconMap[props.icon] || iconMap.menu);
|
||||
<div class="flex items-center justify-between text-sm">
|
||||
<span class="text-gray-400">今日新增</span>
|
||||
<span v-if="todayCount === -1" class="text-gray-400">--</span>
|
||||
<span v-else class="font-medium text-green-500"
|
||||
>+{{ todayCount }}</span
|
||||
>
|
||||
<span v-else class="font-medium text-green-500">
|
||||
+{{ todayCount }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -61,18 +61,18 @@ const IconComponent = computed(() => iconMap[props.icon] || iconMap.menu);
|
||||
<style scoped>
|
||||
.stat-card {
|
||||
height: 160px;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
box-shadow: 0 6px 20px rgb(0 0 0 / 8%);
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.stat-card :deep(.ant-card-body) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -27,7 +27,7 @@ const hasData = computed(() => {
|
||||
});
|
||||
|
||||
/** 初始化图表 */
|
||||
const initChart = () => {
|
||||
function initChart() {
|
||||
if (!hasData.value) return;
|
||||
|
||||
nextTick(() => {
|
||||
@@ -94,7 +94,7 @@ const initChart = () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 监听数据变化 */
|
||||
watch(
|
||||
|
||||
@@ -80,7 +80,7 @@ const getGaugeOption = (value: number, color: string, title: string): any => {
|
||||
};
|
||||
|
||||
/** 初始化图表 */
|
||||
const initCharts = () => {
|
||||
function initCharts() {
|
||||
if (!hasData.value) return;
|
||||
|
||||
nextTick(() => {
|
||||
@@ -101,7 +101,7 @@ const initCharts = () => {
|
||||
),
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 监听数据变化 */
|
||||
watch(
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import type {
|
||||
IotStatisticsDeviceMessageReqVO,
|
||||
IotStatisticsDeviceMessageSummaryByDateRespVO,
|
||||
} from '#/api/iot/statistics';
|
||||
import type { IotStatisticsApi } from '#/api/iot/statistics';
|
||||
|
||||
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
|
||||
|
||||
@@ -13,7 +10,7 @@ import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
import { Button, Card, DatePicker, Empty, Space } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { StatisticsApi } from '#/api/iot/statistics';
|
||||
import { getDeviceMessageSummaryByDate } from '#/api/iot/statistics';
|
||||
|
||||
defineOptions({ name: 'MessageTrendCard' });
|
||||
|
||||
@@ -23,11 +20,11 @@ const messageChartRef = ref();
|
||||
const { renderEcharts } = useEcharts(messageChartRef);
|
||||
|
||||
const loading = ref(false);
|
||||
const messageData = ref<IotStatisticsDeviceMessageSummaryByDateRespVO[]>([]);
|
||||
const messageData = ref<IotStatisticsApi.DeviceMessageSummaryByDate[]>([]);
|
||||
const activeTimeRange = ref('7d'); // 当前选中的时间范围
|
||||
const dateRange = ref<[Dayjs, Dayjs] | undefined>(undefined);
|
||||
|
||||
const queryParams = reactive<IotStatisticsDeviceMessageReqVO>({
|
||||
const queryParams = reactive<IotStatisticsApi.DeviceMessageReq>({
|
||||
interval: 1, // 按天
|
||||
times: [],
|
||||
});
|
||||
@@ -38,7 +35,7 @@ const hasData = computed(() => {
|
||||
});
|
||||
|
||||
// 设置时间范围
|
||||
const setTimeRange = (range: string) => {
|
||||
function setTimeRange(range: string) {
|
||||
activeTimeRange.value = range;
|
||||
dateRange.value = undefined; // 清空自定义时间选择
|
||||
|
||||
@@ -73,10 +70,10 @@ const setTimeRange = (range: string) => {
|
||||
];
|
||||
|
||||
fetchMessageData();
|
||||
};
|
||||
}
|
||||
|
||||
// 处理自定义日期选择
|
||||
const handleDateChange = () => {
|
||||
function handleDateChange() {
|
||||
if (dateRange.value && dateRange.value.length === 2) {
|
||||
activeTimeRange.value = ''; // 清空快捷选择
|
||||
queryParams.interval = 1; // 按天
|
||||
@@ -86,16 +83,15 @@ const handleDateChange = () => {
|
||||
];
|
||||
fetchMessageData();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 获取消息统计数据
|
||||
const fetchMessageData = async () => {
|
||||
async function fetchMessageData() {
|
||||
if (!queryParams.times || queryParams.times.length !== 2) return;
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
messageData.value =
|
||||
await StatisticsApi.getDeviceMessageSummaryByDate(queryParams);
|
||||
messageData.value = await getDeviceMessageSummaryByDate(queryParams);
|
||||
await nextTick();
|
||||
initChart();
|
||||
} catch (error) {
|
||||
@@ -104,10 +100,10 @@ const fetchMessageData = async () => {
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 初始化图表
|
||||
const initChart = () => {
|
||||
function initChart() {
|
||||
if (!hasData.value) return;
|
||||
|
||||
const times = messageData.value.map((item) => item.time);
|
||||
@@ -181,7 +177,7 @@ const initChart = () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// 组件挂载时查询数据
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user